Logo

How to Install PHP 7.2 on Ubuntu 24.04

May 02, 2024

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

Step 1 : First, update your package index using the following command:

sudo apt update

Step 2 : Add the Repository (ppa:ondrej/php)

sudo add-apt-repository ppa:ondrej/php

Step 3 : Update your package index again:

sudo apt update

Step 4 : Install PHP 7.2 core packages:

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

Step 5 : Install commonly used PHP extensions:

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

  • php7.2-mysql: Enables PHP to interact with MySQL databases.
  • php7.2-curl: Allows PHP scripts to make HTTP requests and interact with APIs.
  • php7.2-json: Provides functions to encode and decode JSON data, facilitating data exchange.
  • php7.2-xsl: Enables PHP to apply XSLT stylesheets to XML data for transformation.
  • php7.2-gd: Allows PHP to create and manipulate images, useful for image processing tasks.
  • php7.2-xml: Provides functions for parsing and manipulating XML documents.
  • php7.2-zip: Enables PHP scripts to work with ZIP archives, facilitating file compression and extraction.
  • php7.2-soap: Allows PHP to interact with SOAP-based web services for communication between systems.
  • php7.2-bcmath: Provides functions for precise mathematical calculations with large numbers.
  • php7.2-mbstring: Handles multibyte character encodings for proper string manipulation.
  • php7.2-common: Includes common files for PHP, providing core functionality such as basic PHP functions and configuration files.

Step 6 : Verify the PHP version installed:

php -v

Congratulations! You have successfully installed PHP 7.2 on Ubuntu 24.04.

Recommended