How to install PHP on Ubuntu 26.04
development linux ubuntuThe PPA from Ondřej Surý does is about to be migrated to https://packages.sury.org/php/, so to use that instead of the current PPA, you can follow these steps:
# Remove old PPA
sudo rm /etc/apt/sources.list.d/ondrej-ubuntu-php-*
# Install dependencies
sudo apt install -y ca-certificates curl lsb-release
# Download and install the keyring
curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
# Update package lists
sudo apt update
# Install PHP version of your choice
sudo apt install php[version]
I have multiple PHP versions installed, what to do then?
Don't worry — Ubuntu has a built-in option to easily set your default PHP version using the command line. If you choose auto mode, the system will automatically select the alternative with the highest priority.
This means that if a newer version of PHP is installed with a higher priority, the system will switch to it without requiring manual intervention. For example, if PHP 7.4 is currently running in auto mode and you install PHP 8.2 with a higher priority (such as 100), the system will automatically switch to PHP 8.2.
sudo update-alternatives --config php
[sudo] password for tomas:
There are 6 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/php8.4 84 auto mode
1 /usr/bin/php7.4 74 manual mode
2 /usr/bin/php8.0 80 manual mode
3 /usr/bin/php8.1 81 manual mode
4 /usr/bin/php8.2 82 manual mode
* 5 /usr/bin/php8.3 83 manual mode
6 /usr/bin/php8.4 84 manual mode
Want to Hire Me?
I work as a freelancer in my company 7th Green. My strengths include TYPO3, PHP, DevOps and Automation.
Reach out, I'd be happy to talk about your project.