Install PHP

Updated: 2022.11.23


Debian / Ubuntu

Fedora / Rocky / RHEL

Install PHP on a Linux server to run PHP applications.


Install PHP

The PHP version available in most default package repositories can be outdated. Add a PHP repository to your system to install more recent versions of PHP. For Debian distros this will be the Ondřej Surý PPA , and for Fedora distros this will be the Remi repository .


Verify that the required packages software-properties-common and apt-transport-https are installed.

sudo apt install software-properties-common apt-transport-https

Add the ondrej/php PPA to the system sources.

# Debian
sudo curl -sSLo /usr/share/keyrings/
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/] $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
# Ubuntu
sudo add-apt-repository ppa:ondrej/php

Update package sources and install PHP. The latest PHP release will be installed by default. To install a specific version, append the version number: php8.1 php7.4.

sudo apt install php


Verify that the required package dnf-utils is installed.

sudo dnf install dnf-utils

Add the repository to the system sources.

sudo dnf install

Change the module selection to the latest version of PHP, or the version required by your application. View available module versions using dnf module list php.

sudo dnf module enable php:remi-8.1

Install the selected PHP version.

sudo dnf install php

PHP Extensions

Refer to the PHP Manual Extension List for available packages. To install an extension, install the system package with the naming scheme php-extensionname.

# Debian
sudo apt install php-openssl
# Fedora
sudo dnf install php-openssl

Common Dependencies

Common packages required to integrate PHP with other applications.


# Debian
sudo apt install libapache2-mod-php


# Debian
sudo apt install php-fpm
# Fedora
sudo dnf install php-fpm

MariaDB / MySQL

# Debian
sudo apt install php-mysql
# Fedora
sudo dnf install php-mysqlnd