Logo

How to Install PHP 7.2 on Ubuntu 22.04

Aug 07, 2023

To install PHP 7.2 on Ubuntu 22.04, you can use the ondrej/php PPA (Personal Package Archive), which provides different PHP versions. Follow the steps below to install PHP 7.2:

Step 1 : Update the package list and upgrade existing packages:

sudo apt update
sudo apt upgrade

Step 2 : Install the software-properties-common package, which is needed to add external repositories:

sudo apt install software-properties-common

Step 3 : Add the ondrej/php repository, which provides various PHP versions:

sudo add-apt-repository ppa:ondrej/php

Step 4 : Update the package list again to include the new repository:

sudo apt update

Step 5 : Install PHP 7.2 along with some commonly used extensions. You can customize the list of extensions based on your specific needs. Here's how to install PHP 7.2:

sudo apt install php7.2 php7.2-common php7.2-cli php7.2-fpm

During the installation, you may be prompted to confirm the installation by typing 'Y' and pressing Enter.

Step 6 : Install commonly used PHP extensions. You can add or remove extensions based on your specific needs:

  • php7.2-mysql: MySQL extension for PHP 7.2 (enables PHP to work with MySQL databases).
  • php7.2-curl: cURL extension for PHP 7.2 (enables HTTP requests from PHP).
  • php7.2-json: JSON extension for PHP 7.2 (enables JSON manipulation in PHP).
  • php7.2-xsl: XSL extension for PHP 7.2 (enables XSLT transformations in PHP).
  • php7.2-gd: GD extension for PHP 7.2 (enables image processing functions in PHP).
  • php7.2-xml: XML extension for PHP 7.2 (enables XML-related functions).
  • php7.2-zip: ZIP extension for PHP 7.2 (enables ZIP archive support in PHP).
  • php7.2-soap: SOAP extension for PHP 7.2 (enables SOAP web services support in PHP).
  • php7.2-bcmath: BCMath extension for PHP 7.2 (enables arbitrary precision mathematics).
  • php7.2-mbstring: Multibyte String extension for PHP 7.2 (enables multibyte character encoding support).
  • php7.2-gettext: Gettext extension for PHP 7.2 (enables internationalization support in PHP).
  • php7.2-imagick: Imagick extension for PHP 7.2 (enables image manipulation with ImageMagick).

Install the extensions using the following command:

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

Step 7 : Verify PHP 7.2 Installation

Once the installation is complete, you can verify the PHP version to ensure that PHP 7.2 is installed. Run the following command:

php -v

This command will display the PHP version, and it should show that PHP 7.2 is now installed.

Congratulations! PHP 7.2 and the specified extensions are now installed on your Ubuntu 22.04 system. You can start using PHP for your web applications or command-line scripts.

Recommended