In this article, we will have explained the necessary steps to install and configure PHP 7.4 on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges. All the commands in this tutorial should be run as a non-root user.
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. Many popular CMS and frameworks such as WordPress, Laravel, and many more are built in PHP.
- Operating System with Ubuntu 20.04
- Server IPv4 Address with Superuser Privileges (Root Access)
- Gnome Terminal for Linux Desktop
- PuTTy SSH client for Windows or macOS
- Powershell for Windows 10/11
- Familiar with APT Commands
Install PHP 7.4 on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade sudo apt install software-properties-common
Step 2. Install PHP 7.4 on the Ubuntu system.
Now add the PPA repository which has the latest build packages of PHP:
sudo add-apt-repository ppa:ondrej/php
Once the update adds repository completely, let’s begin the PHP installation:
sudo apt update sudo apt install php7.4
Verifying the version of install PHP on Ubuntu 20.04:
$ php -v PHP 7.4.8 (cli) (built: Mei 20 2020 20:36:46) ( 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
Step 3. Installing PHP extensions.
PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with apt:
sudo apt install php-[module]
sudo apt install php7.4-mysql php7.4-curl php7.4-json php7.4-cgi php7.4-xml php7.4-fpm
PHP configurations related to Apache is stored in
Step 4. Testing PHP Processing
First, create a test PHP file called info.php in the webserver default home directory:
sudo nano /var/www/html/info.php
Then copy and paste the line into the file and save it:
After that, open your browser and browse to the server hostname or IP address followed by the name of the file you created above:
That’s all you need to do to install the PHP on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on PHP 7.4, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.