My phpinfo() shows the version to be 7.1.23. But when I execute php -v on terminal, it shows the version to be 7.3.10. How do I get the phpinfo version to be the same as the CLI/terminal? I followed the steps by user corretge on this question:
different result between phpinfo.php and php-v
which I assumed would resolve the issue, but it didn’t. I also added these lines to my httpd.conf file:
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
I added all the above code right below the last LoadModule (etc etc etc)
text. The location of my httpd.conf is:
/etc/apache2/httpd.conf
So doing all that for whatever reason did not work. I installed via Curl at first, it didn’t update the phpinfo version, and did the same just now via Homebrew, and same – no updated result.
I am using macOS High Sierra 10.13.6
When I run this command:
/usr/local/bin/php -v
the result is:
PHP 7.3.10
When I run this command:
/usr/bin/php -v
the result is:
PHP 7.1.23
2
Answers
Try to see what program your
/usr/bin/php
and/usr/local/bin/php
are actually calling:Very likely, just like @Always Sunny said, you will find out that you have two versions of the PHP installed on your machine. In other words, these links are calling different executables.
Your LoadModule directive in httpd.conf file points to php71 path. You may want to change that to php73 path. Also, set the handler properly:
If you just had one php version, then x-httpd-php would work.
Restart apache to ensure new configurations are loaded.
You may also need to do additional setup mentioned below. I am not sure if that’s necessary, but you may give it a try.
If you want to force web request to specific PHP version, you have 2 options:
1. php.ini modifications
In your php_info() output, you would see loaded configuration file – php.ini path. Go to that path and add the
2. Add the following directives in the .htaccess file of your website.
To switch to PHP 7.3
To switch to PHP 7.1
Details
PHP lets you load multiple php.ini files with a provision to override them in particular folder.
When you run the PHP script with phpinfo(), it would load the nearest php.ini to that file. It may be the root level or any other php.ini that is present in the folder hierarchy above.
Whereas when you run from terminal, it would run PHP from the path that is registered in your environment variable. When you run from terminal, I doubt apache configuration would come into the picture, so changing anything in apache configuration won’t have an effect on terminal execution. The Apache PHP module and the PHP command line binary are two different things that don’t interfere with each other.
If you want to force your terminal to use the version that you want, there are two options
1. Change the environment variable to run PHP in a specific version
This would have a path to your PHP. Remove that and put new one by
2. Change the PHP alias
You can also use an alias instead. Add the following to your .bash_profile file.
This works the same as the export PATH when added to your .bash_profile.