How to fix a PHP version problem between CLI and Apache2

OK, allow me to vent here a little bit: Suse Linux SUCKS! And PHP is a steaming smelly piece of ______________!!

There, I feel better. ;-)

OK, here is the problem: one of the suckers that pass for a "programmer" here (PHP is not programming, since PHP is a steaming smelly piece of ______________, remember?) reports that the freaking phpinfo() says that PHP is version 5.2.12, while rpm indicates that the installed version of PHP is: 5.4.14.

For instance:

galactus# rpm -qa | grep -i php

Another way to check the PHP version is, of course, to ask PHP directly. Here are several ways to do this:

 # $(which php) --version
PHP 5.4.14 (cli) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Suhosin v0.9.34-dev, Copyright (c) 2007-2012, by SektionEins GmbH
edc2hgtst01:~ # $(which php) -i | grep -i php.version
PHP Version => 5.4.14
PHP Version => 5.4.14

All right, so now, we know the version really is 5.4.14. Good.


To understand this solution, you have to know that Suse Linux separates the PHP configuration into two different parts: the CLI (command-line) version and the Apache version, which is used by... well, Apache, of course!

The two configurations are kept in separate directories and one configuration is not exactly the same than the other...

BUT more importantly, upgrading the installed PHP does not mean the module used by Apache is always upgraded. And you can check that with the following commands:

galactus# find / -name

OK, so we do have two files named Let's learn more about these:

galactus# ll /usr/lib64/apache2/ /usr/lib64/apache2-prefork/
-rw-r--r-- 1 root root 2980144 Jan 27  2012 /usr/lib64/apache2-prefork/
-rw-r--r-- 1 root root 9480360 Apr 15 14:24 /usr/lib64/apache2/

Wait a minute! These two files are not identical!! There is a good chance Apache is using the oldest one, dated Jan 27 2012.

From there, the solution is fairly easy. Let's start by making a copy of the oldest file:

galactus# cp -v /usr/lib64/apache2-prefork/ /usr/lib64/apache2-prefork/
`/usr/lib64/apache2-prefork/' -> `/usr/lib64/apache2-prefork/'

Now that we have a copy (just in case...), let's delete the original version:

galactus# rm -v  /usr/lib64/apache2-prefork/
removed `/usr/lib64/apache2-prefork/'

Now, let's just create a symbolic link to the correct (newer) file:

galactus# ln -v --symbolic /usr/lib64/apache2/ /usr/lib64/apache2-prefork/
`/usr/lib64/apache2-prefork/' -> `/usr/lib64/apache2/'

And let's restart the Apache server, since I forgot to stop it at the beginning... ;-)

galactus# /etc/init.d/apache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to terminate)                                                                  done
Starting httpd2 (prefork)                                                                                                     done

And... We are done! The phpinfo() function now reports the proper version of PHP, as well as all the other functions provided by PHP. Whew!

Hope this helps!!


How can you run a phpinfo function from the command-line? Simple enough:

# php -r "phpinfo();" | less

This should display way more information than you need on PHP... But remember: this is the CLI version, and not the Apache version, and the two may differ if you haven't performed the steps detailed above!!

To create a nice PHP file to do the same from within Apache, use the following:

<?php phpinfo(); ?>

You can also run this file from the command-line with: php -f ./phpinfo.php.