How to install / setup PHP 5.5.x on Ubuntu 12.04 LTS

Please note: This works fine. But this package will also upgrade your apache to version 2.4 which has different config files than apache 2.2 and even deletes stuff, like /etc/apache2/sites-available/default when upgrading. This may result in a loss of your apache settings (vhost, mod_rewrite stuff etc.). Be aware of that ! This shit cost me a full weekend. This affects only upgrades, not fresh installs for sure. Update: This is a known bug (more here), I’ll keep this post updated…
How to install
There’s an excellent and (usually) hassle-free method to install the latest version of PHP5 (which is 5.5.3 when i’m writing this) with 3 simple bash commands:
1. Add this package-repository to your system. If Ubuntu says that you need to download a key first, then follow the instructions given in the notice.
sudo add-apt-repository ppa:ondrej/php5
If you get an error message now, then please do an update first and install the python-software-properties, that need to be necessary to add a package repository:
sudo apt-get update sudo apt-get install python-software-properties
2. Update
sudo apt-get update
3. Install PHP
sudo apt-get install php5
Check the installed version of PHP via
php5 -v
Please note: The ondrej/php5 repository (which is used here) provides the very latest version of PHP. Usually the new version of PHP is available a few days after it was been officially released. This is really cool and a big step forward as Ubuntu, Debian, CentOS etc. provide only very old versions by default.
To UPDATE from PHP 5.3 / 5.4 to PHP 5.5:
It’s also possible to update from any PHP version to the latest one with exactly the commands above. But, after doing
sudo apt-get install php5
you’ll have to restart the server with
sudo /etc/init.d/apache2 restart
or
sudo service apache2 restart
By the way, I’ve also written a tutorial on “How to setup latest version of PHP 5.5 on Debian Wheezy 7.0/7.1/7.2 (and how to fix the GPG key error)“, which is different from this here.
sudo apt-get install -y php5.5
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package php5.5
E: Couldn’t find any package by glob ‘php5.5’
E: Couldn’t find any package by regex ‘php5.5’
This didn’t work. Thank the good Lord for Virtual Machine snapshots. :)
Thanks a lot for this simple solution.
I was trying to install symfony 2 which need at least php 5.4 on ubuntu 12 LTS :
Symfony Installer requires PHP 5.4 version or higher and your system has
PHP 5.3.10-1ubuntu3.19 version installed.
To solve this issue, upgrade your PHP installation or install Symfony manually
executing the following command:
composer create-project symfony/framework-standard-edition
Finally , this was not working have reinstalled a brand new ubuntu 12.04 LTS
installation httpd-2.4.16 + php-5.6.13 + symphony-2.7.3
——————————————————-
(Brand new Ubuntu 12.04 LTS
with kernel : 3.2.0-23-generic-pae)
1. install apache.
——————
download httpd-2.4.16.tar.gz
(http://httpd.apache.org/download.cgi#apache24)
# apt-get install libapr1util-dev
(needed for apache)
# tar zxvf httpd-2.4.16.tar.gz
# cd httpd-2.4.16
# ./configure –prefix=/usr/local/apache2
# make
# make test
# make install
test : # /usr/local/apache2/bin/apachectl start
and test the default ‘It works’ web page
located in /usr/local/apache2/htdocs
2. install php. (minimal configuration for symfony)
—————————————————
2.1. Pre-requisites
————–
# apt-get install libxml2-dev
(needed for php)
download zlib-1.2.8.tar.gz
(http://zlib.net/zlib-1.2.8.tar.gz)
(needed for symfony with linux systems)
# tar zxvf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure
# make test
# make install
this create libz.so.1.2.8 in /usr/local/lib
2.2. php-5.6.13 installation
———————–
download php-5.6.13.tar.gz
(http://fr2.php.net/distributions/php-5.6.13.tar.gz)
# tar zxvf php-5.6.13.tar.gz
# cd php-5.6.13
# ./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-zlib-dir=/usr/local/lib
# make
# make test
# make install
test : # php -v
# cd /usr/local/apache2/conf/
and add
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
in httpd.conf file
test by adding an index.php file with in it
in /usr/local/apache2/htdocs
3. symfony 2.7.3 installation and demo test
——————————————-
# apt-get install curl
modify /usr/local/lib/php.ini, uncomment date.timezone and fix it
(see http://php.net/date.timezone)
for example : date.timezone = ‘Europe/Brussels’
# curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
# chmod a+x /usr/local/bin/symfony
# mkdir /home/your_home/symfony_test
# chmod 777 /home/your_home/symfony_test
# exit
$ cd /home/your_home/symfony_test
$ php /usr/local/bin/symfony demo
$ cd symfony_demo
$ php app/console server:run
console server:run
Server running on http://127.0.0.1:8000
Quit the server with CONTROL-C.
I updated my php from 5.10 to 5 but now I get the error message:
phpMyAdmin – Error
The mysqli extension is missing. Please check your PHP configuration.
Any assistance will be much appreciated.
about the orange note at beginning of the article… is it fixed now, right?
Hi,
I have some trouble: after I added the repository,
when I do: “apt-get install php5”,
I get: “php5 is already the newest version.”
But it’s still PHP 5.3
Any suggestions? Thanks.
EDIT: btw I use Ubuntu 10.04
followed the instructions… When I do ‘php5 -v’ I still get PHP 5.3.2… help …
me too. Had any clue?
Great. Just what I needed.
hello, after an Update from 5.3 to 5.5 i get these error:
Output of config test was:
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 2 of /etc/apache2/mods-enabled/fcgid_easyscp.load: Cannot load /usr/lib/apache2/modules/mod_fcgid.so into server: /usr/lib/apache2/modules/mod_fcgid.so: cannot open shared object file: No such file or directory
the mod_fcgid.so cannot load. How can i fix this?
i do that…i didn`t find any notice of this error :-/
This worked great, thanks a lot – saved me a headache.
sudo: add-apt-repository: command not found on ubuntu server 12
Thanks for the post, very helpful! I’m currently running PHP 5.3.10, and I have also installed:
php5-pspell
php5-curl
php5-gd
php5-intl
php5-mysql
php5-xmlrpc
php5-ldap
Will updating to 5.5 with the above method break any of the above? I’d just try myself, but I don’t want to break my production server :)
Sorry, I cannot answer this :( … But in general you should not update a production server withouth being 99% sure everything runs fine. Make a perfect copy of that server and try out :)
Good call, thanks Chris!
Thank you very much!
Hi,
What if I already have v5.3.6 on my LEMP Ubuntu 12.04?
Is there a way to remove that completely or with it resolve itself?
Thanks.
Hey Nicholas, I just tried this out: Works perfectly ! I installed the standard packaged PHP version (5.3.10) in Ubuntu 12.04 LTS and did exactly the stuff written in the above article. You’ll need to restart the server afterwards. Thanks for the interesting idea, I will put this into the article.
Hi Chris,
Thanks for coming back. I actually uninstalled v5.3.6 and then used the steps you outlined to add the v5.5 ppa. Good news is it works and I got Zend Opcache (Zend Optimizer+) running. Typical load on my DB is now under 10MB (was about 35MB previously). The Opcode Cache (APC) on v5.3.6 was bringing down my server for some strange reason.
Anyway, thought be useful if someone running Nginx (instead of Apache) lands on your site.
Restart server command in terminal (Ubuntu 12.04 LTS)
1. sudo service nginx restart
or
2. sudo /etc/init.d/nginx restart
Wow, excellent! Btw just to clarify: No need to uninstall anything,
sudo apt-get install php5
will update PHP without any problems.