PHP Setup
Debian / Ubuntu
Fedora / Rocky / RHEL
Overview
Install PHP for web applications on a Linux server.
Assumptions
Initial System Setup completed.
Logged in as administrative user.
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 upgradeInstall 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-httpsSome 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/phpUpdate 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 phpFedora
Verify that the required package dnf-utils is installed.
sudo dnf install dnf-utilsAdd the remirepo.net repository to the system sources.
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpmSelect 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.1Install the selected PHP version.
sudo dnf check-update
sudo dnf install phpPHP 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.inisudo nano /etc/php/8.3/cli/php.iniPHP 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-opensslCommon Dependencies
Common packages required to integrate PHP with other applications.
Apache
# Debian
sudo apt install libapache2-mod-phpNginx
# Debian
sudo apt install php-fpm# Fedora
sudo dnf install php-fpmMariaDB / MySQL
# Debian
sudo apt install php-mysql# Fedora
sudo dnf install php-mysqlndReferences
The PHP Group. “PHP Documentation .” 2025. ↩︎
The PHP Group. “PHP GitHub .” 2025. ↩︎
Ondřej Surý. “DEB.SURY.ORG .” 2025. ↩︎
Remi. “Remi’s RPM Repository .” 2025. ↩︎