Web20 University

How to Install PHP 8.4 on Ubuntu

Get Unlimited Bandwidth and FREE Domain Names for All Your PHP Projects!

As of September 2024, PHP 8.4 has been released with really useful new features like improved array functions and more streamlined object syntax.

If you’re wanting to try this out on your hosting service then you’re going to need to update your PHP version via your cPanel admin or similar.

Alternatively if you are running Ubuntu locally or have access to your hosting environment you can update this manually yourself.

Here’s a step-by-step guide on how to install PHP 8.4 on Ubuntu, whether you’re using 20.04, 22.04, or other versions.

Step 1: Update Your System

Before installing PHP 8.4, ensure that your system is up-to-date:

sudo apt update && sudo apt upgrade -y

Step 2: Add the PHP Repository

You need to add the Ondřej Surý PPA, which hosts the latest PHP versions. This PPA often has early versions of PHP releases, including 8.4:

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

Step 3: Install PHP 8.4

Once the repository is added, you can install PHP 8.4 along with common extensions:

sudo apt install php8.4 php8.4-cli php8.4-fpm php8.4-mysql php8.4-xml php8.4-mbstring php8.4-curl

You can add more extensions as needed, depending on your use case.

Step 4: Verify PHP Installation

To confirm that PHP 8.4 is correctly installed, use the following command:

php -v

This should display the installed PHP version, which should now be 8.4.

Step 5: Configure Apache or Nginx

If you’re using Apache, enable PHP 8.4 by disabling the older version and enabling the new one:

sudo a2dismod php8.2  # Example for PHP 8.2
sudo a2enmod php8.4
sudo systemctl restart apache2

For Nginx, you’ll need to adjust your configuration to point to PHP 8.4’s FPM service:

sudo systemctl restart php8.4-fpm
sudo systemctl restart nginx

Step 6: Set PHP 8.4 as Default (Optional)

If you have multiple PHP versions installed and want to set PHP 8.4 as the default, run:

sudo update-alternatives --set php /usr/bin/php8.4

Now, PHP 8.4 should be your default version when using php in the terminal.

Conclusion

Installing PHP 8.4 on Ubuntu is straightforward by using the Ondřej Surý PPA. With its latest features, PHP 8.4 brings performance improvements and new functions that can simplify your development process. By following these steps, you’ll have PHP 8.4 up and running in no time on your Ubuntu machine.

For more information on PHP 8.4’s new features, check out detailed release notes and community discussions:

Get Unlimited Bandwidth and FREE Domain Names for All Your PHP Projects!