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.

警告

第三方提供的版本被视为非官方版本,不直接受 PHP 项目支持。 除非可以通过 » 官方下载区的构建版重现, 否则遇到的任何错误都应报告给这些非官方构建版的提供者。

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.

示例 #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:

示例 #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.

示例 #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.

示例 #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.

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top