Installing from packages on GNU/Linux distributions that use DNF

While PHP can be installed from source, it is also available through packages on systems that use DNF, such as Red Hat Enterprise Linux, OpenSUSE, Fedora, CentOS, Rocky Linux, and Oracle Enterprise Linux.

Warning

Builds from third-parties are considered unofficial and not directly supported by the PHP project. Any bugs encountered should be reported to the provider of those unofficial builds unless they can be reproduced using the builds from » the official download area.

The packages can be installed using the dnf command.

Installing packages

First, note that other related packages may be desired like php-pear for » PEAR, or php-mysqlnd for the MySQL extension.

Second, before installing a package, it's wise to ensure the package list is up to date. Typically, this is done by running the command dnf update.

Example #1 DNF Install Example

# dnf install php php-common

DNF will automatically install the configuration for PHP for the web server, but it may need to be restarted in order for the changes to take effect. For example:

Example #2 Restarting Apache once PHP is installed

# sudo systemctl restart httpd

Better control of configuration

In the last section, PHP was installed with only core modules. It's very likely that additional modules will be desired, such as MySQL, cURL, GD, etc. These may also be installed via the dnf command.

Example #3 Methods for listing additional PHP packages

# dnf search php

The list of packages will include a large number of packages that includes basic PHP components, such as php-cli, php-fpm, and php-devel, as well as many PHP extensions. When extensions are installed, additional packages will be automatically installed as necessary to satisfy the dependencies of those packages.

Example #4 Install PHP with MySQL, GD

# dnf install php-mysqlnd php-gd

DNF will automatically add the appropriate lines to the different php.ini related files like /etc/php/8.3/php.ini, /etc/php/8.3/conf.d/*.ini, etc. and depending on the extension will add entries similar to extension=foo.so. However, restarting the web server (like Apache) is required before these changes take affect.

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top