Install PHP 7.4 on Ubuntu 20.04

0
2212

In this guide, we are going to learn how to install PHP 7.4 on Ubuntu 20.04. PHP is a recursive acronym for Hypertext Preprocessor and is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

PHP 7.4 comes with a lot of improvements and new features over the previous versions such as;

See a complete list of changes in the ChangeLog.

Install PHP 7.4 on Ubuntu 20.04

Update and upgrade your system packages;

apt update
apt upgrade

Ubuntu 20.04 ships with PHP 7.4 in its default repos.

apt show php7.4
Package: php7.4
Version: 7.4.3-4ubuntu1
Priority: optional
Section: php
Origin: Ubuntu
Maintainer: Ubuntu Developers [email protected]
Original-Maintainer: Debian PHP Maintainers
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 72.7 kB
Provides: php
Depends: libapache2-mod-php7.4 | php7.4-fpm | php7.4-cgi, php7.4-common
Homepage: http://www.php.net/
Download-Size: 9,244 B
APT-Sources: http://ke.archive.ubuntu.com/ubuntu focal/main amd64 Packages

Therefore the installation of PHP 7.4 is as simple as running the command below;

apt install php

You can as well use the command;

apt install php7.4

Either of the commands above installs PHP 7.4 on Ubuntu 20.04 along with its dependent packages.

Verifying the version of install PHP on Ubuntu 20.04;

php -v
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

Install PHP 7.4 Modules/Extensions on Ubuntu 20.04

Depending on the requirements of your web application, you may need to install extra PHP 7.4 extensions/modules.

To install the modules/extensions simply use the command;

apt install php7.4-extension

Where extension is the name of the module/extension you are trying to install.

For example, you want to install the following PHP modules;

  • Bcmath module for PHP
  • bzip2 module for PHP
  • IMAP module for PHP
  • Internationalisation module for PHP
  • MBSTRING module for PHP
  • SOAP module for PHP
  • Sybase module for PHP
  • XSL module for PHP
  • Zip module for PHP

You would simply execute the command below to install them;

apt install php7.4-{bcmath,bz2,imap,intl,mbstring,soap,sybase,xsl,zip}

Verifying PHP Version and Modules from Browser

You can also be able to verify version of install PHP and its modules via the browser. For this, you need a web server. Apache2 is installed by default as a dependency package for PHP.

Hence, start Apache and open port 80/TCP on firewall to allow external access.

systemctl enable --now apache2
ufw allow Apache

Next, create a PHP test page on your default web root directory as shown below;

echo "<?php phpinfo(); ?>" > /var/www/html/index.php

Then navigate to the address, http://your-server/index.php on you browser.

And that is how simple it is to install PHP 7.4 on Ubuntu 20.04.

Related Tutorials

Install PHP 7.4 on FreeBSD 12

Install PHP 7.4 on CentOS 8

Install PHP 7.4 on Debian 10/Debian 9

LEAVE A REPLY

Please enter your comment!
Please enter your name here