YouTube Icon

Code Playground.

How to Install PHP on Ubuntu 20.04


How to Install PHP on Ubuntu 20.04

PHP is one of the most utilized worker side programming dialects. Numerous well known CMS and structures, for example, WordPress, Magento, and Laravel are written in PHP. 

This guide covers the means important to introduce PHP on Ubuntu 20.04 and incorporate it with Nginx and Apache. 

At the hour of composing, the default Ubuntu 20.04 storehouses incorporate PHP 7.4 adaptation. We'll additionally tell you the best way to introduce past PHP forms. Before picking which adaptation of PHP to introduce, ensure that your applications uphold it. 

Installing PHP 7.4 with Apache

In case you're utilizing Apache as your web worker, run the accompanying orders to introduce PHP and Apache PHP module: 

sudo apt update
sudo apt install php libapache2-mod-php

When the bundles are introduced, restart Apache for the PHP module to get stacked: 

sudo systemctl restart apache2

Installing PHP 7.4 with Nginx 

Not at all like Apache, Nginx doesn't have underlying help for handling PHP documents. We'll utilize PHP-FPM ("fastCGI measure director") to deal with the PHP documents. 

Run the accompanying orders to introduce PHP and PHP FPM bundles: 

sudo apt update
sudo apt install php-fpm

When the establishment is finished, the FPM administration will begin naturally. To check the status of the administration, run 

systemctl status php7.4-fpm
php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-06-09 19:07:05 UTC; 37s ago
You can now edit the Nginx server block and add the following lines so that Nginx

You would now be able to alter the Nginx worker square and include the accompanying lines with the goal that Nginx can handle PHP documents: 

server {

    # . . . other code

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:q;

Remember to restart the Nginx administration so the new arrangement produces results: 

sudo systemctl restart nginx

Installing PHP extensions

PHP expansions are incorporated libraries that broaden the center usefulness of PHP. Expansions are accessible as bundles and can be effectively introduced with able : 

sudo apt install php-[extname]

For instance, to introduce MySQL and GD expansions, you would run the accompanying order: 

sudo apt install php-mysql php-gd

In the wake of introducing another PHP expansion, contingent upon your arrangement, remember to restart Apache or PHP FPM administration. 

Testing PHP Processing

To test whether the webserver is arranged appropriately for PHP preparing, make another record named info.php inside the/var/www/html catalog with the accompanying code: 




Spare the document, open your program, and visit: http://your_server_ip/info.php. 

You'll consider data to be your PHP design as appeared on the picture beneath: 

Installing Previous PHP Versions

Ond?ej Surý, a Debian designer, keeps up a vault that incorporates different PHP renditions. To empower the archive , run: 

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

You would now be able to introduce subterranean insect PHP form you need by adding the variant number to the bundle name: 

sudo apt install php[version]

For instance, to introduce PHP 7.1 and not many regular PHP modules, you would run: 

sudo well-suited introduce php7.1-basic php7.1-opcache php7.1-mcrypt php7.1-cli php7.1-gd php7.1-twist php7.1-mysql 


Introducing PHP on Ubuntu 20.04 worker is a clear undertaking. You should simply to introduce the bundle with adept. 

On the off chance that you have any inquiries or criticism, don't stop for a second to leave a remark.