0

When I run php -v in cli I get the exact php version 7, but when i run exec("php -v") in web server I get php 5.5 even thought in phpinfo i see that I am runing php 7?! Any idea why I get the older version of PHP?

Sasser
  • 45
  • 8

2 Answers2

1

running exec you get the CLI version of PHP you probably installed php5.5 as CLI and php7 as apache module

sylvain
  • 1,951
  • 2
  • 19
  • 34
  • when I check on terminal about my php -v I can see that my version of php is PHP7 – Sasser Nov 21 '16 at 20:07
  • run `which php` in both you script and command line. Also the php configured for your apache user (ie : www-data) may differ from the php cli for user – sylvain Nov 21 '16 at 20:23
  • it shows me the path where my php is located /local/bin/php – Sasser Nov 21 '16 at 20:49
  • Both which show the exact same path to php ? I think it's not possible : if you have 2 concurrent versions of php they've got to be on different locations – sylvain Nov 21 '16 at 22:35
  • when i run whereis php it shows both the same location. I dont know for what reason which php i do not get the result in php script – Sasser Nov 21 '16 at 22:53
1

If you use CentOs, add this line at the end of /etc/bashrc (or ~/.profile for Ubuntu)

 export PATH=$PATH:/your/path/to/php7/bin

Then run: source /etc/bashrc

P/s It may be better if you edit /etc/profile.d. Take a look both of them.

UPDATE

In MacOS, let edit ~/.bash_profile (create it if it does not exist) with the same content.

Davuz
  • 5,040
  • 13
  • 41
  • 61
  • Why is this used for? when I run php -v in command line I get php 7 version it's just when I run exec("php -v") on controller of symfony project I get the wrong version of php (php 5.5). – Sasser Nov 21 '16 at 20:09
  • It's Environment Path. You have to declare PATH for OS know where to find and run the executed files. When you run `php -v`, the cli version will run, not the php web server process. So, let point OS out to php bin dir – Davuz Nov 21 '16 at 20:13
  • I am using CentOS. And sorry but Im new in using CentOS where can I find the path to execute this commands? – Sasser Nov 21 '16 at 20:21
  • Try `which php`, `whereis php` or create `info.php`, which contain "". Put it in your web root, access localhost/info.php and look up the path in there. Maybe you will find in configure params or further... – Davuz Nov 21 '16 at 20:36
  • I am able to find the path of the php exe file but not the ~/.bashrc is it possible that it does not have and i have to create it? – Sasser Nov 21 '16 at 20:45
  • Sorry, I have a confusion between CentOs and Ubuntu. With centos, it places at /etc/bashrc – Davuz Nov 21 '16 at 20:49
  • I used macports to install apache2 and php, and I do not find any file as bashrc – Sasser Nov 21 '16 at 20:54
  • If you use CentOS, it certain places at /etc/bashrc or /etc/profile.d. It is not related to apache, php or macport – Davuz Nov 21 '16 at 20:56
  • I am using OS X El Capitan and I dont have under /etc/ folder bashrc or profile.d ?! – Sasser Nov 21 '16 at 21:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128658/discussion-between-sasser-and-davuz). – Sasser Nov 21 '16 at 23:28
  • hi @Sasser , sorry for late, if you use Mac OX, plz either create or edit `~/.bash_profile` . See more here http://stackoverflow.com/questions/30461201/how-do-i-edit-path-bash-profile-on-osx – Davuz Nov 22 '16 at 03:19
  • hi @Davuz, sorry for late respond, I resolve the problem by updating the path in php-fpm. I needed there to to update the path. – Sasser Dec 03 '16 at 16:49