I'm trying to update my php 5.5.9 to 5.6 in an Ubuntu machine.

But when I run:

sudo add-apt-repository ppa:ondrej/php5-5.6

I'm getting:

Cannot add PPA: 'ppa:ondrej/php5-5.6'.
Please check that the PPA name or format is correct.

How can I fix this?

EDIT

I ran:

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

But when I run:

php5 -v

I still get php 5.5.9:

PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct  3 2016 13:00:37) 
share|improve this question
    
Add the right PPA: launchpad.net/~ondrej/+archive/ubuntu/php. The one you're trying to get was deprecated – Clive Nov 12 '16 at 20:13
    
Thanks, i could install ppm, but not able to update php, I edited my answer. Can you help? @Clive – Filipe Ferminiano Nov 12 '16 at 20:20
    
Hi, I am in ubuntu 14.04, and encountered the same issue, change your last cmd to "sudo apt-get install php5.6", then it works. – zhihong Nov 21 '16 at 13:23
up vote 66 down vote accepted

add the right ppa first, do the following

  1. sudo add-apt-repository ppa:ondrej/php
  2. sudo apt-get update
  3. sudo apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip

i had the same issue in installing the php5.6 then i did the above steps.

share|improve this answer
2  
step 2 & 4 both have apt-get install php5.6, which does not make sense. And after adding repo, you should always issue apt-get update to refresh the local repo list before installing anything. – Raptor Nov 24 '16 at 3:37
    
yes you are right. we should use the apt-get update before install – tanveer ahmad dar Nov 24 '16 at 13:19
    
You saved my day, thanks – dlopezgonzalez Apr 7 '17 at 11:25
    
you are welcome – tanveer ahmad dar May 15 '17 at 6:15

While the answer of @tanveerahmaddar provides crucial information, here is the correct way to install the PHP 5.6 on Ubuntu 12.04:

Important: If you plan to use PHP5.6 in websites (which you probably wish to), you have to upgrade to Apache 2.4, which does not ship with Ubuntu 12.04 (will cover the upgrade of Apache below)

Step 1: Check versions

# check PHP version
php -v
# check Apache version
apache2 -v

If your Apache version is 2.2, follow Step 2; if version is 2.4, skip to Step 3

Step 2: Add PHP5.6+ repository and update package list

add-apt-repository ppa:ondrej/apache2
apt-get update
apt-get upgrade

This step will upgrade Apache from 2.2 to 2.4. Re-configure your Apache if needed. Backup your existing Apache configurations, enabled sites and mods. You might need to re-install / upgrade some of the mods.

Step 3: Add PHP5.6+ Repository

add-apt-repository ppa:ondrej/php
apt-get update

Step 4: Install PHP 5.6

apt-get install -y php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip libapache2-mod-php5.6

This will install PHP 5.6 and some common packages such as cURL (php5.6-curl) and GD (lib5.6-gd), as well as enable PHP 5.6 in Apache 2.4 (libapache2-mod-php5.6).

Apache will be restarted during the process.

That's all steps you have to do.


Hint: If you want to upgrade to PHP 7 instead (off-topic), just issue the following command after Step 3 (skip Step 4):

apt-get dist-upgrade

Final words: Not recommend to upgrade to PHP 5.6 in Ubuntu 12.04, as it involves upgrading Apache to 2.4. Ubuntu 14.04 comes with Apache 2.4, which is a lot easier to upgrade PHP 5.6.

share|improve this answer
    
why after i follow ur step, when i run script with phpinfo() i still get previous php version, yet when i run php -v through cli, i got php5.6 – slier Jan 24 '17 at 6:25
    
This is because your Apache is loading old PHP, as proven by the path of the php.ini shown in phpinfo(). Although throughout the process Apache will restart itself, have you tried restarting the Apache service yourself and see whether Apache is still using the old version? – Raptor Jan 24 '17 at 6:48
    
yes i have, still show me previous php version. – slier Jan 24 '17 at 6:51
    
@slier: this happen because Apache still has loaded old PHP module. This is my solution (You need run all this command in this order): cd /etc/apache2/mods-enabled; rm -fr php5.*; ln -s ../mods-available/php5.6.conf . ; ln -s ../mods-available/php5.6.load . ;/etc/init.d/apache2 restart; – Marek Skiba Jan 31 '17 at 17:38
    
This command can be probably replaced by a2enmod/a2dismod but I'm not familiar with it. – Marek Skiba Jan 31 '17 at 17:44

This work for perfectly for me. Add the right PPA first, by doing the following

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl 
php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip

Disable php 5.5.3 or 5.5.9 module

a2dismod php5

Enable the just installed php5.6 module

a2enmod php5.6

Finally, you restart your apache

sudo service apache restart

@tanveer ahmad dar highlighted most of it.

share|improve this answer
    
Also, if you have to check versions, then use "php5.6 -v" instead of "php5 -v". – rsharpy Nov 13 '17 at 14:26

This worked in my Ubuntu Server 14.04.5 LTS

a2dismod php5
a2enmod php5.6
apache2ctl restart
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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