Jump to content

[SOLVED] PHP CLI Linux Path Problem


freedbill

Recommended Posts

I'm trying to use PHP CLI for the first time and am encountering a path problem that has me confused.

 

Background: I am using a Virtual dedicated server from Godaddy, running Apache Server, on Linux 2.6.9 with PHP 5.2.6 and PLESK 8.4.

 

I know my way around Linux just enough to get into trouble.

 

I have created the following simple php script (named tester):

 

#!/usr/bin/php -q

<?

echo "Hello World";

?>

 

I have placed it in two locations for testing:

 

Location one:

The script is placed in /usr/bin

I can execute the following command line from anywhere and it works fine:

/./usr/bin/tester

 

Location two (in a web folder):

The script is placed in: /var/www/vhosts/lasmi1.net/httpdocs

I am unable to execute this script from the following command line.

/./var/www/vhosts/lasmi1.net/httpdocs/tester.

 

I can 'cd' to the web folder and still am unsuccessful with the following command line:

./tester

 

The error is 'extension "./testert is not present" '

 

This should be simple, but has my brain busted.

 

Any help is greatly appreciated.

Link to comment
Share on other sites

Ok, so I'm not sure why you are putting the '.'  (current directory) in all your paths.  When you cd to a directory to attempt to run it there, it's appropriate, but not when you're running it from some other directory like:  /./var/www/vhosts/lasmi1.net/httpdocs/tester

 

That should just be /var/www/vhosts/lasmi1.net/httpdocs/tester

 

So the first thing to check is:  did you set the permissions on the script so that it has the executable bit?  You can check this with "ls -lath"

 

To set the executable bit for all users:  chmod ugo+x tester

 

 

 

 

Link to comment
Share on other sites

Boy do I wish I could just withdraw this question!

 

Thanks so much for the simple but not so obvious to me use of dot (.) reference.

 

I did not grasp that the dot reference was a reference to the current directory and thought that it was some sort of command needed to "execute" the php cli script.

 

Oh well, thanks again for the obvious.  All works well now.

 

Bill

Link to comment
Share on other sites

Sure thing.  One thing that differentiates unix is that for security reasons, the current directory is not in the path.  This is meant to help prevent people from inadvertently running bogus versions of common commands, rather than those in the path.  For this reason, if you have a script in the current working directory, and you try and run it, it won't be found unless you add the current directory path.  It's an oddity of *nix shell configuration that differs from windows and DOS who tend to include the . directory in the path, so that the current directory is searched first. 

 

At any rate, that is why you have to specify ./myscript, only when you're trying to run a script in the current directory.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.