FedoraRHEL Based

How To Install PHP on Fedora 43

Install PHP on Fedora 43

PHP represents a significant milestone in the evolution of one of the world’s most popular server-side scripting languages. Released with powerful new features and performance improvements, this latest version brings property hooks, asymmetric visibility, and enhanced HTML5 support to Fedora 43 users. Whether you’re a seasoned system administrator managing production servers or a developer setting up a local development environment, upgrading to PHP 8.4 on Fedora 43 ensures you have access to the latest language features, security patches, and performance optimizations. This comprehensive guide walks you through multiple installation methods, configuration best practices, and troubleshooting techniques to get PHP 8.4 running smoothly on your Fedora 43 system.

Understanding PHP 8.4

What’s New in PHP 8.4

PHP 8.4 introduces several groundbreaking features that enhance developer productivity and code quality. Property hooks allow developers to define custom get and set operations directly within property declarations, providing better encapsulation without the need for explicit getter and setter methods. Asymmetric visibility support enables properties to have different visibility levels for reading and writing, offering more granular access control.

The new array functions—array_find, array_find_key, array_any, and array_all—simplify common array operations and reduce the need for verbose foreach loops. HTML5 DOM support improvements modernize PHP’s document parsing capabilities, making it easier to work with contemporary web markup. Additionally, PDO now features driver-specific subclasses, providing better type safety and IDE autocompletion. Developers can also chain methods on newly instantiated objects without parentheses, resulting in cleaner, more readable code.

System Requirements

Before installing PHP 8.4 on Fedora 43, ensure your system meets the necessary requirements. Fedora 43 provides native support for PHP 8.4 through its official repositories, making the installation process straightforward. Your system should have at least 512MB of RAM for basic PHP operations, though 1GB or more is recommended for production environments. A 64-bit processor architecture is standard for Fedora 43, and you’ll need approximately 100-200MB of disk space for PHP and commonly used extensions.

Prerequisites Before Installation

Root or sudo privileges are essential for installing system packages on Fedora 43. If you’re working on a system with an existing PHP installation, it’s crucial to back up your current configuration files before proceeding. Configuration files are typically located in /etc/php.ini and /etc/php-fpm.d/ directories.

Check your current PHP version by running php -v in the terminal. This helps you understand what version you’re upgrading from and plan for any compatibility issues. Before installing new packages, update your system to ensure all existing packages are current. This prevents potential conflicts and ensures you’re working with the latest package metadata.

Understanding the difference between system-wide PHP installations and parallel installations is important. System-wide installations replace the existing PHP version, while parallel installations allow multiple versions to coexist. Choose the approach that best fits your development or production needs.

Method 1: Installing PHP 8.4 from Default Fedora Repositories

Step 1: Update System Packages

Begin by refreshing your system’s package cache and updating all installed packages. Open your terminal and execute:

sudo dnf upgrade --refresh

This command downloads the latest package metadata and upgrades all installed packages to their newest versions. System updates are crucial before installing new software because they ensure compatibility with the latest libraries and dependencies. The upgrade process may take several minutes depending on your internet connection and the number of packages requiring updates. Once complete, you can verify the update was successful by checking for any error messages in the terminal output.

Step 2: Install PHP 8.4 Core Package

Installing PHP 8.4 from Fedora’s default repositories is the simplest method. Execute the following command:

sudo dnf install php

This command installs the core PHP package along with essential dependencies. The default repository method offers several advantages: official support from Fedora maintainers, seamless integration with system updates, and automatic security patches. The core package includes the PHP command-line interface (CLI), which allows you to run PHP scripts directly from the terminal.

Step 3: Verify PHP Installation

After installation completes, verify that PHP 8.4 is correctly installed and accessible:

php -v

The output should display PHP 8.4 along with version details and copyright information. If you encounter errors such as “command not found,” the installation may have failed, or the PHP binary might not be in your system PATH. Check /var/log/dnf.log for installation errors and ensure the installation completed without issues.

Step 4: Install Essential PHP Extensions

PHP extensions provide additional functionality for database connectivity, image processing, and other common tasks. For Apache web server users, install the following packages:

sudo dnf install php php-cli php-common

Nginx users should install PHP-FPM (FastCGI Process Manager) instead:

sudo dnf install php-fpm php-cli

PHP-FPM is the preferred method for running PHP with Nginx, offering better performance and resource management compared to traditional CGI implementations.

Method 2: Installing PHP 8.4 Using Remi Repository

Understanding Remi Repository

Remi’s RPM repository is a trusted third-party source for PHP packages on Red Hat-based distributions, including Fedora. Maintained by Remi Collet, a PHP package maintainer and Fedora contributor, this repository often provides newer PHP versions and updates faster than official repositories. Many system administrators prefer Remi’s repository because it offers multiple PHP versions simultaneously, comprehensive extension availability, and frequent security updates.

Step 1: Add Remi Repository to Fedora 43

Install the Remi repository configuration package:

sudo dnf install https://rpms.remirepo.net/fedora/remi-release-43.rpm

This command downloads and installs the repository configuration file along with the necessary GPG keys for package verification. The GPG keys ensure package authenticity and protect against tampered packages. After installation, the repository configuration files are located in /etc/yum.repos.d/, where you can view or modify repository settings if needed.

Step 2: List Available PHP Modules

Fedora uses a modular repository system that allows multiple versions of the same software to coexist. View available PHP modules:

sudo dnf module list php

This command displays all available PHP module streams, including those from Remi’s repository. The output shows which versions are available, which is currently enabled, and which is installed. Understanding module streams is essential for managing PHP versions on Fedora effectively.

Step 3: Reset and Enable PHP Module

If you have a previous PHP module enabled, reset it first:

sudo dnf module reset php

Then enable the PHP 8.4 module from Remi’s repository:

sudo dnf module enable php:remi-8.4

Module switching allows you to change between PHP versions without completely removing and reinstalling packages. After enabling the desired module stream, all subsequent PHP package installations will use this version.

Step 4: Install PHP 8.4 Packages

Now install PHP 8.4 and your required extensions:

sudo dnf install php php-cli php-fpm

Update your system to ensure all PHP packages are synchronized:

sudo dnf update

Verify the installation by checking the PHP version. The Remi repository method provides access to a comprehensive collection of PHP extensions and receives updates promptly after new PHP releases.

Method 3: Parallel Installation as Software Collection

When to Use Parallel Installation

Parallel installations are ideal when you need multiple PHP versions running simultaneously on the same system. This approach benefits developers testing applications across different PHP versions, hosting providers serving multiple clients with varying requirements, and production environments requiring gradual migration strategies.

Installing PHP 8.4 as SCL

Install PHP 8.4 as a Software Collection:

sudo dnf install php84

Software Collections install to isolated directories, preventing conflicts with system PHP. PHP 8.4 SCL installs to /opt/remi/php84, with configuration files in /etc/opt/remi/php84. This isolation allows the system PHP and PHP 8.4 to operate independently without interfering with each other.

Working with PHP 8.4 SCL

To invoke PHP 8.4 specifically, use the full path:

/opt/remi/php84/root/usr/bin/php -v

The PHP-FPM service for PHP 8.4 SCL is named php84-php-fpm. Start and enable it:

sudo systemctl enable php84-php-fpm
sudo systemctl start php84-php-fpm

The FPM socket is located at /var/opt/remi/php84/run/php-fpm/www.sock, which you’ll reference in your web server configuration.

Installing Essential PHP Extensions

Most Common Extensions Package

Install a comprehensive set of commonly needed extensions:

sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-xml php-dom php-mbstring php-json

These extensions provide critical functionality. The CLI extension enables command-line script execution, FPM provides FastCGI process management, cURL handles HTTP requests, mysqlnd offers MySQL database connectivity, GD processes images, OPcache improves performance through bytecode caching, ZIP manages compressed archives, Intl supports internationalization, and XML/DOM handle XML parsing.

Database Extensions

Different database systems require specific PHP extensions. For MySQL or MariaDB:

sudo dnf install php-mysqlnd

PostgreSQL users need:

sudo dnf install php-pgsql

SQLite support is often included in the core PHP package but can be explicitly installed if needed. The mysqlnd driver offers better performance and memory usage compared to the older libmysql driver.

Development and Debugging Tools

Developers benefit from additional tools for debugging and profiling. Install the development package:

sudo dnf install php-devel

Xdebug is invaluable for debugging PHP applications:

sudo dnf install php-xdebug

For code coverage analysis:

sudo dnf install php-pcov

These tools integrate with IDEs like PHPStorm and VS Code, enabling breakpoints, variable inspection, and performance profiling.

Viewing Installed Extensions

List all loaded PHP modules:

php -m

This command displays both Zend extensions and standard PHP extensions. Review this list to ensure required extensions are loaded and identify any unnecessary extensions that might impact performance. Remember that each loaded extension consumes memory and potentially affects PHP startup time.

Configuring PHP 8.4

Locating Configuration Files

The main PHP configuration file for CLI operations is typically located at /etc/php.ini. PHP-FPM uses the same php.ini but may have additional FPM-specific configuration in /etc/php-fpm.conf and pool configurations in /etc/php-fpm.d/. Understanding this hierarchy is essential because settings in pool configurations override main FPM settings, which override php.ini settings.

Essential Configuration Settings

Edit the main configuration file:

sudo nano /etc/php.ini

Adjust the memory limit based on your application requirements:

memory_limit = 256M

Increase upload file size limits for applications handling file uploads:

upload_max_filesize = 64M
post_max_size = 64M

Set appropriate execution time limits:

max_execution_time = 300

Configure error reporting for development or production environments. Development environments should display errors, while production environments should log them without displaying to users.

Security Best Practices

Disable dangerous functions that could compromise security:

disable_functions = exec,passthru,shell_exec,system,proc_open,popen

Set appropriate file permissions on PHP configuration files to prevent unauthorized access. Restrict PHP’s file access using open_basedir:

open_basedir = /var/www/html:/tmp

This prevents PHP scripts from accessing files outside specified directories.

Configuring PHP-FPM

Understanding PHP-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with advanced process management features. It offers adaptive process spawning, emergency restart mechanisms, and detailed logging capabilities, making it ideal for high-traffic websites and production environments.

Basic FPM Configuration

Pool configuration files are located in /etc/php-fpm.d/. The default pool configuration is typically www.conf. Edit this file:

sudo nano /etc/php-fpm.d/www.conf

Configure the user and group PHP-FPM runs as:

user = nginx
group = nginx

The listen directive determines how PHP-FPM accepts connections. For Unix socket (recommended for single-server setups):

listen = /run/php-fpm/www.sock

For TCP socket (useful for distributed setups):

listen = 127.0.0.1:9000

Starting and Managing PHP-FPM Service

Enable PHP-FPM to start automatically at boot:

sudo systemctl enable php-fpm

Start the service:

sudo systemctl start php-fpm

Check service status:

sudo systemctl status php-fpm

After making configuration changes, restart PHP-FPM:

sudo systemctl restart php-fpm

Always verify the service started successfully by checking the status output for any error messages.

Web Server Integration

Apache Integration

Apache can integrate with PHP through mod_php or PHP-FPM. Install mod_php for Apache:

sudo dnf install php

Apache automatically configures itself to use PHP when the package is installed. Restart Apache after installation:

sudo systemctl restart httpd

For better performance and isolation, configure Apache to use PHP-FPM instead, requiring additional Apache configuration directives.

Nginx Integration

Nginx requires PHP-FPM since it doesn’t support embedded PHP modules. Configure Nginx to pass PHP requests to PHP-FPM. Edit your Nginx server block configuration:

sudo nano /etc/nginx/conf.d/default.conf

Add the PHP location block:

location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

This configuration passes all .php file requests to PHP-FPM through the Unix socket. TCP connections use fastcgi_pass 127.0.0.1:9000; instead. Restart Nginx after configuration changes:

sudo systemctl restart nginx

Testing PHP Installation

Command Line Testing

Verify PHP version from the command line:

php -v

The output confirms PHP 8.4 is installed and accessible. Test PHP script execution:

php -r "echo 'PHP is working!';"

List all loaded extensions to verify they’re available:

php -m

These tests confirm PHP works correctly from the command line.

Creating phpinfo() Test File

Create a test file in your web root directory:

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

Access this file through your web browser at http://your-server-ip/info.php. The phpinfo() page displays comprehensive information about your PHP installation, including version, configuration settings, loaded extensions, and environment variables.

Security note: The phpinfo() output reveals detailed system information. Remove this test file after verification:

sudo rm /var/www/html/info.php

Never leave phpinfo() files accessible on production servers as they expose sensitive configuration details.

Troubleshooting Common Issues

Installation Problems

Repository GPG key issues can prevent package installation. If you encounter GPG errors, manually import the repository key. Module conflicts occur when multiple PHP module streams are enabled simultaneously. Use dnf module reset php to clear the current module selection before enabling a different stream.

Dependency errors typically indicate missing required packages. The DNF package manager usually resolves dependencies automatically, but occasionally manual intervention is necessary. Review error messages carefully and install any missing dependencies.

Configuration Issues

Permission denied errors when accessing PHP-FPM sockets indicate incorrect ownership or permissions. Ensure the web server user has read/write access to the socket file. Verify the socket file exists and check the listen directive in your PHP-FPM pool configuration.

Extension loading failures happen when an extension’s dependencies aren’t met or the extension file doesn’t exist. Check /var/log/php-fpm/error.log for detailed error messages. Verify extension files exist in /usr/lib64/php/modules/ and configuration files in /etc/php.d/.

Performance Issues

Too many loaded extensions impact PHP startup time and memory usage. Audit your loaded extensions and disable any that aren’t actively used. Memory limit problems manifest as “Allowed memory size exhausted” errors. Increase the memory_limit setting in php.ini to resolve these issues.

Optimization recommendations include enabling OPcache for bytecode caching, which significantly improves performance by eliminating the need to parse and compile PHP scripts on every request. Configure realpath caching to reduce filesystem overhead for file path resolution.

Upgrading from Previous PHP Versions

Preparation Steps

Before upgrading, back up your current PHP configuration files:

sudo cp -r /etc/php.ini /etc/php.ini.backup
sudo cp -r /etc/php-fpm.d /etc/php-fpm.d.backup

Document all installed extensions:

php -m > installed_extensions.txt

This list helps ensure you reinstall necessary extensions after upgrading. Test your applications in a development environment with PHP 8.4 before upgrading production systems to identify compatibility issues.

Migration Considerations

PHP 8.4 deprecates certain features and introduces breaking changes that may affect existing code. Review the official PHP 8.4 migration guide to understand deprecated functions and changed behaviors. Update your application code to address deprecated features and leverage new PHP 8.4 capabilities like property hooks and asymmetric visibility.

Best Practices and Recommendations

Maintenance Tips

Keep PHP regularly updated to receive security patches and bug fixes. Enable automatic security updates on Fedora:

sudo dnf install dnf-automatic

Monitor PHP error logs at /var/log/php-fpm/error.log for application errors and warnings. Implement performance monitoring using tools like New Relic or custom monitoring scripts to track PHP-FPM resource usage and response times.

Security Hardening

Maintaining an up-to-date PHP installation is the foundation of security. Subscribe to PHP security advisories and Fedora security announcements to stay informed about vulnerabilities. Remove unnecessary extensions to reduce attack surface—every extension represents potential security vulnerabilities. Regular security audits of your PHP configuration and application code help identify and address security weaknesses before they’re exploited.

Congratulations! You have successfully installed PHP. Thanks for using this tutorial for installing the PHP popular general-purpose scripting language on Fedora 43 Linux system. For additional Apache or useful information, we recommend you check the official PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button