Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Now I have to type /usr/local/php5/bin/php to run php,

is there a way so that I just type php and it's run?

share|improve this question

4 Answers 4

you can either add an alias to your ~/.bash_profile file like so(http://freeunix.dyndns.org:8088/site2/howto/Bash.shtml):

 alias php=/usr/local/php5/bin/php 

for this i recommend using something else other than php though unless its the only php binary on your system

or you can either Symlink the to the php binary in /usr/local/php5/bin from /usr/sbin

ln -s /usr/local/php5/bin/php /usr/sbin/php

or add the directory to your PATH environment by editing or adding the following line in your ~/.bashrc file (you need to logout and in for this to work)

PATH=/usr/local/php5/bin:${PATH}

options 1 and 3 are only for your user, if you need it to work for all users of the system you need to use option 2

share|improve this answer
2  
Despite the massive comments on the other answer, yours is complete and has good explanations. One thing to note is that setting the PATH will introduce ordering if there's another php binary somewhere on his system (i.e., /usr/bin/php). Whichever path appears first will be used. –  Andrew M. Apr 6 '11 at 12:06
    
Please try to show the users the right path of doing that. Is not useful if on 3 weeks after an upgrade your solutions will not work. All 3 solutions from here will work, but only the PATH solution is 100% safe. –  Sacx Apr 6 '11 at 13:40
    
For the ordering of php binaries, type type -a php to see them all. –  glenn jackman Apr 6 '11 at 15:00
cd /usr/sbin
sudo ln -s /usr/local/php5/bin/php
sudo chmod +x php
share|improve this answer
    
Is not the good answer. It will work, but in future is possible to have problems when you try to install a real php5 distro and you will not know why is not working. –  Sacx Apr 6 '11 at 9:42
    
/usr/local/php5/bin/php means it was compiled from source. or im just one who uses /usr/local/blabla for source compiled programs. and .bashrc path wont work for zsh shell or some other ) –  MealstroM Apr 6 '11 at 9:44
    
Is compiled from sources, or are the third party binaries. This is the reason why is not a good idea to link in /usr/sbin. We should maintain clean system, to don't break the packages what are possible to come in the future. If is using zsh then it should use .zshrc, but the systems by default are coming with bash and not zsh. –  Sacx Apr 6 '11 at 9:48
    
hence why you use a symlink rather than placing the binary there.... it should get overwritten/replaced if you happen to install a binary package of something you have compiled from source (which is a very rare event because people compiling from source are less likely to be installing it from a binary down the line) –  anthonysomerset Apr 6 '11 at 9:49
1  
the first one what is in the path, and usually is /usr/bin. don't do symlinks by hand. You can use stow, update-alternatives etc etc, but, as I said, doing that by hand is dangerous for a new guy. –  Sacx Apr 6 '11 at 10:03

add in your .bashrc

PATH=/usr/local/php5/bin:${PATH}

logout and login again.

share|improve this answer

You can add /usr/local/php5/bin to your PATH, or you can make an alias

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.