2

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
Shiki
  • 16,688
  • 7
  • 32
  • 33
  • Is this a programming question? Also, it doesn't seem to be related to php. – Mewp Jun 22 '10 at 23:58
  • what does `ls -l /usr/bin/php` show you? – Wrikken Jun 23 '10 at 00:00
  • @Mewp I'm not really sure myself. Should this be in superuser? – Shiki Jun 23 '10 at 00:04
  • @Wrikken I've edited the question to show the result for that – Shiki Jun 23 '10 at 00:08
  • What happens after you `chmod 0755 vardump`? Right now, permissions on it are 777, and that's an itsy bit dangerous as root. – Charles Jun 23 '10 at 00:15
  • If php binary executes, it's a programming question, because it's something in your php code (though it doesn't seem that it is). Otherwise, it has nothing to do with php, therefore nothing to do with programming, so... probably superuser. – Mewp Jun 23 '10 at 00:23
  • @Charles hmm.. that's weird, the permission is still 777 after I did that – Shiki Jun 23 '10 at 00:23
  • @Shiki: that's a symlink, please keep following it's target (probably something from -> /etc/alternatives/php -> /usr/bin/php5) until you actually reach the 'normal' file, and give the filepermissions / `ls -l` output of that one. – Wrikken Jun 23 '10 at 00:30
  • @Shiki, something is freaky wrong. Setting permissions to 0755 should have set them to 0755, not to 0777... Have you ever touched your umask? (Then again, the umask is entirely subtractive, it shouldn't matter...) – Charles Jun 23 '10 at 00:32

5 Answers5

5

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!

Community
  • 1
  • 1
Shiki
  • 16,688
  • 7
  • 32
  • 33
3

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

which php
labratmatt
  • 1,821
  • 2
  • 20
  • 21
1

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.

1

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
  • 7,163
  • 5
  • 31
  • 43
1

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
  • 1,821
  • 2
  • 20
  • 21