Install PHP 8.4 on Ubuntu 24.04

Install PHP 8.4 on Ubuntu 24.04

PHP is a programming language which often used for creating web applications and dynamic websites. New features and various changes are introduced on each release of PHP.

This tutorial demonstrates how to install PHP 8.4 on Ubuntu 24.04.

Install PHP

Add PHP repository:

sudo add-apt-repository -y ppa:ondrej/php

Run the following command to install PHP 8.4 with command line interface (CLI):

sudo apt install -y php8.4-common php8.4-cli

When installation is completed, we can check PHP version:

php --version

PHP has various extensions which provides additional functionality. We can install PHP extensions using the following syntax:

sudo apt install -y php8.4-extension_name

Run the following command to install commonly used PHP extensions:

sudo apt install -y php8.4-curl php8.4-gd php8.4-mbstring php8.4-xml php8.4-zip

The -m option allows checking which extensions are currently installed.

php -m

PHP integration with MySQL or MariaDB

If you want to use PHP with MySQL or MariaDB database, install the following extension:

sudo apt install -y php8.4-mysql

PHP integration with Apache

If you want to integrate PHP with Apache HTTP server, install the following extension:

sudo apt install -y libapache2-mod-php8.4

When it finished, restart Apache:

sudo service apache2 restart

PHP integration with Nginx

If you want to integrate PHP with Nginx, install the FPM extension:

sudo apt install -y php8.4-fpm

Testing PHP

Create a new main.php file:

nano main.php

Once the file is opened, add the following lines of code:

<?php

echo 'Hello world';

Execute command to test a script:

php main.php

Uninstall PHP

If you want to completely remove PHP and related dependencies, run the following command:

sudo apt purge --autoremove -y php-common

Remove repository:

sudo rm -rf /etc/apt/sources.list.d/ondrej-ubuntu-php-noble.sources

Remove PHP related file:

sudo rm -rf /var/lib/systemd/timers/stamp-phpsessionclean.timer

Install older versions

PHP 8.3 is an older version that is still supported. It can be installed by changing php8.4 to php8.3 in this post presented commands.

Leave a Comment

Cancel reply

Your email address will not be published.