isChild | anchor |
---|---|
true |
linux_setup |
Most GNU/Linux distributions come with PHP available from the official repositories, but those packages usually are a little behind the current stable version. There are multiple ways to get newer PHP versions on such distributions.
On Ubuntu and Debian-based GNU/Linux distributions, for instance, the best alternatives for native packages are provided and maintened by Ondřej Surý, through his Personal Package Archive (PPA) on Ubuntu and DPA/bikeshed on Debian. Find instructions for each of these below.
For Ubuntu distributions, the PPA by Ondřej Surý provides supported PHP versions along with many PECL extensions. To add this PPA to your system, perform the following steps in your terminal:
-
First, add the PPA to your system's software sources using the command:
sudo add-apt-repository ppa:ondrej/php
-
After adding the PPA, update your system's package list:
sudo apt update
This will ensure that your system can access and install the latest PHP packages available in the PPA.
For Debian-based distributions, Ondřej Surý also provides a bikeshed (Debian equivalent of a PPA). To add the bikeshed to your system and update it, follow these steps:
-
Ensure that you have root access. If not, you might need to use
sudo
for the following commands. -
Update your system's package list:
sudo apt-get update
-
Install
lsb-release
,ca-certificates
, andcurl
:sudo apt-get -y install lsb-release ca-certificates curl
-
Download the signing key for the repository:
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
-
Add the repository to your system's software sources:
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
-
Finally, update your system's package list again:
sudo apt-get update
With these steps, your system will be able to install the latest PHP packages from the bikeshed.
On RPM-based distributions (CentOS, Fedora, RHEL, etc.) you can use the Remi's RPM repository to install the latest PHP version or to have multiple PHP versions simultaneously available.
There is a configuration wizard available to configure your RPM-based distribution.
All that said, you can always use containers or compile the PHP source code from scratch.