# Why is the PHP version different in phpinfo() and CLI?

I realized that there is a miss matching between the PHP version reported by phpinfo() and php -v (in the CLI).

phpinfo():  5.5.24
php -v: 5.6.9


I am working on a Mac OS X 10.10 (Yosemite) and installed a library (php-version) to try to manage the PHP versions.

It reports me 3 different versions installed on my laptop:

  5.4.41
5.5.25
* 5.6.9


I would like to set the same version of PHP in both Apache and CLI.

How can I tell Apache which PHP version use?

I tried to write this line in my httpd.conf:

LoadModule php5_module    /usr/local/opt/php56/libexec/apache2/libphp5.so


Then:

sudo apachectl restart


But all this not solve the problem… In my PHP info I still have: 5.5.24

A few different issues here all hiding under the concept of PHP version confusion, so will try to address each one as clearly as possible. First this:

I realized that there is a miss matching between the PHP version reported by phpinfo() and php -v (in the CLI).

phpinfo():  5.5.24
php -v: 5.6.9


### PHP CLI is not the same as the PHP Apache module.

As I explain in the answer to this other question here, don’t panic! If you are concerned about what PHP version your Apache server is using, the output of phpinfo() is always what you should pay attention to. The Apache PHP module and the PHP command line binary are two different things that don’t interfere with each other.

Just pay attention to the output of phpinfo() if you are concerned about setting the correct PHP module version in Apache.

That said, you still seem to have issues getting the correct PHP module loaded in Apache:

I tried to write this line in my httpd.conf:

LoadModule php5_module    /usr/local/opt/php56/libexec/apache2/libphp5.so


While what you did technically looks to be correct, the only reason I can see for this to not work is somehow there is another LoadModule php5_module directive in the Apache config files that is superseding the value you are setting that line.

I would recommend looking through the httpd.conf—which I assume is located here /etc/apache2/httpd.conf—and see if perhaps there is indeed another LoadModule php5_module that you missed or did not notice when editing that file. Looking at my equivalent file in Mac OS X 10.9.5 I see the line is commented out—since I don’t use Mac OS X Apache/PHP setups—and reads something like this:

#LoadModule php5_module libexec/apache2/libphp5.so


Of course in your case it would be uncommented. More details on configuring Apache and PHP for web development can be found on this site.

### Seriously consider using MAMP as an alternative to Mac OS X Apache/PHP quirks.

Now all of that said, I don’t know what you are attempting to do, but if you are doing web development on a Mac OS X system you should seriously consider using MAMP instead of hacking the core Mac OS X web stack to get things running.

The benefit of MAMP is it’s an extremely production level Mac OS X equivalent of a LAMP stack. And since it’s geared towards real-world web development, it has all the modules and configs setup exactly as one should have them setup.

The core problem with Apache and PHP on Mac OS X is the software is typically out of date, a pain to configure/tweak and manage and a headache to debug when stuff like this happens. And what if a Mac OS X update comes along that wipes out your carefully setup Apache and PHP settings? You are back to square one.

• Why did you answer this Duplicate instead of marking the question as a duplicate? – Pmpr Mar 3 '17 at 14:55
• @Trix Because that “duplicate” is a similar answer to a different question posted within days of each other. As I answer to a similar comment here, “@bertieb Question is indeed similar to that other one. I just answered it, but there is specific issue here I will attempt to answer as well. – JakeGould Sep 12 '15 at 0:42” One question is about the difference between PHP from the command line. The other is about that AND PHP module issues. – Giacomo1968 Mar 3 '17 at 16:38

I found the solution to my problem. After editing /etc/apache2/httpd.conf I used to restart apache using:

sudo apachectl restart


For some reason using this command Apache would not fetch the updates in the httpd.conf and load the old config.

Using:

sudo apachectl -k stop
sudo apachectl -k start


Make a kind of hard restart of all the services and also reads the updates in the config file and finally read the new path for the php5_module:

/usr/local/opt/php56/libexec/apache2/libphp5.so


Thanks also @JakeGould for his explanation.

• Edited the post to remove the -k flag from the apachectl commands since if you check apachectl -h that flag/option does not exist there. No idea where you got that from. Also, while you state doing stop and start cleared things up, the odd thing is that restart on Linux systems does exactly that. If you check the script located in /usr/sbin/apachectl (it’s a script so use any text editor to view) it seems to do exactly that as well. Maybe on Mac OS X the LaunchDaemons for Apache is just “weird” when compared to standard Linux? Anyway, great you solved this. – Giacomo1968 Sep 12 '15 at 15:13
• Just for your info i found the command with the -k flag here: httpd.apache.org/docs/2.2/stopping.html – Salvatore Dibenedetto Sep 13 '15 at 8:51
• You are correct. I looked through the “help” output of /usr/sbin/apachectl (without any command) and it clearly states, [-k start|restart|graceful|graceful-stop|stop]. I am so used to the way Apache works on Linux systems now it seems I forgot about the -k flag for use with apachectl commands. So knowing that the real problem you had is you were attempting to restart with this command sudo apachectl restart when it should have had the -k flag added like this sudo apachectl -k restart. – Giacomo1968 Sep 13 '15 at 17:21

In my situation (windows server with composer installed), composer had also hard coded paths to various php extensions in php.ini (e.g. extension=C:/php7-3-27/ext/php_gd2.dll). So I needed to change those as well. This still didn't change the version being shown in phpinfo() called from an Apache web page. Turns out that composer had also added my old php version folder to the PATH environment variables, so I had to change that to point to my new PHP folder before I saw the version change take effect.

You do have to of course make sure your httpd.conf is updated per the other answers in this thread. But if that doesn't work, check what the path to php.ini is as listed in phpinfo() and check these ^^ things as well.