Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I think I may just be missing something simple, but I can not get PHP to run anything on the command line. I'm using Linux Ubuntu.

All the exact same files run as expected via the web. I have tried all the following commands which produce blank. My php install is located in "/usr/bin/php"

I am logged in as root.

root@mydomain:~# whereis php
php: /usr/bin/php /usr/lib/php /usr/lib64/php /usr/share/man/man1/php.1.gz

All return blank:

/usr/bin/php -v
/usr/bin/php -i
php -v
php -i
/usr/bin/php -v
echo "<?php echo \"hi\\n\";" | /usr/bin/php
echo "<?php echo \"hi\\n\";" | php
/usr/bin/php /var/www/vhosts/mysite.com/delme.php
/usr/bin/php -f /var/www/vhosts/mysite.com/delme.php  

Am I missing something obvious? Is there a setting I must set in order to run a command from the cli? I've tried everything for the past 4 hours with no luck. Any help will be appreciated.

As requested by a user:

root@mydomain:~# ls -l /usr/bin/php
lrwxrwxrwx 1 root root 21 Mar 17  2013 /usr/bin/php -> /etc/alternatives/php
root@mydomain:~# ls -l /etc/alternatives/php
lrwxrwxrwx 1 root root 13 Mar 17  2013 /etc/alternatives/php -> /usr/bin/php5
root@mydomain:~# ls -l /usr/bin/php5
-rwxr-xr-x 1 root root 0 Jan 19 12:42 /usr/bin/php5

root@mydomain:/usr/bin# /usr/bin/php5 -v
root@mydomain:/usr/bin# 
root@mydomain:/usr/bin# type -a php
php is /usr/bin/php
share|improve this question
    
Pleas post the output of ls -l /usr/bin/php. –  terdon Jan 19 at 15:36
    
root@mydomain:~# ls -l /usr/bin/php lrwxrwxrwx 1 root root 21 Mar 17 2013 /usr/bin/php -> /etc/alternatives/php –  kirgy Jan 19 at 17:12
    
Ah, interesting, and what does ls -l /etc/alternatives/php show? Your /usr/bin/php is a link to it, does that file actually exist? It sounds like your webserver has a working PHP executable in it's path but you don't. You'll have to follow the symlinks until you find the missing one. –  terdon Jan 19 at 17:17
    
I see, here is the following (sorry about the formating) root@mydomain:~# ls -l /etc/alternatives/php lrwxrwxrwx 1 root root 13 Mar 17 2013 /etc/alternatives/php -> /usr/bin/php5 root@mydomain:~# ls -l /usr/bin/php5 -rwxr-xr-x 1 root root 0 Jan 19 12:42 /usr/bin/php5 –  kirgy Jan 19 at 17:18
1  
Please edit your question and @ping me to let me know. It is hard to read and easy to loose in the comments. While you're at it, please add the output of /usr/bin/php5 -v. –  terdon Jan 19 at 17:19

1 Answer 1

Since your /usr/bin/php5 is empty, I assume youmust have inadvertently overwritten it at some point. The easiest way to fix would be to remove php and reinstall it:

sudo apt-get remove php5 && sudo apt-get install php5
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.