December 3, 2021
How to install PHP 7.4 on Ubuntu 20.04 LTS

How To Install PHP 7.4 On Ubuntu 20.04 LTS

On this article we will show you how to install PHP version 7.4 on Linux Ubuntu 20.04 LTS Operating system.



Introduction

PHP is general-purpose scripting language that is widely used in various applications today, especially for web-based applications. PHP code is usually processed on a web server by a PHP interpreter implemented as a module, a daemon or as a Common Gateway Interface (CGI) executable. The default of Ubuntu 20.04 repositories has included PHP 7.4 version. On this article we will show you how to install PHP 7.4 on Ubuntu 20.04 LTS operating system.

The latest PHP version while this article is writing is version 8.02 which was released on 4 February 2021. Also for PHP 8.0 installation has been discussed on How To Install PHP 8.0 On Linux Ubuntu 20.04 LTS article.

PHP 7.4 Installation on Ubuntu 20.04 LTS

Ubuntu 20.04 packed with PHP version 7.4 in its upstream repositories. On this article we will install PHP with its extensions so we will integrate with other application on the system. We just start doing the PHP 7.4 installation process, as explained below.

  1. Update System
  2. Install PHP 7.4
  3. Verify PHP installation

The installation requires a root user account an ordinary account with sudo privilege.

1. Update System

As usual, before doing any installation on our Linux system, we are advised to update our system first. For this purpose we will submit the command line : sudo apt update.

amansah@ldap:~$ sudo apt update
 Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
 Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
 Hit:3 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
 Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
 Get:5 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [191 kB]
 Get:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [497 kB]
 Get:7 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [24.3 kB]
 Get:8 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [541 kB]
 Get:9 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages [426 kB]
 Get:10 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [57.6 kB]               
 Fetched 1,845 kB in 7s (279 kB/s)                                                                              
 Reading package lists… Done
 Building dependency tree       
 Reading state information… Done
 438 packages can be upgraded. Run 'apt list --upgradable' to see them.
Update Ubuntu 20.04 LTS System
Update Ubuntu 20.04 LTS System

2. Install PHP 7.4

On this section, we will install PHP 7.4 with common extension. We will submit the command line : sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath.

amansah@ldap:~$ sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
 Reading package lists… Done
 Building dependency tree       
 Reading state information… Done
 The following additional packages will be installed:
   apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1
   libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 libonig5
   libzip5 php7.4 php7.4-bcmath php7.4-cli php7.4-common php7.4-curl php7.4-fpm
   php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache
   php7.4-readline php7.4-xml php7.4-zip
 Suggested packages:
   apache2-doc apache2-suexec-pristine | apache2-suexec-custom
 The following NEW packages will be installed:
   apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1
   libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 libonig5
   libzip5 php php-bcmath php-cli php-common php-curl php-fpm php-gd php-json
   php-mbstring php-mysql php-pear php-xml php-zip php7.4 php7.4-bcmath
   php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd php7.4-json
   php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml
   php7.4-zip
Install PHP 7.4
Install PHP 7.4

The ouptu will be as follow :

Processing triggers for ufw (0.36-6) …
Processing triggers for systemd (245.4-4ubuntu3) …
Processing triggers for man-db (2.9.1-1) …
Processing triggers for libc-bin (2.31-0ubuntu9) …
Processing triggers for php7.4-cli (7.4.3-4ubuntu2.4) …
Processing triggers for php7.4-fpm (7.4.3-4ubuntu2.4) …
NOTICE: Not enabling PHP 7.4 FPM by default.
NOTICE: To enable PHP 7.4 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php7.4-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Processing triggers for libapache2-mod-php7.4 (7.4.3-4ubuntu2.4) …

3. Verifty PHP 7.4 Installation

The last step ini PHP 7.4 installation is to verify the PHP version, we just hit the command line : php --version.

ramansah@ldap:~$ php --version
 PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( 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
PHP version 7.4 was installed on the system
PHP version 7.4 was installed on the system

Conclusion

PHP version 7.4 installation on Ubuntu 20.04 LTS has been completed done. The PHP 7.4 extension installation help us on PHP integration with other application, such as : Apache Web server, NginX, MySQL and others. Have a nice day, stay at home and stay safe.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *