Upgrade php version. Module php5.6 does not exist

January 26, 2017 5.2k views
Apache PHP Ubuntu

I needed to perform the upgrade php version from 5.3 to 5.6 (ubuntu 12.04).

I used the following commands:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get purge php5-common
sudo apt-get install libapache2-mod-php5.6
sudo a2dismod php5
sudo a2enmod php5.6 # after this command I get 'Module php5.6 does not exist'
sudo service apache2 restart

if check through the terminal "php --version" I see a new version:

PHP 5.6.30-1+deb.sury.org~precise+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Through http request php does not work.
If I understand correctly php already installed.
But the apache can not determine it.

How can I fix this?

Thank you.

2 Answers

12.04 LTS will be end of life in 2 months, why not upgrade to 14.04? This will upgrade PHP too.

@michael363434

Unless the libapache2-mod-php5.6 installs all required PHP packages for you during the process (and not just the module used by Apache to enable PHP), then you would most likely need to install additional PHP packages before you'll be able to handle web-based requests.

When installing PHP from a PPA or the base repositories, the CLI package is often installed and when you run php -v from the CLI, the PHP CLI package is what's giving you that result (this is especially the case with the PPA that you're using -- I'm very familiar with it).

So what you'd need to do is run:

sudo apt-cache search php5.6 --names-only

... and when you do, you're going to see quite a few PHP 5.6 packages pop up in list format. You then need to install the packages that you need for your PHP installation. They may just be tagged as php5, though in some cases, he does tag them as php5.6 (or another version -- that's the case with newer packages for newer Ubuntu releases, such as 16.04).

Ideally, you'd install the common, dev, and cli packages. Once those are installed, if you need MySQL, you'd install the MySQL package, if Memcached, then the memcached package, etc. The only one you don't want to install, since you're not setup to use it (based on what you've provided) is the FPM package as to run that one you'd need to use another apache module instead of mod_php.

Have another answer? Share your knowledge.