• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install PHP 7.4 on Ubuntu 20.04

Written by Admin, Updated On May 18, 2020
php, ubuntu
How to Install PHP 7.4 on Ubuntu 20.04

PHP is a most popular server scripting language used for creating dynamic and interactive Web pages. PHP is widely-used programming language in the Web. This tutorial explains how to install PHP 7.4 on Ubuntu 20.04

By default, Ubuntu 20.04 ships with PHP version 7.4, which is supported by the most popular CMS and frameworks such as WordPress, Magento, and Laravel.

Step 1 – Prerequisites#

Before start installation, make sure your are logged in as root or user with sudo privileges.

Step 2 – Update system#

Update the package index list, it’s recommend to update software repositories and install packages to sync with latest releases.

sudo apt update && sudo apt upgrade

Step 3 – Install PHP on Ubuntu#

At this step your system is up to date and ready to install PHP. Run the following command to install PHP 7.4.

Installing PHP with Apache#

For Apache web server to install PHP and Apache PHP module run the following commands:

sudo apt install php php-common libapache2-mod-php

Installing PHP with Nginx#

By default, Nginx doesn’t have a built-in support for processing PHP files. So we need to use PHP FPM service to handle the PHP files.

sudo apt install php php-common php-fpm

After that, you need to edit domain Nginx server block and add following lines to work PHP file using Nginx:

server {

    # . . . other code

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }
}

Save the configuration file and restart the nginx service for the new configuration take effect:

sudo systemctl restart nginx

Step 4 – Installing PHP Extensions#

You can install PHP extensions as per requirements. Run below command to install most common PHP extensions required for basic usage.

sudo apt install php-cli php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

Step 5 – Testing PHP#

Once the installation complete, you can verify version by typing:

php --version
PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Conclusion#

This tutorial explained how to install PHP 7.4 on Ubuntu 20.04 and configure your web server to process PHP files.

If you have any questions or suggestion, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Yarn on Debian 10 Buster
Next Article   How to Install Webmin on Ubuntu 20.04

Related Posts

  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Puppet Agent on Ubuntu 22.04

    How to Install Puppet Agent on Ubuntu 22.04

    January 22, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook