In this article, we’ll see how to install PHP 7.4 on Ubuntu 20.04. PHP is a very popular server scripting language, and it is widely used for creating dynamic and interactive web pages.
Steps to Install PHP 7.4 on Ubuntu 20.10/20.04
Step 1: Update Ubuntu system
sudo apt update
Step 2: Install php and required package on Ubuntu
sudo apt install php php-xml php-cli php-json php-common php-mysql php-fpm php-zip php-gd php-mbstring php-pear php-bcmath php-curl
Sample Output:
root@php:~# sudo apt install php php-xml php-cli php-json php-common php-mysql php-fpm php-zip php-gd php-mbstring php-pear php-bcmath php-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
php-common is already the newest version (2:76).
php-common set to manually installed.
php-gd is already the newest version (2:7.4+76).
php-gd set to manually installed.
php-mysql is already the newest version (2:7.4+76).
php-mysql set to manually installed.
php-xml is already the newest version (2:7.4+76).
php-xml set to manually installed.
php-bcmath is already the newest version (2:7.4+76).
php-bcmath set to manually installed.
php-mbstring is already the newest version (2:7.4+76).
php-mbstring set to manually installed.
The following package was automatically installed and is no longer required:
virtualbox-guest-utils
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libzip5 php7.4 php7.4-curl php7.4-fpm php7.4-zip
The following NEW packages will be installed:
libzip5 php php-cli php-curl php-fpm php-json php-pear php-zip php7.4
php7.4-curl php7.4-fpm php7.4-zip
0 upgraded, 12 newly installed, 0 to remove and 238 not upgraded.
Need to get 1,846 kB of archives.
After this operation, 7,543 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 libzip5 amd64 1.5.1-0ubuntu1 [46.7 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe amd64 php7.4-fpm amd64 7.4.9-1ubuntu1.1 [1,436 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu groovy-updates/main amd64 php7.4 all 7.4.9-1ubuntu1.1 [9,244 B]
Get:4 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 php all 2:7.4+76 [2,772 B]
Get:5 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 php-cli all 2:7.4+76 [3,252 B]
Get:6 http://us.archive.ubuntu.com/ubuntu groovy-updates/main amd64 php7.4-curl amd64 7.4.9-1ubuntu1.1 [31.1 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu groovy/main amd64 php-curl all 2:7.4+76 [2,004 B]
Get:8 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 php-fpm all 2:7.4+76 [2,856 B]
Get:9 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 php-json all 2:7.4+76 [2,004 B]
Get:10 http://us.archive.ubuntu.com/ubuntu groovy-updates/main amd64 php-pear all 1:1.10.9+submodules+notgz-1ubuntu0.20.10.2 [286 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu groovy-updates/universe amd64 php7.4-zip amd64 7.4.9-1ubuntu1.1 [21.5 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 php-zip all 2:7.4+76 [1,996 B]
Fetched 1,846 kB in 9s (208 kB/s)
Selecting previously unselected package libzip5:amd64.
(Reading database ... 206106 files and directories currently installed.)
Preparing to unpack .../00-libzip5_1.5.1-0ubuntu1_amd64.deb ...
Unpacking libzip5:amd64 (1.5.1-0ubuntu1) ...
Selecting previously unselected package php7.4-fpm.
Preparing to unpack .../01-php7.4-fpm_7.4.9-1ubuntu1.1_amd64.deb ...
Unpacking php7.4-fpm (7.4.9-1ubuntu1.1) ...
Selecting previously unselected package php7.4.
Preparing to unpack .../02-php7.4_7.4.9-1ubuntu1.1_all.deb ...
Unpacking php7.4 (7.4.9-1ubuntu1.1) ...
Selecting previously unselected package php.
Preparing to unpack .../03-php_2%3a7.4+76_all.deb ...
Unpacking php (2:7.4+76) ...
Selecting previously unselected package php-cli.
Preparing to unpack .../04-php-cli_2%3a7.4+76_all.deb ...
Unpacking php-cli (2:7.4+76) ...
Selecting previously unselected package php7.4-curl.
Preparing to unpack .../05-php7.4-curl_7.4.9-1ubuntu1.1_amd64.deb ...
Unpacking php7.4-curl (7.4.9-1ubuntu1.1) ...
Selecting previously unselected package php-curl.
Preparing to unpack .../06-php-curl_2%3a7.4+76_all.deb ...
Unpacking php-curl (2:7.4+76) ...
Selecting previously unselected package php-fpm.
Preparing to unpack .../07-php-fpm_2%3a7.4+76_all.deb ...
Unpacking php-fpm (2:7.4+76) ...
Selecting previously unselected package php-json.
Preparing to unpack .../08-php-json_2%3a7.4+76_all.deb ...
Unpacking php-json (2:7.4+76) ...
Selecting previously unselected package php-pear.
Preparing to unpack .../09-php-pear_1%3a1.10.9+submodules+notgz-1ubuntu0.20.10.
2_all.deb ...
Unpacking php-pear (1:1.10.9+submodules+notgz-1ubuntu0.20.10.2) ...
Selecting previously unselected package php7.4-zip.
Preparing to unpack .../10-php7.4-zip_7.4.9-1ubuntu1.1_amd64.deb ...
Unpacking php7.4-zip (7.4.9-1ubuntu1.1) ...
Selecting previously unselected package php-zip.
Preparing to unpack .../11-php-zip_2%3a7.4+76_all.deb ...
Unpacking php-zip (2:7.4+76) ...
Setting up php-pear (1:1.10.9+submodules+notgz-1ubuntu0.20.10.2) ...
Setting up php7.4-curl (7.4.9-1ubuntu1.1) ...
Creating config file /etc/php/7.4/mods-available/curl.ini with new version
Setting up php7.4-fpm (7.4.9-1ubuntu1.1) ...
Creating config file /etc/php/7.4/fpm/php.ini with new version
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.
Created symlink /etc/systemd/system/multi-user.target.wants/php7.4-fpm.service
→ /lib/systemd/system/php7.4-fpm.service.
Setting up libzip5:amd64 (1.5.1-0ubuntu1) ...
Setting up php-json (2:7.4+76) ...
Setting up php7.4 (7.4.9-1ubuntu1.1) ...
Setting up php7.4-zip (7.4.9-1ubuntu1.1) ...
Creating config file /etc/php/7.4/mods-available/zip.ini with new version
Setting up php-fpm (2:7.4+76) ...
Setting up php-cli (2:7.4+76) ...
update-alternatives: using /usr/bin/php.default to provide /usr/bin/php (php) i
n auto mode
update-alternatives: using /usr/bin/phar.default to provide /usr/bin/phar (phar
) in auto mode
update-alternatives: using /usr/bin/phar.phar.default to provide /usr/bin/phar.
phar (phar.phar) in auto mode
Setting up php-zip (2:7.4+76) ...
Setting up php (2:7.4+76) ...
Setting up php-curl (2:7.4+76) ...
Processing triggers for systemd (246.6-1ubuntu1) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for libapache2-mod-php7.4 (7.4.9-1ubuntu1.1) ...
Processing triggers for libc-bin (2.32-0ubuntu3) ...
Processing triggers for php7.4-cli (7.4.9-1ubuntu1.1) ...
Processing triggers for php7.4-fpm (7.4.9-1ubuntu1.1) ...
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.
root@php:~#
Step 3: Verify the php version
$ php --version
Step 4: Listing all loaded PHP modules:
$ php -m
Sample Output:
root@php:~# php -m [PHP Modules] bcmath calendar Core ctype curl date dom exif FFI fileinfo filter ftp gd gettext hash iconv json ldap libxml mbstring mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql Phar posix readline Reflection session shmop SimpleXML sockets sodium SPL standard sysvmsg sysvsem sysvshm tokenizer xml xmlreader xmlwriter xsl Zend OPcache zip zlib [Zend Modules] Zend OPcache root@php:~#
If you are looking for installing php version for ubuntu 18.04.
Steps to Install PHP 7.4 on Ubuntu 18.04/16.04
Step 1: Install Prerequisite package
sudo apt-get update sudo apt -y install software-properties-common
Step 2: Add PHP repository
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Step 3: Install PHP 7.4 on Ubuntu 18.04/19.04/16.04
sudo apt -y install php7.4
Step 4: Verify the PHP version
$ php -v
Step 5: Install additional package
sudo apt-get install -y php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,common}
Location for php config : /etc/php/7.4/apache2/php.ini
Step to configure PHP 7.4 with Nginx on Ubuntu
If you want to use Nginx and PHP instead of apache2
Step 1: Disable Apache on Ubuntu
sudo systemctl disable --now apache2
Sample Output:
root@php:~# sudo systemctl disable --now apache2 Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install disable apache2 Removed /etc/systemd/system/multi-user.target.wants/apache2.service. root@php:~#
Step 2: Install fpm extension and nginx packages
sudo apt-get install nginx php7.4-fpm
Check Nginx Version:
root@php:~# nginx -v nginx version: nginx/1.18.0 (Ubuntu) root@php:~#
FPM configuration file is /etc/php/7.4/fpm/pool.d/www.conf
Step 3: Verify status of fpm and nginx
$ systemctl status php7.4-fpm
$ systemctl status nginx
End of article – You’ve learned how Install PHP 7.4 on Ubuntu 20.10/20.04/18.04/16.04.