I install php via brew. With brew install PHP. My version of php-cli is 7.2
But, if I use phpinfo() on my server, I get php version 7.1.
If I use php -v in my terminal, I get php version 7.2.
Disclaimer: I'm adding this hopefully extensive answer as part of the Revival badge. (Answer more than 30 days after a question was asked as first answer scoring 2 or more)
TL;DR
php -v settings can be different from phpinfo() inside your web-server due to the running service state of fpm and your webserver. Perhaps you need to restart php-fpm and/or your web-server (apache, nginx, ..).
Long version: Command line
Command-line based calls like php -v or php -i or php test.php will read your configuration, options and arguments every time you execute your script within a terminal.
This means if you update php in your operating system then you'll get the most recent version in your terminal session.
Attention: Depending on your PATH variables you still might get an older version.
What does this mean? Even if you update your php version on your operating system you might still have an older terminal session which links to an older php-binary.
Here is an example: I am an OSX user and installed php through brew. Currently php links to php#7.3. Here is my way to validate which versions are running where. For this I'm using which php.
$ which php
/usr/local/opt/php#7.3/bin/php
$ php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:42) ( NTS )
// or the equivalent "absolute path" example
$ /usr/local/opt/php#7.3/bin/php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:42) ( NTS )
I have multiple php-versions installed on my local system. I can run them all individually. Here is an example:
$ /usr/local/opt/php#7.2/bin/php -v
PHP 7.2.20 (cli) (built: Jul 5 2019 12:56:54) ( NTS )
Long version: Why is my phpinfo() using the wrong php version?
Since we now have an understanding that we can run multiple and different versions of php on a single operating system, lets dig into our web-server based script which runs phpinfo().
After installing a new php-version you'll have your binaries replaced by new versions. Awesome! but.. how does my running web server get notified about it?
For this I'll refer to the php documentation Apache 2.x on Unix systems Point 7. Also apache allows us to load different modules for PHP.
Edit your httpd.conf to load the PHP module. [...]
For PHP 7:
LoadModule php7_module modules/libphp7.so
For PHP 5:
LoadModule php5_module modules/libphp5.so
Since you are upgrading from PHP 7.1 to PHP 7.2 there is probably no change but your webserver is still running the old linked version of php.
In this case a restart of your apache webserver should help so it can pickup the new binaries correctly.
Please let me know if this will help you to solve your issue. For all the other readers: If you think there is something missing OR there is something wrong in my explanation then please let me know with a comment.
Related
I have an Ubuntu 16.04 vagrant box running on php 7.1. When I try to build xdebug by running ./configure in xdebug-2.6.0 I get
Check for supported PHP versions... configure: error: not supported. Need a PHP version >= 7.0.0 and < 7.3.0 (found 5.5.9-1ubuntu4.24)
PHP -v yields
Xdebug requires Zend Engine API version 320170718.
The Zend Engine API version 320160303 which is installed, is outdated.
PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018 11:27:08) ( NTS )
So the system is running 7.1, but for some reason the configure script thinks we're still on 5.5.9
I've hit google pretty hard, but still can't find a way to update the Zend engine either.
Any ideas?
It happens because you're configuring with default settings and that is different from the PHP version you're trying to configure.
Just like you saw the PHP version using the php -v command, check the php-config version using the php-config --version command, it should be the same as php -v, but in your case, it would be different and hence this issue.
Now let's talk about how we can solve it. Since you need a different version of config, you should point that to the configure command.
For example, in your case, you need php-config7.1 (because you're using PHP v7.1, similarly for 7.2 you have php-config7.2 and so on)
To point the configure command to a specific PHP version you need to specify that as a flag called with-php-config and the value should be the location of the php-config file, a sample would be
./configure --with-php-config=/usr/bin/php-config7.1
Hope this solves the problem.
I assume you run phpize before running ./configure. Instead you need to run phpize7.1 and then ./configure
if you don't have phpize7.1 installed you can install it via:
sudo apt install apt install php7.1-dev
I tried to install Phalcon PHP but I got an error
php 5.3 is no longer supported
I check PHP Version
$ php -v
return
PHP 7.0.25-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct 27 2017 13:43:45) ( NTS )
but I check in phpinfo();
PHP Version 5.6.32-1+ubuntu16.04.1+deb.sury.org+1
Phpinfo() will always show the version your server is currently running. You will need to change the php version that apache is using. You can do this by disabling PHP 5 module by checking your apcahe files or disabling with 'sudo a2dismod php5'. Then you will need to enable php 7 by allocating in your files or again enabling it with 'sudo a2enmod php7.1'. To see results you will need to restart apache. I hope this helps
I installed the apm on my Linux (Centos7) and i think i installed the php again with yum.
I have two php.ini file in the paths below.
/usr/loacal/php/bin/php.ini (v5.3)
/etc/php.ini (v5.4)
php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
/usr/local/php/bin/php -v
PHP 5.3.27 (cli) (built: Mar 3 2016 11:17:12)
I have two versions of php on one server right now.
rpm -qa | grep php
php-pdo-5.4.16-36.el7_1.x86_64
php-tcpdf-6.2.11-1.el7.noarch
php-tidy-5.4.16-3.el7.x86_64
php-xml-5.4.16-36.el7_1.x86_64
php-mbstring-5.4.16-36.el7_1.x86_64
php-cli-5.4.16-36.el7_1.x86_64
php-php-gettext-1.0.11-12.el7.noarch
php-bcmath-5.4.16-36.el7_1.x86_64
php-gd-5.4.16-36.el7_1.x86_64
php-process-5.4.16-36.el7_1.x86_64
php-common-5.4.16-36.el7_1.x86_64
php-mysql-5.4.16-36.el7_1.x86_64
php-tcpdf-dejavu-sans-fonts-6.2.11-1.el7.noarch
I think this all files are installed with php(v5.4)
I can I remove these?
Can i just use the yum command again like below?
yum remove php
I'm so afraid that something happens when i do that.
Please let me know how to deal with this situation... Thanks
You might not need to remove anything. You can have as many versions of PHP installed as you like. The PATHS etc determine what actually gets used. To see what php binary is being used on command line use
which php
To see what php.ini file is being used by that binary use
php -i |grep "php.ini"
If you have the correct one then you're probably fine. To see what files will be remove by removing packages you can query the package to get the file list ie
rpm -ql php-common-5.4.16-36.el7_1.x86_64
The common package should contain the php.ini file that gets installed. From these commands you should be able to work out if you want to remove anything.
Note, if you can, use the more modern versions of PHP that you have installed. PHP 5.3 and 5.4 are both considered old versions now and are no longer supported.
https://en.wikipedia.org/wiki/PHP#Release_history
I am trying to get the Symphony framework installed on my laptop (running OS X 10.9 Mavericks), so far I can't even get it started because of error messages
The first thing not being an error but it seems that I have multiple versions of PHP running and I would like to remove everything except the latest version (5.5.12). Can someone please tell me how I can achieve this?
I compiled and built the newest version of PHP from source and installed it (which should replace the original version), however I am seeing 2 different versions when using phpinfo() from a webpage and php -v from the command line:
phpinfo(): PHP Version 5.4.24
php -v: PHP 5.5.12 (cli) (built: May 29 2014 11:21:46)
I compiled and built the newest version of PHP from source and
installed it (which should replace the original version), however I am
seeing 2 different versions when using phpinfo() from a webpage and
php -v from the command line:
PHP from the command line is 100% different from PHP as loaded via an Apache module. So wiping out the old version won’t solve this issue & might cause other issues. Don’t ever attempt that. Instead just install the version of PHP you want to run and edit your Apache config to load the proper libphp5.so PHP 5.5.12 module.
In my Mac OS X 10.9.3 install the default system Apache config is located here:
/private/etc/apache2/httpd.conf
And in there is a commented out line—might be uncommented in yours—that reads:
#LoadModule php5_module libexec/apache2/libphp5.so
So you need to just make sure you create a similar line to the libphp5.so PHP 5.5.12 module like so:
LoadModule php5_module /path/to/the/new/version/of/php/libphp5.so
Making sure to change that /path/to/the/new/version/of/php/ to match your actual libphp5.so PHP 5.5.12 module.
Then restart the Apache web service & all should be good.
Remember this: When it comes to Unix/Linux tools & configurations, you never have to forcefully uninstall components to solve issues like this. It’s all about getting the configuration straight.
All that said, you might make your live easier by running MAMP instead of compiling from source like this. MAMP is a self-contained LAMP stack for MAMP that has the latest versions of PHP installed. And since it runs as an application, none of the issues you are facing compiling from source will ever happen when you use MAMP.
Thanks for your help. I realized that I had installed so many things with MacPorts (programming my Arduino among other things) that I just decided to wipe my drive and reinstall OS X 10.9
Then I just followed this tutorial and finally got everything working properly
http://dab.io/posts/install-symfony-on-os-x-mavericks.html
My phpinfo.php on apache shows
PHP Version 5.4.15
but commandline
php - v
shows
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
I think apache and commandline reaches the different php,however
which php
shows only
/usr/bin/php
it is 5.4.17
I would like to know where php apache uses, and how can I check which php apache uses?
I think this depend on if you run php files using mod_php5 or cgi. The difference is explained in the accepted answer in this question: What is mod_php?
As I understand it, basically mod_php5 is pre-compiled from a specific PHP version that Apache will than use. While if CGI is used to run PHP the installed PHP command line version will be used when spawning a new process each time a PHP file is executed.
Hope this helps.