In this tutorial, you will learn how to install PHP 7.4 on Ubuntu 18.04. PHP is a widely used general-purpose scripting language that is particularly well suited for web development. It was one of the first server-side languages to be integrated into HTML, making it simple to add functionality to web sites without accessing data from separate files. PHP is used in most web from your blog to the world’s most popular websites, and it’s fast, adaptable, and pragmatic.
How to Install PHP 7.4 on Ubuntu 18.04
- First and foremost, we must ensure that our system is up to date. Run the following command to update and upgrade.
sudo apt update
sudo apt upgrade
Add PHP PPA Repository on Ubuntu 18.04
- We must first install the required packages before we can add a new repository.
sudo apt -y install software-properties-common
- Run this command to add the
ondrej/php
repository.
sudo add-apt-repository ppa:ondrej/php
Sample output
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided. Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa You can get more information about the packages at https://deb.sury.org IMPORTANT: The -backports is now required on older Ubuntu releases. BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/#bug-reporting CAVEATS: 1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman 2. If you are using apache2, you are advised to add ppa:ondrej/apache2 3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline or ppa:ondrej/nginx PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/ WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround: # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php More info: https://launchpad.net/~ondrej/+archive/ubuntu/php Press [ENTER] to continue or Ctrl-c to cancel adding it. Hit:1 http://ppa.launchpad.net/linuxuprising/shutter/ubuntu focal InRelease Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Hit:3 http://us.archive.ubuntu.com/ubuntu focal InRelease Get:4 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease [23.9 kB] Get:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.6 kB] Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.2 kB] Get:8 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main i386 Packages [34.4 kB] Get:9 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B] Get:10 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] Get:11 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages [101 kB] Get:12 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,581 kB] Get:13 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main Translation-en [33.6 kB] Get:14 http://us.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [605 kB] Get:15 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [279 kB] Get:16 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [14.7 kB] Get:17 http://us.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [668 kB] Get:18 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [904 kB] Get:19 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [390 kB] Get:20 http://us.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B] Get:21 http://us.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [8,004 B] Get:22 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [23.7 kB] Fetched 5,113 kB in 20s (256 kB/s) Reading package lists... Done
- Next, update the system package list on newly added repositories before installing PHP 7.4 on Ubuntu 18.04.
Install PHP 7.4 on Ubuntu 18.04
- Run the command below to update the package list on newly added repositories.
sudo apt update
- After updating, run the following command to install PHP 7.4 on Ubuntu 18.04
sudo apt -y install php7.4
- Alternatively you can run the following command to install PHP 7.4 with its modules
sudo apt -y install php7.4-fpm php7.4-bcmath php7.4-curl php7.4-gd php7.4-mbstring php7.4-mysql php7.4-xml php7.4-zip
- Verify PHP version installed using the command below.
php -v
Sample output
PHP 7.4.28 (cli) (built: Feb 17 2022 16:06:35) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
- You have reached the end of the article, Congratulations. You have learned how to Install PHP 7.4 on Ubuntu 18.04.
Other Tutorials
Install WordPress with LAMP Stack on Ubuntu 22.04