so I've recently installed my first Ubuntu, to be precise, a daily build of 16.04, on my new laptop since the hardware was to new for 15.10. Now I'm in the process of setting it up and I want to install php5 and some extensions.

When I execute sudo apt-get install libapache2-mod-php5 I get the error message that there is no installation package available for php5 and libapache2.

The error message is in german, so I doubt that this would help, but anyways here it is. :-) E: For package »libapache2-mod-php5« existiert kein Installationskandidat.

Do I need to add a apt-get repository? Or what am I doing wrong?

up vote 71 down vote accepted

TL;DR: If you want to stay with php5, you will need to stay at Ubuntu 14.04 LTS

Using PHP 7.0 on Ubuntu 16.04 LTS

Ubuntu 16.04 has switched to PHP 7.0 with a new infrastructure for PHP package. So, no, you can't install php5 on Ubuntu 16.04, but you can install PHP 7.0 packages with:

apt-get install libapache2-mod-php

That will install a virtual package that depends on the latest PHP version and pull libapache2-mod-php7.0 as a dependency.

If you are looking for extensions, always use a version-less variant as well (e.g. php-apcu instead of php7.0-apcu) as the PECL extensions are packaged without the version to allow smooth upgrades.

Using PHP PPA to coinstall PHP 5.6 with PHP 7.0

There's an option to co-install PHP 5.6 packages using ppa:ondrej/php.

For more information, please see that answer: https://askubuntu.com/a/762161/309221

Extracted from link above:

Assuming libapache2-mod-php is a suitable way to enable PHP in Apache for you, you can proceed in this way:

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0

Switch PHP version ( Apache ):

  • from php5.6 to php7.0:
    sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart

  • from php7.0 to php5.6:
    sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

  • 1
    No, there are no PHP 5.x packages in Xenial repositories. Only in the PPA. – oerdnj Jul 12 '16 at 4:54
  • Looks like you're right: bugs.launchpad.net/ubuntu/+source/php5/+bug/1522422 – NoBugs Jul 12 '16 at 4:57
  • When I switch to php5.6, I got error "Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.". – lyhong Nov 15 '16 at 8:05
  • And what does the journal say? – oerdnj Nov 15 '16 at 8:07
  • found something like this apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 3 of /e – lyhong Nov 15 '16 at 8:22

EDIT: the accepted answer does not explicitly say how to co-install PHP 5.6 and 7.0, so I wanted to extend it.

For more information, please see that answer: https://askubuntu.com/a/762161/309221

Extracted from link above:

Assuming libapache2-mod-php is a suitable way to enable PHP in Apache for you, you can proceed in this way:

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0

Switch PHP version ( Apache ):

  • from php5.6 to php7.0:
    sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart

  • from php7.0 to php5.6:
    sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

  • 1
    FYI: The PPA you use is maintained by the person who wrote the accepted answer. And the last line in that answer: "There's an option to co-install PHP 5.6 packages using ppa:ondrej/php". Note that you aren't installing php5 packages either, but php5.6 – muru May 8 '16 at 21:49
  • 1
    There are a number of differences in the packaging and location of configuration files that anyone looking for the old php5 packages would be surprised in the new ones. – muru May 9 '16 at 17:27
  • I have edited my answer so it doesn't say that the accepted answer was incorrect, but only extends it. – FlavioEscobar May 9 '16 at 17:39
  • @NoBugs It does have imagick extension packaged. Please stop spewing things without at least basic checking whether they are true or not. – oerdnj Jul 13 '16 at 11:12
  • @FlavioEscobar I have merged your edits into my answer. Thanks for extending the answer. – oerdnj Jul 13 '16 at 11:20

protected by Community Nov 29 '16 at 11:31

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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