How to Install PHP on Fedora

This guide walks you through installing PHP on Fedora Linux using the official repositories. By the end, you will have a working PHP installation ready for web development, command-line scripting, or powering frameworks like Laravel and WordPress. Both Fedora 43 (current stable) and Fedora 42 (old stable) provide PHP 8.4, the current stable PHP release.

PHP remains the foundation of countless web applications, from simple contact forms to complex content management systems. Whether you are setting up a local development environment or preparing a production server, Fedora’s official repositories provide a tested PHP distribution that integrates smoothly with Apache or Nginx.

Understand PHP Installation on Fedora

Fedora uses PHP-FPM (FastCGI Process Manager) as the default PHP handler for both Apache and Nginx. Unlike older distributions that ran PHP as an Apache module (mod_php), Fedora routes all PHP requests through PHP-FPM regardless of which web server you choose. This approach provides better process isolation and consistent behavior across web servers.

The main difference between installing PHP for Apache versus Nginx lies in the dependencies and configuration files each package installs:

Web ServerPHP PackageWhat It ConfiguresBest For
Apache (httpd)phpInstalls Apache dependency, adds PHP-FPM proxy configurationTraditional LAMP stacks, cPanel-style hosting
Nginxphp-fpmInstalls PHP-FPM only, manual Nginx configuration requiredHigh-traffic sites, containerized deployments

For most users, the Apache method is simpler because the php package automatically installs Apache and configures it to proxy PHP requests to PHP-FPM. If you plan to use Nginx, install php-fpm directly and follow our guide to configure Nginx for PHP-FPM on Fedora.

Update Fedora Before Installation

First, update your system to ensure all packages are current. This step prevents dependency conflicts and ensures you install the latest PHP version available in the repositories:

sudo dnf upgrade --refresh

The --refresh flag forces DNF to download fresh repository metadata, which is especially important if your system has been idle for several days.

Install PHP on Fedora

Fedora ships PHP 8.4 in the official repositories. Choose the installation command that matches your web server.

Install PHP for Apache

If you are using Apache (httpd) or setting up a traditional LAMP stack, install the main PHP package along with the CLI tools:

sudo dnf install php php-cli -y

This command installs PHP with the PHP-FPM service, the command-line interpreter, and several commonly-used extensions as weak dependencies. As a result, DNF automatically pulls in Apache (httpd) and configures it to route .php files to PHP-FPM through the proxy configuration at /etc/httpd/conf.d/php.conf.

Install PHP-FPM for Nginx

Alternatively, if you plan to use Nginx or prefer a minimal installation without Apache, install PHP-FPM directly:

sudo dnf install php-fpm php-cli -y

PHP-FPM (FastCGI Process Manager) handles PHP requests independently from the web server. Nginx passes requests to PHP-FPM through a Unix socket at /run/php-fpm/www.sock, which provides better process isolation and allows fine-tuned resource management. For complete Nginx setup instructions, see our guide to configure Nginx for PHP-FPM on Fedora.

Verify PHP Installation

Once installation completes, confirm that PHP is accessible from the command line by checking the version:

php -v

Expected output:

PHP 8.4.16 (cli) (built: Dec 16 2025 16:03:34) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Fedora Project
Zend Engine v4.4.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies

This output confirms you are running PHP 8.4 from the Fedora repositories. Additionally, the Zend OPcache extension loads by default, caching compiled PHP scripts in memory for faster execution on subsequent requests.

Start and Enable PHP-FPM

Since Fedora uses PHP-FPM for all web server configurations, you need to start and enable the PHP-FPM service. This applies whether you chose the Apache or Nginx method:

sudo systemctl enable php-fpm --now

The --now flag starts the service immediately while also enabling it for future boots. Next, verify the service is running:

systemctl status php-fpm

Expected output (abbreviated):

● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-12-25 12:00:00 UTC; 5s ago
   Main PID: 12345 (php-fpm)
      Tasks: 6 (limit: 4096)
     Memory: 16.0M
        CPU: 52ms
     CGroup: /system.slice/php-fpm.service
             ├─12345 "php-fpm: master process (/etc/php-fpm.conf)"
             └─12346 "php-fpm: pool www"

Finally, if you installed PHP for Apache, also start the Apache service:

sudo systemctl enable httpd --now

Install Common PHP Extensions

Most web applications require additional PHP extensions beyond the base installation. While the extensions you need depend on your specific use case, the following are commonly required for popular frameworks and CMS platforms like WordPress, Laravel, and Drupal:

sudo dnf install php-gd php-mysqlnd php-pgsql php-intl php-bcmath php-soap php-process php-ldap php-tidy php-snmp -y

These extensions provide the following functionality:

ExtensionPurpose
php-gdImage manipulation (thumbnails, watermarks, captchas)
php-mysqlndMySQL and MariaDB database connectivity (native driver)
php-pgsqlPostgreSQL database connectivity
php-intlInternationalization (date/time formatting, collation)
php-bcmathArbitrary precision mathematics
php-soapSOAP web services client and server
php-processProcess control functions (pcntl, posix)
php-ldapLDAP directory access
php-tidyHTML cleanup and repair
php-snmpSNMP protocol support for network monitoring

After installing new extensions, restart PHP-FPM to load them:

sudo systemctl restart php-fpm

Install PECL Extensions

In addition to the standard extensions, some popular extensions come from the PHP Extension Community Library (PECL) and have different package names in Fedora. For caching, image processing, and in-memory data stores, install:

sudo dnf install php-pecl-apcu php-pecl-redis6 php-pecl-memcached php-pecl-imagick -y

These PECL extensions provide:

  • php-pecl-apcu: User cache for storing data between requests (successor to APC)
  • php-pecl-redis6: Redis client for session storage and object caching
  • php-pecl-memcached: Memcached client for distributed caching
  • php-pecl-imagick: ImageMagick bindings for advanced image manipulation

JSON support is built into PHP 8.0 and later. You do not need to install a separate php-json package.

After installing these extensions, restart PHP-FPM and verify they are loaded:

sudo systemctl restart php-fpm
php -m | grep -iE 'apcu|redis|memcached|imagick'

Expected output:

apcu
imagick
memcached
redis

View All Loaded PHP Modules

To see which extensions are currently enabled, run:

php -m

This lists all compiled-in and dynamically loaded modules. After installing the extensions above, you should see entries for gd, mysqli, pdo_mysql, intl, redis, memcached, imagick, and others.

Install PHP Development Tools

For development work, if you are building PHP extensions from source or need debugging capabilities, install the development package along with debugging tools:

sudo dnf install php-devel php-pecl-xdebug3 php-pecl-pcov -y

The php-devel package includes header files and development libraries needed to compile PECL extensions. In addition, Xdebug provides step-through debugging, stack traces, and profiling capabilities for IDEs like VS Code and PhpStorm. Meanwhile, PCOV is a lightweight code coverage driver that runs faster than Xdebug when you only need coverage analysis.

Do not enable Xdebug on production servers. It significantly impacts performance and is intended for development environments only. PCOV is faster for code coverage but should also be disabled in production.

Test PHP with Your Web Server

To verify that PHP is working correctly with your web server, create a simple test file. For Apache installations, the default document root is /var/www/html:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Then open http://localhost/info.php or http://your-server-ip/info.php in your browser. You should see the PHP information page displaying your PHP version, loaded extensions, and configuration settings.

Remove the info.php file immediately after testing. The phpinfo() output reveals detailed server configuration that attackers can use to find vulnerabilities. Delete it with sudo rm /var/www/html/info.php.

Configure PHP Settings

PHP configuration is stored in /etc/php.ini. Common settings you may need to adjust for production or development workloads include:

sudo nano /etc/php.ini

Key directives to review:

  • memory_limit: Maximum memory per script (default 128M, increase for large applications)
  • upload_max_filesize: Maximum file upload size (default 2M, increase for media-heavy sites)
  • post_max_size: Maximum POST data size (must exceed upload_max_filesize)
  • max_execution_time: Maximum script execution time in seconds (default 30)
  • date.timezone: Your server timezone (for example, America/New_York or Europe/London)

Individual extension configurations are stored in /etc/php.d/. Each extension has its own .ini file, such as 20-gd.ini or 10-opcache.ini.

After modifying configuration files, restart PHP-FPM to apply changes:

sudo systemctl restart php-fpm

If you are using Apache, also restart Apache to ensure it picks up any changes:

sudo systemctl restart httpd

Troubleshooting PHP Installation

PHP Scripts Display as Plain Text or Download

If your browser shows raw PHP code or prompts you to download the file instead of executing it, the web server is not routing PHP requests to PHP-FPM. First, verify that PHP-FPM is running:

systemctl status php-fpm

The service should show active (running). Otherwise, start it:

sudo systemctl start php-fpm

Additionally, for Apache users, verify the PHP configuration file exists and is properly loaded:

ls -la /etc/httpd/conf.d/php.conf

If the file is missing, reinstall PHP and restart both services:

sudo dnf reinstall php
sudo systemctl restart php-fpm httpd

PHP-FPM Returns 502 Bad Gateway

A 502 Bad Gateway error typically means the web server cannot connect to PHP-FPM. To diagnose this, check whether the PHP-FPM socket exists:

ls -la /run/php-fpm/www.sock

If the socket is missing, then PHP-FPM may not be running. Check for errors in the journal:

sudo journalctl -xeu php-fpm | tail -30

Common causes include permission problems or configuration syntax errors. Once you have fixed the issue, restart PHP-FPM:

sudo systemctl restart php-fpm

Extension Not Loading

If an extension is installed but not appearing in php -m output, check that its configuration file exists in /etc/php.d/:

ls /etc/php.d/

Each extension should have a corresponding .ini file. However, if the file exists but the extension still does not load, check for PHP errors during initialization:

php -i 2>&1 | head -30

This command displays any warnings or errors during PHP startup. Missing dependencies or version mismatches will appear here.

Remove PHP from Fedora

If you need to remove PHP completely, first stop the services, then uninstall the packages:

sudo systemctl stop php-fpm
sudo dnf remove php php-cli php-common php-fpm -y

Next, remove orphaned dependencies that are no longer needed:

sudo dnf autoremove -y

Finally, verify PHP has been removed:

php -v

Expected output:

bash: php: command not found

Removing PHP does not delete your application files or PHP configurations. Configuration files remain in /etc/php.ini and /etc/php.d/ unless you manually remove them. This allows you to reinstall PHP later without losing your settings.

Conclusion

You now have PHP installed and configured on Fedora Linux using the official repositories. Your system has PHP 8.4 with PHP-FPM handling requests for both Apache and Nginx, along with the extensions needed for most web applications. After verifying the test page works, remember to remove it and configure your application-specific settings in /etc/php.ini.

Going forward, Fedora’s PHP packages receive regular security updates through the standard system update process. Run sudo dnf upgrade periodically to install the latest patches. For production deployments, consider tuning PHP-FPM’s pool settings in /etc/php-fpm.d/www.conf to match your server’s resources and expected traffic.

Leave a Comment

Let us know you are human: