How can i install PHP?

How can i install PHP?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

Regards, KDSys