Logo

How to Install PHP 7.2 on Ubuntu 23.04

Dec 02, 2023

To install PHP 7.2 on Ubuntu 23.04, follow the steps below.

Step 1 : Ensure your system is up-to-date by running:

sudo apt update

Step 2 : Add the Repository

Since ppa:ondrej/php does not officially support non-LTS versions of Ubuntu, follow these steps:

- Add the Repository (ppa:ondrej/php):

sudo add-apt-repository ppa:ondrej/php

- Open the file

/etc/apt/sources.list.d/ondrej-ubuntu-php-lunar.list

- Find "lunar" and replace it with "jammy" Save the file.

Step 3 : Update Again

sudo apt update

Step 4 : Create Pinning Preferences

Create the file /etc/apt/preferences.d/ondrejphp and add the following code:

Package: libgd3
Pin: release n=lunar
Pin-Priority: 900

Step 5 : Install PHP 7.2 core packages:

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

Step 6 : Install commonly used PHP extensions:

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

Explanation:

- mysql: MySQL database connectivity.

- curl: cURL library for making HTTP requests.

- json: JSON data format support.

- xsl: XSL extension for XML manipulation.

- gd: Graphics Draw (image processing).

- xml: XML support.

- zip: ZIP archive support.

- soap: Simple Object Access Protocol.

- bcmath: Arbitrary precision mathematics.

- mbstring: Multibyte string functions.

- gettext: Internationalization (i18n) and localization (l10n) support.

- imagick: ImageMagick PHP extension for image manipulation.

Step 7 : Verify that PHP 7.2 is installed successfully:

php -v

Congratulations! You have successfully installed PHP 7.2 on Ubuntu 23.04 with the necessary extensions.

Recommended