Two different PHP versions running at the same time - php

Based on this answer I've updated my local PHP to 7.0. This worked as expected when I browser to a file with phpinfo()
When I use the terminal command php -v I get version 5.5.26
As stated in the FAQ I have to add
export PATH=/usr/local/php5/bin:$PATH
to the ~/.profile (which I had to create)
but the result is the same: php -v still shows the 5.5 version

Related

PHP version is not changing after write statement into bash-profile

I tried to make the xampp php version as a default php instance. At the moment the build in php version is default. In the nano .bash_profile I write the statement
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
and this is no stored in the bash_profil. But when I check the php version via php -v I get the older one. Any idea?
exec "$SHELL" to load your recently changed .bash_profile. That should do it.

CentOS ./configure -- how to use alternate PHP version

I am quite new to CentOS.
On my CentOS web server I have PHP 5.4.16 as a native PHP version though I also have alternate PHP version 7.0.
I am trying to install xDebug for PHP 7.0 following the instruction on https://xdebug.org and one of the steps is to run
./configure
When I run ./configure command I am getting error message:
not supported. Need a PHP version >= 5.5.0 and < 7.2.0 (found 5.4.16)
So my question is how do I tell ./configure to use alternate PHP version 7.0?
If you run php -v on command line, it will output the version of PHP it is currently on your PATH. My guess is that it will return the older version of PHP as the result.
The quick and dirty way to try and get it to use version 7.0 for your current shell session would be to run the following
set PATH="/your/path/to/php7/bin:$PATH"
php -v
//Should output version 7.0
You could also try checking in /usr/bin or /usr/local/bin to see exactly which PHP binary it's pointing to, and manually change the location that the symlinks are pointing to.
Another option would be to try creating an alias in your ~/.bashrc file for PHP by editing the file and adding the following to the end:
alias php="/your/path/to/php/7/bin/php"
Then restart your shell session (i.e. close an & re-open PuTTY or whichever SSH client you're using).
Now type php -v and you should see it change to version 7.0.

I'm getting php5.5 instead php7 when I run exec(php -v) in php script

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?
running exec you get the CLI version of PHP
you probably installed php5.5 as CLI and php7 as apache module
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.

Wrong PHP version after installation (OSX)

I am running OSX El Capitan which comes (if I am not wrong) with PHP 5.5.
So I updated my PHP version using this Terminal command:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
And from the docs :
php-osx doesn't overwrite the php binaries installed by Apple, but
installs everything in /usr/local/php5. The new php binary is
therefore in /usr/local/php5/bin/php.
You can also adjust your PATH do include that directory, eg. write
into your ~/.profile file the following
So I did what have been suggested, but still, my php version (shown by php -v) is 5.5 rather than 5.6.
What I am missing here?
After editing ~/.profile or ~/.bash_profile you either have to restart your terminal or do source ~/.profile so the changes take effect immediately.

Ubuntu Command Line Reports PHP version as 5.3.3 but phpinfo says 5.5.9

When I look at a phpinfo page on my ubuntu server it says the php version is 5.5.9. But when I do a php -i or -v from command line it says php version 5.3.3 and it doesn't list the modules I've installed in 5.5.9.
I guess I have two versions running. How do I get rid of 5.3.3 so command line reports 5.5.9?
Do a locate bin/php to see all files on your system that might possibly be PHP binaries. Then do a which php to see which one would be executed. I have one in /usr/bin/php and a self-compiled version in /usr/local/bin/php53, of varying versions.
To run things on the command line with the other version, you can specify the full path of PHP thus: /usr/local/bin/php /command/to/run and it will run that. Or, add the path to the new version to your system path at the start, and this will "see" the new PHP version before the old one.
If you are running this thing from cron, I tend to recommend using the full path to the PHP interpreter anyway - I think it's a good habit, in case the available paths are different between your environment and the cron environment.

Categories