Logo

How to Install PHP 7.4 on Ubuntu 23.04

Dec 02, 2023

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

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

sudo apt update

Step 2 : Add the PHP Repository

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

- Add the Repository (ppa:ondrej/php)

sudo add-apt-repository ppa:ondrej/php

- Open the file

sudo nano /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 : Set Package Preferences

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

sudo nano /etc/apt/preferences.d/ondrejphp

Add the following lines:

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

Save the file.

Step 5 : Install PHP 7.4 Core

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

Step 6 : Install commonly used PHP extensions:

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

Explanation of Extensions:

- mysql: MySQL database support

- curl: cURL support for making HTTP requests

- json: JSON support

- xsl: XSL extension for XML manipulation

- gd: GD graphics library support for image processing

- xml: XML support

- zip: ZIP archive support

- soap: SOAP protocol support

- bcmath: Arbitrary precision mathematics support

- mbstring: Multibyte string support

- gettext: Gettext support for message translation

- imagick: ImageMagick support for image manipulation

Step 7 : Check PHP Version

php -v

Congratulations, you have successfully installed PHP 7.4 on Ubuntu 23.04 with the necessary extensions.

Recommended