Recently one of my client provided a fresh VPS and asked me to install PHP 7, Apache and MySQL. While installing PHP, I encountered the below error:
root@webimage:~# apt-get install php Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package php
Solution: By default PHP5.5 is only available for Ubuntu Trusty in the standard Ubuntu repositories. So, you can install PHP 5.5 version as shown below:
#apt-get install php5
How to Install PHP 7?
If you want to install PHP 7 and the same is not available in standard Ubuntu Trusty repository. Then you need to add the corresponding repository which includes PHP 5.6 and above versions.
Add the below repositories in your ubuntu:
root@webimage:~# add-apt-repository ppa:ondrej/php Co-installable PHP versions: PHP 5.6, PHP 7.0, PHP 7.1 and most requested extensions are included. PLEASE DON'T USE PHP 5.4 OR PHP 5.5. The PHP 5.5 and later are no longer supported with security updates, therefore they are not included in this repository. You can get more information about the packages at https://deb.sury.org BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/#bug-reporting PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/ WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround: # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php More info: https://launchpad.net/~ondrej/+archive/ubuntu/php Press [ENTER] to continue or ctrl-c to cancel adding it gpg: keyring `/tmp/tmp16acixb1/secring.gpg' created gpg: keyring `/tmp/tmp16acixb1/pubring.gpg' created gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com gpg: /tmp/tmp16acixb1/trustdb.gpg: trustdb created gpg: key E5267A6C: public key "Launchpad PPA for OndÅej Surý" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) OK
You need to update the repository
#apt-get update
As stated earlier, you can install PHP versions of 5.6, 7.0 and 7.1 as below:
For installing PHP 5.6
#apt-get install php5.6
For installing PHP 7.0
# apt-get install php7.0
For installing PHP 7.1
# apt-get install php7.1
Now you can start working with your corresponding PHP versions.