Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have installed XAMPP v1.8.3 for my PHP development. I am new to Ubuntu, so I don't know how to set environment variable for PHP which is located at /opt/lampp/bin/php.

I can run PHP scripts from localhost just fine, but I wanted to run them from the command line as well.

I want to set this variable for every user, since I am the only one who uses this system.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Environment variables are set in /etc/environment. You will find the $PATH variable in this file. This variable stores the path to binaries in various locations.

To add /opt/lampp/bin to the location searched for binary files, just append this path preceded by a : to the path variable.

For example, if the $PATH variable was:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

add /opt/lampp/bin to the end of it, so that it becomes:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/lampp/bin

After doing this, do a source /etc/environment.

share|improve this answer
    
@sud_the_devil: Just edited my answer. –  i08in Apr 13 at 14:32
    
I opened the file by issuing sudo subl /opt/lampp/bin/php and then appended the location as you asked me to do . Here's the link to the opened file. PATH Do I need to restart my system after that?? –  sud_the_devil Apr 13 at 14:38
1  
No, you don't need to restart your system. Can you paste the output of echo $PATH after you have added the path and done a source /etc/environment and ls /opt/lampp/bin/php? –  i08in Apr 13 at 14:41
1  
@sud_the_devil you are required to edit the environment file and not the php executable. Your command should be sudo subl /etc/environment –  Srihari Apr 13 at 14:47
2  
@sud_the_devil Add only /opt/lampp/bin, not /opt/lampp/bin/php which is the executable file. –  Radu Rădeanu Apr 13 at 14:48

As an alternative to /opt/lampp/bin/php, to run a php script from the command line, you just need to install php5-cli:

sudo apt-get install php5-cli

And run your script with:

php myscript.php
share|improve this answer
    
php5-cli is in a different package. –  Wutaz Apr 13 at 15:30
    
@Wutaz On what planet? (hint) –  e-sushi Jul 25 at 3:10

To open an interactive php shell, just type in a terminal:

php -a

As for opening a file, just:

php filename.php
share|improve this answer
    
The OP problem is: I don't know how to set environment variable for php which is located at /opt/lampp/bin/php . –  Radu Rădeanu Apr 13 at 17:08

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.