27
votes

I tried installing php in ubuntu 16.04 using following command:

sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi  php7.0 libapache2-mod-php7

but it says

Unable to locate package libapache2-mod-php7

Should I skip this or install by an alternative way?

9

9 Answers

74
votes

The name of the package is libapache2-mod-php7.0 Try again by having that .0 at the end and it should work.

23
votes

On Ubuntu 18.04, I had to add the repository below first. Once the repo was added I was able to install the php7.x items.

sudo add-apt-repository ppa:ondrej/php

Source: https://websiteforstudents.com/apache2-with-php-7-1-support-on-ubuntu-18-04-lts-beta-server/

6
votes

If you are using Ubuntu 17.04/17.10 or above use php7.1 instead of 7.0 since it is no longer available.

sudo apt-get install php7.1
4
votes

At the time of the post Ubuntu 16.04 was one of the newer versions and as such the packages changed to php7.0 but as time goes on it will be 7.1 to 7.2 etc... and I don't have the time to figure out what was the latest package and I'm not dependent on a specific version. So if you want the latest version of packages to install without having to know the correct version number just drop the version number and the latest applicable to the distribution you are using will be installed. In my case I was using Ubuntu 17.10 and the php version is different so I used the following command line to get the latest.

sudo apt-get install apache2 php-mysql libapache2-mod-php mysql-server

It installed php 7.1 and all of the correct dependencies.

So if you don't require a specific version but just want the latest that works with the distribution drop the version number and use the command line above.

2
votes

It is likely the case that your local package index is not updated; try

sudo apt-get update

and then run the previous command again.

As an aside, there is now a program apt that is supposedly more user-friendly than apt-get, apt-cache etc. (see this question on Ask Ubuntu). So your commands could have been replaced by

sudo apt update
sudo apt install <the packages>

to get a slightly nicer user interface.

Probably this question would have been better suited to the Ask Ubuntu community.

0
votes

Apache server can't start because libapache2-mod-php7.0 is not installed: by default aptitude or apt install php7.0-common version 7.8.13 which is not adaptable and libapache2-mod-php need 7.0.8

  1. remove php-common
  2. download http://packages.ubuntu.com/xenial/php7.0-common deb package and install it if it compains about php7.0-json, readline,cli,opache then seatch in upper textbox about those library and install them in this manner
  3. json
  4. opach
  5. cli
  6. readline

  7. install libapache2-mod-php7.0 RESTART APACHE 2 service apache2 restart

it must working probably Good Luck!

0
votes

Try for Ubuntu 16.04:

sudo apt-get update;
sudo apt-get install php7.0-fpm php7.0-mysql <other packages>;

for Ubuntu 14.04:

sudo apt-get update;
sudo apt-get install php5-mysql php5-mysql <other packages>;
0
votes

It should be:

sudo apt-get install libapache2-mod-php7.0

0
votes
sudo apt-get install libapache2-mod-php7.1

worked for me (16.04Ubuntu).