Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 11 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:


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


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

share|improve this answer
@sud_the_devil: Just edited my answer. – i08in Apr 13 '14 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 '14 at 14:38
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 '14 at 14:41
@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 '14 at 14:47
@sud_the_devil Add only /opt/lampp/bin, not /opt/lampp/bin/php which is the executable file. – Radu Rădeanu Apr 13 '14 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 '14 at 15:30
@Wutaz On what planet? (hint) – e-sushi Jul 25 '14 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 '14 at 17:08
@darent Thanks. This was the first search result I got from Google and php -a was exactly what I looked for. – Martin Thoma Feb 25 '15 at 16:52

You can use

php /var/www/html/yourProjctFolder/yourFile.php

This will call your php file and output if you have written echo or print statement

share|improve this answer

Your Answer


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.