Details:

Distributor ID: Ubuntu
Description:    Ubuntu 12.04.5 LTS
Release:        12.04
Codename:       precise
Bitnami used in AWS

I want to install PHP 5.5, so I do next step:

php -v
PHP 5.4.26 (cli) (built: Apr  8 2014 10:05:18)

sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5

Reading package lists... Done
Building dependency tree
Reading state information... Done

php5 is already the newest version.

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

When I use command:

sudo apt-cache policy php5

I get next:

php5:
  Installed: 5.5.29+dfsg-1+deb.sury.org~precise+3
  Candidate: 5.5.29+dfsg-1+deb.sury.org~precise+3
  Version table:
 *** 5.5.29+dfsg-1+deb.sury.org~precise+3 0
        500 http://ppa.launchpad.net/ondrej/php5/ubuntu/ precise/main amd64 Packages
        100 /var/lib/dpkg/status
     5.3.10-1ubuntu3.19 0
        500 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ precise-security/main amd64 Packages
     5.3.10-1ubuntu3 0
        500 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

I check files by:

locate bin/php

/opt/bitnami/php/bin/php
/opt/bitnami/php/bin/php-cgi
/opt/bitnami/php/bin/php-cgi.bin
/opt/bitnami/php/bin/php-config
/opt/bitnami/php/bin/php.bin
/opt/bitnami/php/bin/phpize
/opt/bitnami/php/sbin/php-fpm
/usr/bin/php
/usr/bin/php-cgi
/usr/bin/php-config
/usr/bin/php-config5
/usr/bin/php5
/usr/bin/php5-cgi
/usr/bin/phpize
/usr/bin/phpize5
/usr/lib/cgi-bin/php
/usr/lib/cgi-bin/php5
/usr/sbin/php5-fpm
/usr/sbin/php5dismod
/usr/sbin/php5enmod
/usr/sbin/php5query

which php

/opt/bitnami/php/bin/php

Also I find file /home/bitnami/.bashrc where I see next PATH:

PATH="/opt/bitnami/varnish/bin:/opt/bitnami/sqlite/bin:/opt/bitnami/php/bin:/op$
export PATH

So if I use command /usr/bin/php -v I get my last version PHP 5.5:

PHP 5.5.29-1+deb.sury.org~precise+3 (cli) (built: Sep  8 2015 12:58:11)

But if I use php -v or phpinfo in my site get always old version PHP 5.4:

PHP 5.4.26 (cli) (built: Apr  8 2014 10:05:18)

How I can switch PHP version to 5.5? What I need to do? What I need to write in settings to enable PHP 5? or what need change in Apache settings?

up vote 2 down vote accepted

Shorter answer.

Don’t panic! If you are concerned about what PHP version your Apache server is using, the output of phpinfo()—via the Apache web server—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.

In fact you can compile and load various PHP versions you want to work with Apache as long as you adjust Apache to properly load it. The PHP command line interface will never come into play in the case of Apache parsing PHP pages.

Longer answer.

You say this:

But if I use php -v or phpinfo in my site get always old version PHP 5.4:

PHP 5.4.26 (cli) (built: Apr  8 2014 10:05:18)

The version of PHP available from the command line has 100% nothing to do with the version of PHP loaded as a module. These are completely separate things.

So if you are concerned about which version of PHP your web application is using, if phpinfo() shows version PHP 5.5.29 and that is what you want/need that is 100% fine.

The command line version of PHP is a completely separate system item. So the only thing that matters is the output of phpinfo().

If you have not checked the version of PHP being used by Apache by using phpinfo() yet, it’s easy. In the web root of your server, just create a file called phpinfo.php like this; using nano in this example:

nano phpinfo.php

Now just add this to that file and save it:

<?php

phpinfo();

?>

Then load that phpinfo.php via a web browser URL like this:

http://hostname/phpinfo.php

And check the output returned. There should be tons of configuration details presented but the main thing you want to check is the header which should say something like, “PHP Version 5.4.26” or “PHP Version 5.5.29.” That is the version number you want to pay attention to.

If for some reason you wanted to use a different version of PHP with Apache than what that shows, all you need to do is install the compiled Apache PHP module (libphp5.so) somewhere and add—or adjust—this line in your system’s Apache config:

LoadModule php5_module    /path/to/php/and/the/module/for/apache2/libphp5.so

And just adjust the path to the libphp5.so—which is what Apache uses to parse PHP—then restart Apache and you are in business.

For example, at one point I had to compile PHP version 5.1.6 from source (with GD library support) for use on an Ubuntu 12.04 machine running PHP 5.3.5. In the server’s PHP module loading file here:

sudo nano /etc/apache2/mods-available/php5.load

I had lines like this:

# LoadModule php5_module        /usr/lib/apache2/modules/libphp535.so
LoadModule php5_module        /usr/lib/apache2/modules/libphp516-gd.so

Note how one line is commented out for libphp535.so and the other one for libphp516-gd.so is uncommented? What I did is I renamed the default PHP 5.3.5 libphp5.so Apache module to libphp535.so with the version number in the name so I could have it there for reference and then named the PHP 5.1.6 (with GD library support) module libphp516-gd.so so I know what that is as well. This way I have them both available to me side-by-side on the system.

And—like I said at the outset—the PHP version used in the command line has utterly nothing to do with the Apache PHP module. So you can have any number of different versions of Apache PHP modules sitting on the system ready to go; just adjust a config and restart Apache and you should be all in business to use whatever PHP version you specified Apache should use.

Finding the new PHP 5.5 libphp5.so file.

If you are unsure where the new PHP 5.5 libphp5.so file is do the following. First, install locate on your system if it isn’t installed already:

sudo apt-get install locate

Once installed, force locate to update it’s database like this:

sudo updatedb

Wait for locate to rebuild the file system database; it basically is like Spotlight in Mac OS X but for Linux. Now with that done, do a locate search for libphp5.so like this:

locate libphp5.so

There should be a few lines on your setup that get returned:

/usr/lib/apache2/modules/libphp5.so
/path/to/the/php5.5/location/of/libphp5.so

The first path is the default PHP 5.4 libphp5.so but the one the other one should be the path to the PHP 5.5 libphp5.so Apache module. Once you know that path, open up the php5.load file like this:

sudo nano /etc/apache2/mods-available/php5.load

Adjust the path in there to the path to the PHP 5.5 libphp5.so Apache module. Then restart Apache like this:

sudo service apache2 restart

And check the phpinfo.php URL again via a web browser URL like this:

http://hostname/phpinfo.php
  • @JakeGlould Thanks for your answer. First i check my version by phpinfo and see i have 5.4 you can see it in screenshot screencast.com/t/phXkYzUbs4 screencast.com/t/D2as8lyqnMsc Then i find file in my /etc/apache2/mods-available/php5.load where i see next one line LoadModule php5_module /usr/lib/apache2/modules/libphp5.so this file present in system, but maybe not loaded in apache(php5.load). What i need to do to include it in apache? Thank you! – Brotheryura Sep 24 '15 at 19:45
  • or what settings i need show you? – Brotheryura Sep 24 '15 at 19:51
  • @Brotheryura I think you are missing the point of my answer. That doesn’t seem incorrect. The LoadModule php5_module /usr/lib/apache2/modules/libphp5.so might need to be changed to the new location of the new PHP 5.5 libphp5.so file. See my updated answer for details near the bottom: Finding the new PHP 5.5 libphp5.so file. – JakeGould Sep 24 '15 at 19:58
  • i install locate and find next two path /opt/bitnami/apache2/modules/libphp5.so and /usr/lib/apache2/modules/libphp5.so. In file php5.load add one line LoadModule php5_module /opt/bitnami/apache2/modules/libphp5.so. – Brotheryura Sep 24 '15 at 20:21
  • Then i restarting server sudo service apache2 restart * Restarting web server apache2 [fail] * The apache2 configtest failed. Output of config test was: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php5.load: Cannot load /opt/bitnami/apache2/modules/libphp5.so into server: libexslt.so.0: cannot open shared object file: No such file or directory Action 'configtest' failed. The Apache error log may have more information. Maybe i need install somthing else? – Brotheryura Sep 24 '15 at 20:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.