install php 8.4 ubuntu linux

By following this guide to the end, you will have a successful installation of PHP 8.4 on Ubuntu Linux systems under LTS. We’d guide you through the steps used to install, configure PHP, install and manage PHP extensions, and how to use it in your web applications. The PHP 8.4 release brings many new features and improvements, and this is expected to change heavily before the official stable release.

Disclaimer: PHP 8.4 is currently in active development, with several alpha and beta releases available for testing purposes. At this point we don’t recommend using this release of PHP in a production environment, but to get a glimpse of upcoming features. The GA release is expected around November, 2024.

Check out the the following resources to explore in detail what’s new and expected in PHP 8.4:

We also have installation guide for PHP 8.4 on Rocky / AlmaLinux.

Step 1 – Add PHP Repository

We don’t need to build PHP 8.4 packages from source because Ondřej Surý provides pre-built packages. Before adding the repository, update OS packages list and install dependencies.

sudo apt update
sudo apt install software-properties-common gnupg2  apt-transport-https lsb-release ca-certificates

Add ondrej/php PPA (Personal Package Archive) repository into your Ubuntu system.

sudo add-apt-repository ppa:ondrej/php

Proceed with the installation process.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
software-properties-common is already the newest version (0.99.48).
software-properties-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.
ubuntu@ubuntu-cloudspinx-com:~$ sudo add-apt-repository ppa:ondrej/php
PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'Types: deb
URIs: https://ppa.launchpadcontent.net/ondrej/php/ubuntu/
Suites: noble
Components: main
'
Description:
Co-installable PHP versions: PHP 5.6, PHP 7.x, PHP 8.x and most requested extensions are included. Only Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org
....

Step 2 – Install PHP 8.4

With the PPA repository added, we can now install PHP 8.4 on our Ubuntu system. Use the following command to install PHP 8.4:

sudo apt install php8.4 php8.4-cli

Wait for the packages to be downloaded and installed locally.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils debsuryorg-archive-keyring libapache2-mod-php8.4 libapr1t64 libaprutil1-dbd-sqlite3 libaprutil1-ldap libaprutil1t64 liblua5.4-0 php-common
  php8.4-common php8.4-opcache php8.4-readline ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils debsuryorg-archive-keyring libapache2-mod-php8.4 libapr1t64 libaprutil1-dbd-sqlite3 libaprutil1-ldap libaprutil1t64 liblua5.4-0 php-common php8.4
  php8.4-cli php8.4-common php8.4-opcache php8.4-readline ssl-cert
0 upgraded, 18 newly installed, 0 to remove and 25 not upgraded.
Need to get 7,240 kB of archives.
After this operation, 31.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

After the installation verify that PHP 8.4 is installed by checking the version:

$ php --version
PHP 8.4.0alpha2 (cli) (built: Jul 21 2024 07:00:28) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.0alpha2, Copyright (c), by Zend Technologies

Step 3 – Install PHP 8.4 extensions

Run the following commands to install commonly used extensions of PHP.

sudo apt install php8.4-common php8.4-fpm php8.4-mysql php8.4-xml \
php8.4-gd php8.4-mbstring php8.4-zip php8.4-bcmath  php8.4-curl  -y

To get the list of all active PHP modules

php -m

Any other extension can be installed using the following command syntax:

sudo apt install php8.4-<extension>

Step 4 – Configuring PHP

The default PHP configuration files are located in the /etc/php/8.4 directory:

$ ls /etc/php/8.4/
cli  fpm  mods-available

The main configuration file that controls major aspects of PHP is php.ini.

ls /etc/php/8.4/cli/php.ini

Using PHP with Nginx web server

For Nginx and PHP FPM (FastCGI Process Manager)

/etc/php/8.4/fpm/php.ini

PHP FPM default pool configuration

/etc/php/8.4/fpm/pool.d/www.conf

Using PHP with Apache web server

Install libapache2-mod-php package which provides a module for Apache to interpret PHP scripts and serve them as part of web pages

sudo apt install libapache2-mod-php8.4

The main configuration file that affects Apache web server when handling PHP scripts is located in the /etc/php/8.4/apache2/ directory.

/etc/php/8.4/apache2/php.ini

Optimal configuration files

Below are some optimal configurations that you can use in your php.ini file.

memory_limit = 256M
upload_max_filesize = 10M
post_max_size = 12M
max_execution_time = 60
max_input_time = 60
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
display_errors = Off
log_errors = On
error_log = /var/log/php_errors.log
session.save_path = "/var/lib/php/sessions"
disable_functions = exec,shell_exec,system,passthru
expose_php = Off
file_uploads = On

To set the default timezone use:

date.timezone = "Africa/Nairobi"

Step 5 – Testing PHP installation

We can add a test PHP script to show if PHP is working.

sudo tee /var/www/html/hello.php<<EOF
<?php
// This is a comment in PHP
echo "Hello, World!";
?>
EOF

If you see “Hello, World!” message it means our PHP installation is working.

test php installation

We hope in this article you have learned how to install PHP, install additional extensions, and adjust the settings to optimize its performance. We hope you enjoy using PHP 8.4 in your Ubuntu system.

LEAVE A REPLY

Please enter your comment!
Please enter your name here