
Fedora 45 shipped on November 3, 2026, and the first thing most people do on a fresh install is try to get a web stack running. That is where the confusion starts. Some tutorials still tell you to add third-party repositories before anything else. Others assume a CentOS-style layout that does not match Fedora. A few skip SELinux entirely, which is how a working PHP install ends up serving a blank page or a 503 error.
The good news is that Fedora makes the basic job easy. The distribution’s own repositories already carry a current PHP branch, so you do not need extra repos for a typical install. Fedora 45 ships PHP 8.5 as the default php package, and Remi’s repository lists PHP 8.5.11 for Fedora 45.
The harder part comes after the install. Which SAPI do you want: mod_php, PHP-FPM or plain CLI? Which extensions does your application need? Why does the socket permission fail after a reboot? How do you stop a traffic spike from eating all your RAM?
This guide covers the full path. It starts with a clean install and continues through web server integration, extensions, SELinux, firewall rules, performance tuning and troubleshooting. The commands target Fedora 45 with DNF5. Where Ubuntu, Debian or AlmaLinux differ, the differences are called out so the knowledge carries over.
What You Need Before Starting
A few basics save time later.
- A Fedora 45 system (Workstation, Server or a cloud image) with a user that has
sudorights. - Network access to the Fedora mirrors.
- A rough idea of the workload: a WordPress site, a Laravel app, a legacy script or just a CLI tool.
- About 10 minutes for the install and 30 for proper tuning.
First, confirm what you are running and bring the system up to date:
cat /etc/fedora-release
sudo dnf upgrade --refresh
Fedora 45 uses DNF5 as its package manager front end. The syntax most people know from DNF4 still works for the common commands (install, remove, search, info), so muscle memory carries over. Module handling is the notable exception, and that matters later when third-party PHP streams come up.
A reboot after a large upgrade is worth the minute it takes, especially if the kernel or glibc changed.
Check What Fedora Offers by Default
Before installing anything, look at what the repositories provide:
dnf info php
dnf search php- | head -50
On Fedora 45 the default branch is PHP 8.5, and the package page in the stock repo currently shows an 8.5.x build. The 8.5 branch has security support through the end of 2029, so for most new projects there is no pressure to look elsewhere.
That matters for planning. Fedora is a fast-moving distribution with a release roughly every six months, and Fedora 45 itself is supported until late 2027. Running a production site on Fedora means you will upgrade the OS more often than on AlmaLinux or Debian stable. PHP versions will move with it. Applications need to be tested against that rhythm.
Method 1: Install PHP From Fedora’s Own Repositories
This is the path most administrators should take. It is signed, maintained by Fedora packagers and integrates with SELinux policy out of the box.
Install the CLI only
If PHP is needed for scripts, cron jobs, Composer or tooling, install only the command line pieces:
sudo dnf install php-cli
php -v
Expect output beginning with PHP 8.5. followed by a patch number. The CLI package pulls in php-common and the core libraries. It does not install a web server or a FastCGI manager.
Install PHP for a web server
For web workloads, install PHP-FPM along with a basic set of extensions:
sudo dnf install php php-fpm php-mysqlnd php-mbstring php-xml php-gd php-intl php-opcache php-curl php-zip
Fedora splits PHP into many small packages. That is a feature. Every extension you skip is memory you do not use and attack surface you do not expose. If a package name is rejected, run dnf search php-<name> to see whether it has been merged into another package. Recent PHP releases have folded some previously separate pieces into the core build, so a missing name does not always mean a missing feature. Verify with php -m after installation.
Verify the install
php -v
php -m | sort
php --ini
The last command is underrated. It shows which php.ini is loaded and which extra .ini files from /etc/php.d/ are being parsed. On Fedora the main file is /etc/php.ini, and each extension gets its own numbered file in /etc/php.d/. If a setting does not seem to apply, this is the first place to check.
Choosing Between mod_php, PHP-FPM and CLI
This decision shapes everything that follows, so it deserves a proper look.
| SAPI | Best for | Trade-off |
|---|---|---|
| PHP-FPM | Nearly all production web workloads | Needs a socket or port and a pool config |
| mod_php (Apache) | Legacy setups, quick lab tests | Ties PHP to Apache’s prefork model; heavier per-process memory |
| CLI | Cron, queue workers, Composer, scripts | Not a web server interface |
In practice, PHP-FPM wins. It separates the web server from the PHP process pool, lets you set limits per site and survives web server reloads without dropping running requests. It works the same behind Apache (via proxy_fcgi) and Nginx, so the skills transfer between servers.
mod_php still has its place for a throwaway test box. It is rarely the right call for something that real users depend on.
Set Up PHP-FPM With Nginx
Nginx is the common pairing on modern servers because it handles many concurrent connections with a small memory footprint.
sudo dnf install nginx php-fpm
sudo systemctl enable --now nginx php-fpm
On Fedora the PHP-FPM package ships its own Nginx snippets. It supplies /etc/nginx/conf.d/php-fpm.conf and /etc/nginx/default.d/php.conf for the stock Nginx server. That means the default server block can run PHP with little or no editing.
Create a test file:
echo '<?php phpinfo();' | sudo tee /usr/share/nginx/html/info.php
curl -I http://localhost/info.php
You should see an HTTP/1.1 200 OK. Delete the file as soon as you finish testing. A public phpinfo() page leaks versions, paths and loaded modules, which is exactly what an attacker wants to see.
sudo rm /usr/share/nginx/html/info.php
A custom virtual host
For a real site, write your own server block. Here is a clean example for /etc/nginx/conf.d/example.conf:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 60;
}
location ~ /\.(?!well-known) {
deny all;
}
}
Test and reload:
sudo nginx -t && sudo systemctl reload nginx
The try_files line deserves a note. It is the difference between a clean front-controller setup (Laravel, Symfony, WordPress permalinks) and a pile of 404 errors. The dotfile block protects .env and .git from being served, a mistake that has leaked more database passwords than most people would like to admit.
Set Up PHP-FPM With Apache
Apache works well too, particularly when .htaccess support is needed.
sudo dnf install httpd php-fpm
sudo systemctl enable --now httpd php-fpm
Fedora’s php-fpm package drops a configuration snippet for Apache that routes .php files to the FPM socket, so in many cases no manual handler is needed. Confirm with:
ls /etc/httpd/conf.d/ | grep -i php
sudo apachectl configtest
If you prefer explicit control, add this to your virtual host:
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
Reload Apache afterward with sudo systemctl reload httpd. Make sure you are using the event MPM rather than prefork. Prefork is only needed for mod_php, and it scales poorly under concurrency.
Install Extra PHP Extensions
Applications fail in annoying ways when an extension is missing. WordPress complains about imagick, Laravel needs mbstring and xml, and a payments library might demand bcmath or gmp.
Useful packages worth knowing:
sudo dnf install php-pdo php-pgsql php-sqlite3 php-bcmath php-gmp php-soap php-ldap php-sodium php-process php-pecl-redis6 php-pecl-apcu php-pecl-imagick-im7
Not every name exists on every release, so search first when unsure:
dnf search php | grep -i redis
After installing an extension, restart PHP-FPM so the pool picks it up:
sudo systemctl restart php-fpm
A mistake seen often on servers is installing the extension and then testing with the CLI only. The CLI and FPM can read different ini files. Always test through the web path too, or compare php --ini with the output of a temporary phpinfo() page.
Method 2: Use Remi’s Repository for Other PHP Versions
Sometimes the default branch is wrong for the job. A legacy application may not be ready for PHP 8.5, or a team may standardize on 8.3 or 8.4 for a while. Remi’s RPM repository is the established answer.
Add the release package that matches your Fedora version:
sudo dnf install "https://rpms.remirepo.net/fedora/remi-release-$(rpm -E %fedora).rpm"
Remi’s documentation describes two routes. One is to replace the default PHP with another stream using the module commands. The other is to install a different version beside the default using prefixed packages such as php84. The module route looks like this:
sudo dnf module reset php
sudo dnf module enable php:remi-8.4
sudo dnf install php-cli php-fpm php-mbstring php-xml
Note that DNF5 has only partial module support on Fedora, so check the output of each command rather than assuming it worked. Remi’s own blog post for the matching release is the authority on exact stream names, and it is worth reading before touching a production host.
When two versions must coexist, the prefixed (software collection style) packages are the safer route. For example, php84-php-fpm runs from its own paths and its own service, so the system php is left alone. This is the right pattern when several sites on one server need different PHP versions. Each pool gets its own socket and each virtual host points at the right one.
The cost of third-party repos is real. Remi tracks Fedora well, but any extra repository is another party in the update chain. Keep the list short, and document why each one is there.
Configure php.ini for Real Workloads
The defaults are sane but conservative. Open /etc/php.ini, or better, create an override file so package updates never clash with your edits:
sudo nano /etc/php.d/99-custom.ini
A sensible starting point for a mid-size web application:
memory_limit = 256M
upload_max_filesize = 32M
post_max_size = 40M
max_execution_time = 60
max_input_vars = 3000
expose_php = Off
display_errors = Off
log_errors = On
error_log = /var/log/php-fpm/php_errors.log
date.timezone = Asia/Jakarta
The reasoning behind a few of these:
post_max_sizeshould be larger thanupload_max_filesize, otherwise uploads fail in confusing ways.display_errors = Offis non-negotiable in production. Errors belong in logs, not on screens visitors can read.expose_php = Offremoves the version header. It is not real security, but it avoids advertising.- Setting
date.timezoneexplicitly avoids subtle bugs in scheduled jobs and log timestamps.
Use the override-file approach even on a single server. Months later, when nobody remembers what was changed, a single file named 99-custom.ini tells the story.
Restart PHP-FPM after changes:
sudo systemctl restart php-fpm
Tune OPcache
OPcache stores precompiled PHP bytecode in shared memory. It is the single biggest performance win for most PHP sites, often cutting response time dramatically without touching application code.
In /etc/php.d/10-opcache.ini or your override file:
opcache.enable=1
opcache.memory_consumption=192
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
For deployments that use atomic releases (a new directory per release), set opcache.validate_timestamps=0 and reload PHP-FPM during each deploy. That avoids a stat call on every file and every request. The risk is forgetting the reload and wondering why old code is still running. Put the reload into the deploy script so it cannot be forgotten.
Check the real usage rather than guessing. A tiny script that calls opcache_get_status() will show hit rate and memory use. If the hit rate sits below 99% after warm-up, the cache is too small.
Tune PHP-FPM Process Management
This is where most production pain originates. The pool file is /etc/php-fpm.d/www.conf.
The key directives:
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500
pm.status_path = /fpm-status
Do not copy those numbers blindly. Work them out from real memory use. Measure the average resident memory of a worker under load:
ps -ylC php-fpm --sort:rss | awk '{sum+=$8; n++} END {print sum/n/1024 " MB avg"}'
Then divide the RAM you can spare for PHP by that average. On a 4 GB server where the database and OS take 1.5 GB, and workers average 60 MB, about 2 GB of headroom gives roughly 30 workers at the very top end. A safer figure is 20 to 25, leaving room for spikes.
Setting max_children too high is worse than setting it too low. Too low gives you a queue and slow responses. Too high pushes the box into swap or triggers the OOM killer, and then the site goes down completely.
Consider pm = ondemand for small or rarely used sites. Workers spawn when needed and exit when idle, which saves memory on a host with many low-traffic pools. For high-traffic sites, static can give the most predictable latency because there is no spawn cost, provided the memory budget is solid.
pm.max_requests recycles workers after a set number of requests. It is cheap insurance against slow memory leaks in extensions or application code.
Handle SELinux Properly
Fedora ships with SELinux enforcing. Do not disable it. Disabling is the reflexive fix and almost always unnecessary.
Check the mode:
getenforce
Common situations:
# Allow PHP to connect to a remote database or API
sudo setsebool -P httpd_can_network_connect on
sudo setsebool -P httpd_can_network_connect_db on
# Let the web server write to an upload directory
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/example/storage(/.*)?"
sudo restorecon -Rv /var/www/example/storage
If semanage is missing, install policycoreutils-python-utils. When something is blocked, the audit log tells you why:
sudo ausearch -m avc -ts recent
sudo journalctl -t setroubleshoot --since "10 minutes ago"
Reading denials takes a little practice, but it beats weakening the whole system. A site that works only with SELinux off has a configuration problem that is simply hidden.
Open the Firewall
Fedora Server and Workstation use firewalld. Allow web traffic explicitly:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
Never open the PHP-FPM port to the world. If FPM listens on TCP (for example 127.0.0.1:9000), keep it bound to localhost. A Unix socket is better for same-host setups because there is no network exposure at all, and it is slightly faster too.
File Permissions and Ownership
A reliable pattern for a typical site:
sudo chown -R deploy:nginx /var/www/example
sudo find /var/www/example -type d -exec chmod 750 {} \;
sudo find /var/www/example -type f -exec chmod 640 {} \;
sudo chmod -R 770 /var/www/example/storage
The idea is simple. A deploy user owns the code, the web server group can read it, and only specific directories (uploads, cache, logs) are writable by PHP. Never use chmod 777. It is the quickest way to turn a minor application bug into a full compromise.
If PHP-FPM runs as apache while Nginx runs as nginx, the mismatch causes socket and file permission errors. Fedora’s default pool configuration allows both users to talk to the socket through ACL settings, but custom pools need that handled by hand. Set user, group, listen.owner and listen.group deliberately for each pool.
Install Composer and Common Tooling
Most modern PHP projects depend on Composer:
sudo dnf install composer
composer --version
Run Composer as a normal user, never as root, and never inside the web root of a live site without a plan. For production deployments, use:
composer install --no-dev --optimize-autoloader
The --no-dev flag keeps test frameworks and debug tools off the server. The optimized autoloader trades a slower build for faster runtime class loading.
Handy tools for anyone managing PHP hosts:
htopandbtopfor live CPU and memory.iotopandiostat(fromsysstat) for disk I/O pressure.ss -tulpnto see what is listening.journalctl -u php-fpm -fto follow service logs.php -i | grep -i <setting>for quick config checks.ab,wrkork6for load testing before launch.
Troubleshooting Common Problems
Browser downloads the PHP file instead of running it
The web server is not passing .php files to PHP-FPM. For Nginx, check that the location ~ \.php$ block exists and that php-fpm is running. For Apache, confirm the FPM handler snippet is present. Reload the server after changes.
502 Bad Gateway (Nginx)
Nginx cannot reach PHP-FPM. Check:
sudo systemctl status php-fpm
ls -l /run/php-fpm/
sudo tail -n 50 /var/log/nginx/error.log
Usually the socket path in the Nginx config does not match the listen directive in www.conf, or the service is stopped.
503 or “Primary script unknown”
The SCRIPT_FILENAME parameter points at a path that does not exist, typically a wrong root or a missing file. Verify with ls that the file is where Nginx believes it is.
Permission denied on the socket
Look for connect() to unix:/run/php-fpm/www.sock failed (13: Permission denied). Align the pool’s listen.owner, listen.group and ACL settings with the user running the web server. Then check SELinux with ausearch -m avc.
White screen with no error
display_errors is off, as it should be. Read the log instead:
sudo tail -f /var/log/php-fpm/www-error.log
sudo tail -f /var/log/php-fpm/php_errors.log
“Class not found” or “Call to undefined function”
A missing extension. Find which package supplies it:
dnf provides '*/mbstring.so'
Install it and restart PHP-FPM.
Changes to php.ini do nothing
Three usual causes. The wrong file is being edited (php --ini shows the real one), PHP-FPM was not restarted, or another file in /etc/php.d/ loads later and overrides the value. Numbered filenames load in order, so 99-custom.ini wins over earlier files.
Database connection refused with SELinux on
If MariaDB or MySQL is remote or on another socket, run setsebool -P httpd_can_network_connect_db on. This one trips up many people moving from Debian or Ubuntu, where AppArmor is far less strict about it by default.
Workers exhausted
The FPM log says server reached pm.max_children. Resist the urge to raise the number immediately. First find out why requests are slow: a heavy query, a blocked API call, or a missing cache. Raising the limit hides the symptom and may bring the server down.