Logo

How to Install PHP 7.4 on Ubuntu 22.04

Aug 08, 2023

To install PHP 7.4 on Ubuntu 22.04, you can follow these steps:

Step 1 : Update Package Information:

sudo apt update

Step 2 : Add the Personal Package Archive (PPA):

Now, add the ondrej/php PPA to your system. This PPA offers PHP versions that are not available in the default Ubuntu repositories.

sudo add-apt-repository ppa:ondrej/php

Step 3 : Update Package Information Again:

After adding the PPA, refresh the package information again.

sudo apt update

Step 4 : Install PHP 7.4

sudo apt install php7.4 php7.4-cli php7.4-fpm

Step 5 : Install Essential Extensions:

Next, install essential extensions that enhance PHP's functionality.

  • php7.4-mysql: Adds MySQL support for PHP, allowing interaction with MySQL databases.
  • php7.4-curl: Enables PHP to make HTTP requests and interact with web services.
  • php7.4-json: Provides encoding and decoding of JSON data.
  • php7.4-xsl: Adds XSLT support for XML transformations.
  • php7.4-gd: Provides image manipulation capabilities.
  • php7.4-xml: Provides functionality for parsing and generating XML documents.
  • php7.4-zip: Enables creation and extraction of zip archives.
  • php7.4-soap: Adds SOAP support for web services.
  • php7.4-bcmath: Offers arbitrary precision arithmetic functions.
  • php7.4-mbstring: Provides multibyte character encoding support for strings.
  • php7.4-gettext: Enables internationalization (gettext) functions.
  • php7.4-imagick: Adds support for the Imagick image manipulation library.

You can install these extensions with the following command:

sudo apt install php7.4-{mysql,common,curl,json,xsl,gd,xml,zip,xsl,soap,bcmath,mbstring,gettext,imagick}

Step 6 : Verify PHP Installation:

To confirm that PHP 7.4 is successfully installed, run:

php -v

This command will display information about the installed PHP version.

You have successfully installed PHP 7.4 on Ubuntu 22.04

Recommended