0

I am new to Linux. It's my first time working with the command line and I'm trying to make it a web sever for learning purposes, so I am not going for lamp stack. Instead I am installing all the programs like apache, php, and mysql manually.

I got apache working and php is working as well but the problem I'm facing is that I can't run commands like php -i. Instead I have to run it like path/to/php/bin-directory/php -i.

In Windows we can achieve this by adding environment variables so I looked around, and it seeme like we can do the same thing in Ubuntu. So I modified the /etc/environment file and added the path to php, and I also tried adding the path via this command:

export PATH=$PATH:/path/to/php/bin-directory/

Both these methods worked and added the path to the environment variable. I confirmed it via printenv, but I am still unable to call the php command directly with php -i.

I am not even sure if that's how it's supposed to work, so any suggestions are appreciated.

Thanks

Edit:

Output of a few commands:

output of few commands

wjandrea
  • 14,109
  • 4
  • 48
  • 98
user2801966
  • 111
  • 5
  • Please add to your question the output of commands `echo $PATH`, `which php`, `php -i` and `ls -l /path/to/php/bin-directory/php`. For the last command please replace the /path/to/... with the actual path. – sмurf Nov 08 '16 at 03:11
  • @sмurf I just linked an image of the output of commands, `php -i` prints a lot of text so do you need anything specific from that ? – user2801966 Nov 08 '16 at 03:41
  • Please don't post screenshots of text. Instead copy the text here and apply code formatting. – muru Nov 08 '16 at 04:09
  • 1) Use `echo $PATH` rather than `echo $Path` (unix/linux is case sensitive) 2) You say "`php -i` prints a lot of text ..." but in your question you say "...I am still unable to call the php command directly `php -i`" - which one is true? 3) it looks like you can start /usr/local/php/bin/php manually, that is good. – sмurf Nov 08 '16 at 04:10
  • @sмurf I just ran `echo $PATH` and the path to the `php/bin` directory was not there, it seems like everytime I restart the machine it removes the path. And I just checked `php -i` works directly when the path is there in the file. So the problem is with the path getting removed from the environment file, any suggestions about this? – user2801966 Nov 08 '16 at 04:24

1 Answers1

0

Every time you execute command:

export PATH=$PATH:/path/to/php/bin-directory/

you modify the environment in the current shell, i.e. the program executed in the terminal window. That change will not happen to other terminal windows (or even other tabs on the current terminal program). That change would not survive logoff/logon and/or restart.

To make that change persistent see question How to add a directory to the PATH?

sмurf
  • 4,660
  • 1
  • 23
  • 29
  • I fixed the issue by opting for solution provided here : http://askubuntu.com/questions/500775/permanent-path-variable . But thanks for explaining it further. – user2801966 Nov 08 '16 at 05:41
  • Not so fast... You fixed the issue for interactive sessions only. Depending on your Apache configuration it may not necessarily be able to find php in a non-standard location. – sмurf Nov 08 '16 at 06:32