Installing PHP on Fedora: php-fpm and wiring it to a web server
PHP on Fedora comes from the distribution repositories — no third-party repo needed. F45 ships PHP 8.5, and it works right after installing.
Which packages
Section titled “Which packages”sudo dnf install php php-fpm php-cli| Package | Purpose | Without it |
|---|---|---|
php | meta package with common extensions | bare CLI only |
php-cli | command-line interpreter | no php command |
php-fpm | FastCGI process manager | CLI only, no web serving |
Measured version on F45:
php-8.5.12-1.fc45.x86_64Verify the CLI first
Section titled “Verify the CLI first”php -vPHP 8.5.12 (cli) (built: Oct 19 2026 17:02:46) (NTS gcc x86_64)Copyright (c) The PHP GroupHow many extensions are loaded:
php -m | grep -cE "^[a-z]"35Which configuration file is read — this matters more than anything, because editing the wrong file is the classic mistake:
php --iniConfiguration File (php.ini) Path: "/etc"Loaded Configuration File: "/etc/php.ini"Scan for additional .ini files in: "/etc/php.d"So: main config /etc/php.ini, per-extension files in /etc/php.d/*.ini. CLI picks changes up immediately; php-fpm must be restarted.
php-fpm is stopped by default
Section titled “php-fpm is stopped by default”php-fpm -vsystemctl is-enabled php-fpmPHP 8.5.12 (fpm-fcgi) (built: Oct 19 2026 17:02:46) (NTS gcc x86_64)disabledInstalling does not start it:
sudo systemctl enable --now php-fpmsystemctl status php-fpm --no-pagerIts pool configuration lives in /etc/php-fpm.d/:
ls /etc/php-fpm.d/www.confThe listen = line in www.conf decides whether it uses a Unix socket or a TCP port — half of all nginx misconfigurations come from this mismatch.
Wiring nginx
Section titled “Wiring nginx”sudo dnf install nginxsudo tee /etc/nginx/conf.d/php.conf >/dev/null <<'EOF'server { listen 80; server_name _; root /usr/share/nginx/html; index index.php index.html;
location ~ \.php$ { fastcgi_pass unix:/run/php-fpm/www.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }}EOFsudo systemctl enable --now nginx php-fpmA probe:
echo '<?php phpinfo();' | sudo tee /usr/share/nginx/html/info.phpcurl -s http://127.0.0.1/info.php | head -5HTML coming back means it works. Delete info.php afterwards.
Wiring httpd (Apache)
Section titled “Wiring httpd (Apache)”sudo dnf install httpd phpsudo systemctl enable --now httpdecho '<?php echo PHP_VERSION;' | sudo tee /var/www/html/v.phpcurl -s http://127.0.0.1/v.phpWith httpd’s mod_php you do not need php-fpm; with nginx you do.
Installing extensions
Section titled “Installing extensions”sudo dnf search php- | grep -i mysql # find the package name firstsudo dnf install php-mysqlnd php-gd php-opcachesudo systemctl restart php-fpmConfirm with php -m. Extensions are separate RPMs, not pecl install — Fedora packages them so upgrades do not wipe them.
Common traps
Section titled “Common traps”| Symptom | Cause |
|---|---|
| browser downloads the .php file | nginx lacks location ~ \.php$, or FastCGI is not connected |
502 Bad Gateway | php-fpm not running, or socket path mismatch |
| php.ini change has no effect | you edited it but fpm needs systemctl restart php-fpm |
extension installed but missing from php -m | installed for a different version prefix (e.g. php84-php-*) |
Related pages
Section titled “Related pages”- Fedora repositories and dnf5 — installing packages
- systemd services and timers — why php-fpm is not enabled
- firewalld — opening 80/443
- SELinux —
restoreconafter changing the document root - Official: PHP