Rostyslav Rava - Personal Website

How to Install Latest PHP on Ubuntu

PHP is available on Ubuntu out of the box, but there are several reasons not to install it from the default distribution. Usually, the available version is outdated and tied to a specific release.

For example, Ubuntu 22.04.5 includes PHP 8.1.2, while Ubuntu 24.04.3 includes PHP 8.3.6. These versions are outdated compared to current releases. Additionally, PHP 8.1 coming with Ubuntu 22.04 will soon reach EOL, making it an unsuitable option.

If there are no strict requirements to use a version tied to a specific Ubuntu release, it is better to use a newer version.

Yes, it is certainly possible to build and install the latest PHP versions from source. However, if there is no such development need, everything has already been done and is available in a separate repository. This is possible thanks to Ondřej Surý, who has been maintaining this repository since Y2K.

The repository can be added using a single command.

sudo add-apt-repository ppa:ondrej/php

After that, the following output will be shown:

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. Packages are provided for *Current* Ubuntu *LTS* releases (https://wiki.ubuntu.com/Releases).  Expanded Security Maintenance releases ARE NOT supported.

Debian stable, oldstable and Debian LTS packages are provided from a separate repository: https://deb.sury.org/#debian-dpa

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

BUGS&FEATURES: This PPA has a issue tracker:
https://deb.sury.org/#bug-reporting

Issues reported in a private email don't scale and most likely will be ignored.  I simply don't have capacity to answer questions privately.

CAVEATS:
1. If you are using apache2, you are advised to add ppa:ondrej/apache2
2. If you are using nginx, you are advised to add ppa:ondrej/nginx

DONATION: If you like my work and you want to show appreciation, please consider donating regularly: https://donate.sury.org/

COMMERCIAL SUPPORT: Support for PHP packages for older Debian and Ubuntu release can be bought from https://www.freexian.com/lts/php/
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.

By pressing Enter, the repository will be added.

Alternatively, you may add the repository with the -y parameter, so additional interaction and confirmation with Enter will not be needed.

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

After that, update the package list, which will make up-to-date PHP versions like 8.1.34, 8.3.29 or even the latest PHP 8.5.1 available.

sudo apt update

All packages for available PHP versions and modules are well organized and named following the pattern php-<major_version>.<minor_version>-<module_name>.

To install PHP 8.5 CLI, use the following command:

sudo apt -y install php8.5-cli

Additional modules can be installed using the same pattern. For example, the MySQL module:

sudo apt -y install php8.5-mysql

This can be verified by running a version check:

php -version

The output confirms that PHP is installed and ready to use.

PHP 8.5.1 (cli) (built: Dec 18 2025 23:39:41) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies

By following these steps, the latest PHP version can be installed on an Ubuntu machine. Additional PHP modules and extensions can be installed using the same naming pattern as needed for your specific requirements.

Tags:

Last updated: