Skip to main content

How to install PHP 8.3 with Apache on Ubuntu

4 months ago
10
0
0

PHP 8.3 is now the default stable branch on many modern Linux distributions. It brings performance improvements and new language features that make it a very good choice for new projects and upgrades.

In this guide you will learn, step by step, how to install PHP 8.3 with Apache on Ubuntu and get a working LAMP stack that is ready for production.

The guide covers:

  • Ubuntu 24.04 where PHP 8.3 is in the official repositories
  • Ubuntu 22.04 and 20.04 where you use the trusted ondrej/php

What you need before installing PHP 8.3 on Ubuntu

Before you start, make sure you have:

  • Ubuntu 24.04, 22.04 or 20.04 server or VPS
  • A user with sudo privileges
  • Shell access via SSH or local console
  • A domain name (optional, but recommended for production)

Update your system packages first:

sudo apt update
sudo apt upgrade -y

Quick overview of PHP 8.3 + Apache commands

You will find full explanations below, but here is a quick reference.

On Ubuntu 24.04 (official PHP 8.3 packages)

sudo apt update
sudo apt install apache2 -y
sudo apt install php8.3 libapache2-mod-php8.3 php8.3-cli php8.3-mysql php8.3-xml php8.3-curl php8.3-gd php8.3-zip php8.3-mbstring -y
sudo systemctl restart apache2

On Ubuntu 22.04 / 20.04 (using ondrej/php PPA for PHP 8.3)

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudo apt update

sudo apt install apache2 -y
sudo apt install php8.3 libapache2-mod-php8.3 php8.3-cli php8.3-mysql php8.3-xml php8.3-curl php8.3-gd php8.3-zip php8.3-mbstring -y

sudo a2dismod php8.0 php8.1 php8.2 2>/dev/null
sudo a2enmod php8.3
sudo systemctl restart apache2

Installing PHP 8.3 with Apache on Ubuntu 24.04

This section assumes a fresh Ubuntu 24.04 server.

PHP 8.3 is available in the official Ubuntu 24.04 repository, so you do not need external PPAs.

Update packages

sudo apt update
sudo apt upgrade -y

Install Apache

sudo apt install apache2 -y

Enable Apache to start on boot:

sudo systemctl enable apache2
sudo systemctl status apache2

Install PHP 8.3 and the Apache PHP module

The package libapache2-mod-php8.3 integrates PHP 8.3 directly into Apache.

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

Install common PHP 8.3 extensions

Most web apps and CMS need several standard extensions:

sudo apt install php8.3-cli php8.3-mysql php8.3-xml php8.3-curl php8.3-gd php8.3-zip php8.3-mbstring -y

Check the installed PHP version:

php -v

You should see output with PHP 8.3.x.

Restart Apache to load PHP 8.3:

sudo systemctl restart apache2

Installing PHP 8.3 with Apache on Ubuntu 22.04 / 20.04 using PPA

On older Ubuntu versions, PHP 8.3 is not provided in the default repositories. The widely used ondrej/php PPA provides up to date PHP 8.3 builds for Ubuntu LTS releases.

Add the PHP 8.3 PPA

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install Apache

sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2

Install PHP 8.3 and the Apache module

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

Install important extensions

sudo apt install php8.3-cli php8.3-mysql php8.3-xml php8.3-curl php8.3-gd php8.3-zip php8.3-mbstring -y

Switch Apache from older PHP versions to PHP 8.3

If your server previously used PHP 8.0, 8.1 or 8.2, disable the old modules and enable the new one:

sudo a2dismod php8.0 php8.1 php8.2 2>/dev/null
sudo a2enmod php8.3
sudo systemctl restart apache2

Verify PHP 8.3 from the command line:

php -v

Configuring Apache to use PHP 8.3 correctly

In most cases, installing libapache2-mod-php8.3 is enough for Apache to serve .php files with PHP 8.3. If you want to double check or tune the configuration, follow these steps.

Check that PHP 8.3 module is loaded

sudo apachectl -M | grep php

You should see something like:

php8_module (shared)

Ensure index.php has priority

Open the dir.conf file:

sudo nano /etc/apache2/mods-enabled/dir.conf

Make sure index.php appears early in the DirectoryIndex line, for example:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Save the file and reload Apache:

sudo systemctl reload apache2

Creating a PHP info test page

This is a quick way to confirm that Apache runs PHP 8.3 and to inspect the configuration.

Create a simple test file in the default web root:

echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php

Reload Apache just in case:

sudo systemctl reload apache2

Open your browser and visit:

http://YOUR_SERVER_IP/info.php

You should see the PHP information page that shows:

  • PHP Version 8.3.x
  • Loaded PHP modules and configuration
  • Apache integration details

Important: After testing, remove this file. It exposes detailed configuration information that attackers could use.

sudo rm /var/www/html/info.php

Installing additional PHP 8.3 extensions

Different applications need different extensions. You can search and install modules with apt.

List available PHP 8.3 packages:

apt search php8.3-

Install a specific extension, for example imagick or redis:

sudo apt install php8.3-imagick php8.3-redis -y
sudo systemctl restart apache2

Verify the module is loaded:

php -m | grep imagick
php -m | grep redis

Basic PHP 8.3 configuration for production

Most configuration for PHP 8.3 lives in php.ini. The path varies slightly by SAPI and Linux distribution, but on Ubuntu it is usually:

  • /etc/php/8.3/apache2/php.ini for Apache module
  • /etc/php/8.3/cli/php.ini for CLI

Set the correct timezone

Open the Apache PHP configuration file:

sudo nano /etc/php/8.3/apache2/php.ini

Find and set:

date.timezone = "Europe/Berlin"

Replace with your timezone. This avoids warnings and ensures accurate date functions.

Improve security basics

In the same php.ini file you can hide the PHP version:

expose_php = Off

Increase memory or upload limits if your application needs it, for example:

memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50M

After changes, restart Apache:

sudo systemctl restart apache2

Optional: Using PHP 8.3 FPM with Apache instead of mod_php

While libapache2-mod-php8.3 is the simplest route, many production setups prefer PHP FPM for better performance and flexibility.

Install PHP 8.3 FPM:

sudo apt install php8.3-fpm -y

Enable the required Apache modules:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo a2dismod php8.3   # if you were using libapache2-mod-php8.3
sudo systemctl restart apache2

Apache will now forward PHP requests to the FPM service instead of using the embedded module.


Troubleshooting common PHP 8.3 + Apache issues

PHP files download instead of execute

  • Check that libapache2-mod-php8.3 is installed.
  • Confirm the module is loaded: sudo apachectl -M | grep php
  • If nothing appears, run: sudo a2enmod php8.3 sudo systemctl restart apache2

Seeing PHP 8.1 or 8.2 in phpinfo() instead of 8.3

  • Disable older PHP modules and enable PHP 8.3: sudo a2dismod php8.0 php8.1 php8.2 2>/dev/null sudo a2enmod php8.3 sudo systemctl restart apache2
  • Make sure there is no leftover php*-fpm configuration referencing older versions.

403 or 500 errors after enabling PHP 8.3

  • Check Apache syntax: sudo apachectl configtest
  • Look at the Apache error log: sudo tail -n 50 /var/log/apache2/error.log
  • Roll back any recent virtual host or .htaccess changes that may be causing the problem.

FAQ: PHP 8.3 and Apache on Ubuntu

Is PHP 8.3 stable enough for production?

Yes. PHP 8.3 is a stable release and is widely deployed in production environments. As with any upgrade, test your application thoroughly in staging before migrating.

Should I use PHP FPM or the Apache PHP module?

  • Use libapache2-mod-php8.3 if you value simplicity for smaller sites and want fewer moving parts.
  • Use php8.3-fpm if you host many sites, need better performance under load, or may later switch to Nginx.

Can I keep multiple PHP versions installed?

Yes. You can keep multiple versions installed using the ondrej/php PPA and enable one at a time in Apache using a2dismod and a2enmod. Only one version should be active in Apache at once on a given virtual host unless you use more advanced FPM and proxy configurations.

How do I completely remove an old PHP version?

For example, to remove PHP 8.1:

sudo apt purge 'php8.1*'
sudo apt autoremove -y
sudo systemctl restart apache2

Wrap up

You now have a complete guide for installing PHP 8.3 with Apache on Ubuntu:

  • Ubuntu 24.04 using official repositories
  • Ubuntu 22.04 and 20.04 using the ondrej/php PPA
  • Configuration, modules, PHP info test page, and basic hardening

From here you can proceed to install your application stack, such as WordPress, Laravel, Symfony or a custom PHP app, all running on a modern and supported PHP 8.3 environment.


Related Tags:
7 min read
Share this post:

0 comments

Leave a Comment

Please, enter your comment.
Please, enter your name.
Please, provide a valid email address.
Enjoy this post? Join our newsletter
Don’t forget to share it

Related Articles

All posts