Install PHP 8.3 on Ubuntu 24.04

Install PHP 8.3 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.3 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.3 with command line interface (CLI):

sudo apt install -y php8.3-common php8.3-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.3-extension_name

Run the following command to install commonly used PHP extensions:

sudo apt install -y php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-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.3-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.3

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.3-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.2 is an older version that is still supported. It can be installed by changing php8.3 to php8.2 in this post presented commands.

Leave a Comment

Cancel reply

Your email address will not be published.