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?
22 Answers
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:
Extracted from link above:
Assuming
libapache2-mod-phpis 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.012Switch PHP version ( Apache ):
from php5.6 to php7.0:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restartfrom php7.0 to php5.6:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
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:
Extracted from link above:
Assuming
libapache2-mod-phpis 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.08Switch PHP version ( Apache ):
from php5.6 to php7.0:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restartfrom php7.0 to php5.6:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart