tags:

views:

212

answers:

5

I'm trying to follow the instructions here: http://www.php.net/manual/en/features.commandline.usage.php

  • I created a file named "vardump"
  • Added this code to the file:

    #!/usr/bin/php
    <?php
    var_dump($argv);
    ?>
    
  • did chmod +x vardump
  • but I'm getting a permission denied error when executing the file:

    shiki@Etna:~/projects/tests$ ./vardump
    bash: ./vardump: Permission denied
    shiki@Etna:~/projects/tests$ sudo ./vardump
    sudo: unable to execute ./vardump: Permission denied
    

What could be the problem? I'm running Ubuntu 10.04.

Executing it like this works though:

shiki@Etna:~/projects/tests$ php vardump
array(1) {
  [0]=>
  string(7) "vardump"
}

Here are the file permissions:

shiki@Etna:~/projects/tests$ ls -l
-rwxrwxrwx 1 root root   41 2010-06-23 07:25 vardump

shiki@Etna:~/projects/tests$ ls -l /usr/bin/php
lrwxrwxrwx 1 root root 21 2010-06-02 15:34 /usr/bin/php -> /etc/alternatives/php
+1  A: 

Do you have permission to run /etc/alternatives/php on the system? t's possible that when you run the scripts with php vardump it's using a different php binary than /etc/alternatives/php. To check that, run which php and see what it prints out. Also, what's the output of ls -l /etc/alternatives/php.

Matrix Mole
It's `lrwxrwxrwx 1 root root 13 2010-06-02 15:34 /etc/alternatives/php -> /usr/bin/php5`
Shiki
Known that `which php` is `/usr/bin/php` it's possibly something to do with the php installation as Marco mentioned
Matrix Mole
+3  A: 

Are you possibly using two different php instances? Run the following, is it something other than /usr/bin/php?

which php
labratmatt
No, it's still `/usr/bin/php`
Shiki
+1  A: 

I would run which php - I know on Ubuntu that php is linked to /usr/bin/php (tested on Ubuntu 10.04 Desktop and Server your script runs fine with both 0777 and 0755 permissions on my machine using the following:

marco@FW2X9K1:~/Projects$ php -v
PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:03:45) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

marco@FW2X9K1:~/Projects$ ls -lah vardump 
-rwxrwxrwx 1 marco marco 41 2010-06-22 20:17 vardump
marco@FW2X9K1:~/Projects$ ls -l /usr/bin/php
lrwxrwxrwx 1 root root 21 2010-05-26 09:15 /usr/bin/php -> /etc/alternatives/php
marco@FW2X9K1:~/Projects$ ls -l /etc/alternatives/php
lrwxrwxrwx 1 root root 13 2010-05-26 09:15 /etc/alternatives/php -> /usr/bin/php5
marco@FW2X9K1:~/Projects$ ls -l /usr/bin/php5
-rwxr-xr-x 1 root root 7836792 2010-05-13 16:20 /usr/bin/php5

marco@FW2X9K1:~/Projects$ ./vardump 
array(1) {
  [0]=>
  string(9) "./vardump"
}

This likely will need to be posted in serverfault. Lastly run the following to ensure everything is installed correctly.

marco@FW2X9K1:~/Projects$ dpkg -l | grep php5
ii  libapache2-mod-php5                  5.3.2-1ubuntu4.2                                      server-side, HTML-embedded scripting languag
ii  php5                                 5.3.2-1ubuntu4.2                                      server-side, HTML-embedded scripting languag
ii  php5-cgi                             5.3.2-1ubuntu4.2                                      server-side, HTML-embedded scripting languag
ii  php5-cli                             5.3.2-1ubuntu4.2                                      command-line interpreter for the php5 script
ii  php5-common                          5.3.2-1ubuntu4.2                                      Common files for packages built from the php
ii  php5-dev                             5.3.2-1ubuntu4.2                                      Files for PHP5 module development
ii  php5-mysql                           5.3.2-1ubuntu4.2                                      MySQL module for php5
Marco Ceppi
+1  A: 

I think Marco Ceppi might be onto something. Do you have the php5-cli package installed? Have a look at http://ubuntuforums.org/archive/index.php/t-1172223.html for more details.

labratmatt
Yes, php5-cli is installed. I think that's why `php vardump` works.
Shiki
+1  A: 

Solved it. Based on all your answers, I suspected the problem is not in php at all. I'm running the script on a NTFS mount so I tried to move it to the root mount and it worked there. So I added exec to /etc/fstab and it worked.

UUID=0B02861D7B0D6A31 /media/Data ntfs-3g defaults,users,exec,locale=en_PH.UTF-8 0 0

This answer also gave me the clue for it. Thanks a lot for all your help!

Shiki
Nice. Thanks for posting the answer to the thread for future reference.
labratmatt