PHP Setup

Last Edit: 2025-02-28

Debian / Ubuntu

Fedora / Rocky / RHEL

Overview

Install PHP for web applications on a Linux server.

Assumptions

Update

Before getting started, update package repositories and apply upgrades for the latest patches.

# Debian
sudo apt update
sudo apt upgrade
# Fedora
sudo dnf check-update
sudo dnf upgrade

Install PHP

The PHP version included in default package repositories used to be significantly outdated, this is no longer true.

A third party repository can be optionally used for the most recent version. For Debian distributions this will be the Ondřej Surý PPA , and for Fedora distros this will be the Remi repository .

Debian

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

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

Some systems may require the python3-launchpadlib package .

Add the ondrej/php PPA to the system sources.

# Debian
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
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'
# 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.3 php7.4.

sudo apt update
sudo apt install php

Fedora

Verify that the required package dnf-utils is installed.

sudo dnf install dnf-utils

Add the remirepo.net repository to the system sources.

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Select 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 check-update
sudo dnf install php

PHP Configuration

Configure PHP with the php.ini files found in the /etc/php/8.3/ directory, where 8.3 is the current version of PHP the system is using.

Determine the current PHP version with the php -v command. Get a list of all additional PHP configuration files in use with php --ini.

Depending on system applications and modules installed, multiple configuration directories will be available. For example to modify the Apache or CLI configurations:

sudo nano /etc/php/8.3/apache2/php.ini
sudo nano /etc/php/8.3/cli/php.ini

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.

Apache

# Debian
sudo apt install libapache2-mod-php

Nginx

# 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

References

1 2 3 4 5 6


  1. The PHP Group. “PHP Documentation .” 2025. ↩︎

  2. The PHP Group. “PHP GitHub .” 2025. ↩︎

  3. Debian. “PHP .” 2025. ↩︎

  4. The PHP Group. “Apache .” 2025. ↩︎

  5. Ondřej Surý. “DEB.SURY.ORG .” 2025. ↩︎

  6. Remi. “Remi’s RPM Repository .” 2025. ↩︎