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

Source: Internet
Author: User
Tags debian server

Original: http://www.dev-metal.com/how-to-setup-latest-version-of-php-5-5-on-ubuntu-12-04-lts/

Recently encountered the issue of upgrading PHP version on Ubuntu 12.04, here is the way to upgrade PHP to the latest version:

Please note:this works fine. But this package would also upgrade your Apache to version 2.4 which have different config files than Apache 2.2 and even de Letes stuff, like/etc/apache2/sites-available/default when upgrading. This could result in a loss of your Apache settings (vhost, mod_rewrite stuff etc). is aware of that! This shit cost me a full weekend. This affects is 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 was 5.5.3 when I ' M writi Ng this) with 3 simple bash commands:

1. Add this package-repository to your system. If Ubuntu says that is need to download a key first and then follow the instructions given in the notice.

sudo add-apt-repository ppa:ondrej/php5

If you get the "error message now," then "do a" update first and install the python-software-properties, that need to B e necessary to add a package repository:

Advertisement
sudo apt-get updatesudo 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 are 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.
[Wp_ad_camp_2]

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 the-the-by, I ' ve also written a tutorial on "What 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 are different from this here.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hey, according to the above update may encounter problems, Nginx 502 Bad Gateway error, I met, the following stack overflow above answer, the perfect solution!!

120down VoteAccepted

If anyone finds this page by encountering the same problem I had, I found the answer here:http://www.howtoforge.com/instal Ling-nginx-with-php5-and-php-fpm-and-mysql-support-lemp-on-ubuntu-12.04-lts

For those of the Who can ' t is bothered to click and work it off for themselves ...;)

The Condition:

Ubuntu or Debian server with NGINX and PHP 5.3 works fine but upgrading PHP to 5.4 gives 502 bad Gateway errors. Looking for services running in Port 9000 (typically running netstat -lp or similar) returns Nothing.

The FIX:

Open and make /etc/php5/fpm/pool.d/www.conf a note of the ' listen ' parameter (in my case /var/run/php5-fpm.sock ):

; TheAddress on which to acceptFastCGIRequests.; ValidSyntaxes is:; ' Ip.add.re.ss:port ' -To listen in a TCP socket to a specific address on;A specific port;; ' Port ' -To listen in a TCP socket to all addresses on a specific Port;  '/path/to/unix/socket '  -  listen on a UNIX socket. note: this  value is Mandatory.= /var/run/< Span class= "PLN" >php5-fpm. Sock                  

and replace the Fastcgi_pass variable in your vhost with the location of you just noted.

So this sample Symfony2 configuration (taken from Here:http://wiki.nginx.org/symfony):

  # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000Location~ ^/(APP|APP_DEV) \.php (/ | $)  { Fastcgi_pass 127.0. 0.1:9000; Fastcgi_split_path_info ^ (. +\.php$;; Fastcgi_param script_filename $document _root$fastcgi_ Script_name; Fastcgi_param HTTPS off; Span class= "pun" >               

becomes this:

  # Pass the PHP scripts to FastCGI server At/var/run/php5-fpm.sockLocation~ ^/(App|app_dev) \.php (/| $) { fastcgi_pass unix:/var/run/php5-fpm.  Sock; fastcgi_split_path_info ^ (. +\.php) (/.*)$; include Fastcgi_params ; fastcgi_param script_filename $document _root$fastcgi_script_name; fastcgi_param HTTPS off;  }< /c10> 

Then restart Nginx:

sudo /etc/init.d/nginx restart

Note: replace ~ ^/(app|app_dev)\.php(/|$) { with ~ ^/index\.php(/|$) { if you ' re not on sf2**

Hope This saves someone a little bit of time:)

Edit

Of course, you could the change of the and then listen = /var/run/php5-fpm.sock listen = 127.0.0.1:9000 /etc/php5/fpm/pool.d/www.conf restart PHP5-FPM (which would Your vhosts), but you had to assume they changed php5-fpm to run through a sockets rather than listening on port 9000 for A reason.

Edit2

If you ' re still experiencing 502 error See this Answer:nginx error connect to Php5-fpm.sock failed (13:permission denied )

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.