How can i install PHP?

Posted October 31, 2019 2.4k views

How can i install PHP?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer

Hi @remadaria,

Depending on the OS and the OS version installation could be different as well as using a different Web Service (Apache/Nginx)

Ubuntu 16.04

If you are using Apache as your Web Server, you’ll need to install PHP and Apache PHP model, to install them run the following command

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

To further read upon that, I’ll recommend you to check this DigitalOcean Article - HERE

Nginx does not contain native PHP processing like some other Web Servers, you will need to install php-fpm, which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.

The installation will pull in the necessary PHP core files. Do this by typing:

sudo apt install php-fpm php-mysql 

There is actually a pretty good guide written by DigitalOcean again - HERE

Ubuntu 18.04

Similar to Ubuntu 16.04 in the 18.04 version is installed by

sudo apt install php libapache2-mod-php

To further read upon that, you can check this DigitalOcean article - HERE

For Nginx, the same as mentioned above about 16.04, can be said here. The same command can be executed here as well

sudo apt install php-fpm php-mysql

Of course there is a relevant DigitalOcean article here as well - HERE

CentOS 7

Similar to the above examples with the only exception that in CentOS as opposed to Ubuntu we use yum instead of apt, to install PHP we use

sudo yum install php php-mysql

Again, to further read upon the matter, you can check the following article - HERE

If you are using Nginx as a Web Service on a CentOS machine, you’ll need to run the following

sudo yum install php php-mysql php-fpm

Please check this article, again in the DigitalOcean database for more information - HERE

If you by any chance use anything Different than Apache or Nginx like Debian, there is a section for that too in the mentioned articles.


by Mitchell Anicas
In this guide, we'll get a LAMP stack installed on an CentOS 7 VPS. A "LAMP" stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the **L**inux operating system, with the **A**pache web server. The site data is stored in a **M**ySQL database (using MariaDB), and dynamic content is processed by **P**HP.
Submit an Answer