How To Install PHP on AlmaLinux 10
PHP 8.4 represents a significant advancement in web development technology, introducing groundbreaking features like property hooks, asymmetric visibility, and substantial performance improvements. For developers and system administrators running AlmaLinux 10, installing this latest PHP version unlocks enhanced capabilities while maintaining the stability and security that enterprise environments demand. AlmaLinux 10, as a Red Hat Enterprise Linux derivative, provides an excellent foundation for PHP development with its robust package management system and enterprise-grade reliability.
This comprehensive guide walks you through every aspect of installing PHP 8.4 on AlmaLinux 10, from initial system preparation to advanced configuration optimization. Whether you’re setting up a development environment or preparing a production server, you’ll find detailed instructions, troubleshooting solutions, and best practices to ensure a successful installation.
Understanding PHP 8.4 and AlmaLinux 10 Compatibility
PHP 8.4 Key Features and Improvements
PHP 8.4 introduces revolutionary features that enhance both developer productivity and application performance. Property hooks provide a more elegant way to handle getter and setter methods, while asymmetric visibility offers finer control over property access. The new version also includes significant performance optimizations, improved error handling, and enhanced type system capabilities that make PHP more robust for modern web applications.
Security enhancements in PHP 8.4 address various vulnerabilities found in previous versions, making it essential for production environments. The improved JIT compilation and optimized memory management contribute to faster execution times, particularly beneficial for high-traffic applications running on AlmaLinux 10 servers.
AlmaLinux 10 Environment Considerations
AlmaLinux 10 ships with an older PHP version in its default repositories, making third-party repositories like EPEL and REMI necessary for PHP 8.4 installation. The REMI repository specifically maintains cutting-edge PHP versions for RHEL-based distributions, ensuring compatibility and regular security updates. Understanding this ecosystem is crucial for maintaining a stable PHP 8.4 installation on AlmaLinux 10.
The modular package system in AlmaLinux 10 allows multiple PHP versions to coexist, providing flexibility for developers who need to maintain legacy applications while adopting newer PHP features. This compatibility layer ensures smooth transitions and comprehensive testing opportunities.
Prerequisites and System Preparation
System Requirements and Verification
Before beginning the PHP 8.4 installation process, ensure your AlmaLinux 10 system meets the minimum requirements. Your server should have at least 1GB of RAM, though 2GB or more is recommended for development environments. Verify your AlmaLinux 10 installation by checking the system version:
cat /etc/almalinux-release
Confirm you have root access or sudo privileges, as the installation process requires administrative permissions to modify system packages and configurations. Check your current user’s sudo access:
sudo whoami
Essential System Updates
Start by updating your AlmaLinux 10 system to ensure all packages are current and security patches are applied:
dnf update -y
This command updates all installed packages to their latest versions, resolving potential dependency conflicts that might interfere with PHP 8.4 installation. The update process also ensures compatibility with the latest repository metadata.
Check if PHP is currently installed on your system:
php -v
If PHP is already installed, note the version to understand what changes the upgrade will bring. Document any existing PHP extensions or configurations you may need to preserve or reconfigure after the PHP 8.4 installation.
Development Tools Installation
Install essential development tools and utilities that may be required during the PHP 8.4 installation process:
dnf groupinstall "Development Tools" -y
dnf install wget curl vim -y
These packages provide compilation tools, network utilities, and text editors that prove invaluable for troubleshooting and customization during the installation process.
Adding Required Repositories
Installing EPEL Repository
The Extra Packages for Enterprise Linux (EPEL) repository provides additional packages not available in the standard AlmaLinux repositories. Install EPEL using the following command:
dnf install epel-release -y
EPEL serves as a foundation for other third-party repositories and contains dependencies required by the REMI repository. Verify the EPEL installation by listing available repositories:
dnf repolist
The output should include the EPEL repository, confirming successful installation. EPEL provides essential libraries and tools that PHP 8.4 extensions depend on, making it a critical component of the installation process.
Installing REMI Repository
The REMI repository is the primary source for current PHP versions on RHEL-based distributions. Install the REMI repository for AlmaLinux 10:
dnf install -y https://rpms.remirepo.net/enterprise/remi-release-10.rpm
This command downloads and installs the REMI repository configuration, providing access to PHP 8.4 packages specifically compiled for AlmaLinux 10. The REMI repository maintains multiple PHP versions simultaneously, allowing you to choose the specific version that meets your requirements.
Verify the REMI repository installation:
dnf repolist | grep remi
You should see multiple REMI repositories listed, including remi-safe and remi-modular. These repositories contain different categories of packages, with remi-safe providing stable releases and additional repositories offering testing versions.
Repository Configuration and Optimization
Enable the remi-safe repository, which contains stable PHP packages:
dnf config-manager --set-enabled remi-safe
This step ensures access to the most stable PHP 8.4 packages while maintaining system reliability. The remi-safe repository undergoes extensive testing before package releases, making it suitable for production environments.
Update the repository metadata to reflect the newly added repositories:
dnf makecache
This command refreshes the package index, ensuring your system recognizes all available PHP 8.4 packages and their dependencies.
Installing PHP 8.4 – Primary Method
Module Stream Management
AlmaLinux 10 uses module streams to manage different versions of software packages. List available PHP modules to understand the current configuration:
dnf module list php
Reset any existing PHP module configuration to avoid conflicts:
dnf module reset php -y
This step clears previous PHP module selections, ensuring a clean installation environment for PHP 8.4. Module streams in AlmaLinux 10 provide version isolation, preventing conflicts between different PHP versions.
Enabling PHP 8.4 Module Stream
Enable the PHP 8.4 module stream from the REMI repository:
dnf module enable php:remi-8.4 -y
The system will display output confirming the module stream activation. This step configures your system to prioritize PHP 8.4 packages from the REMI repository over older versions in default repositories.
Expected output should resemble:
Dependencies resolved.
================================================================================
Package Architecture Version Repository
================================================================================
Enabling module streams:
php remi-8.4
Transaction Summary
================================================================================
Complete!
PHP 8.4 Installation Process
Install PHP 8.4 and essential extensions:
dnf install -y php php-cli php-common php-fpm php-mysqlnd php-opcache php-xml php-mbstring php-curl php-gd php-json
This command installs the core PHP 8.4 runtime along with commonly required extensions for web development. The installation process automatically resolves dependencies and configures the PHP environment.
Monitor the installation output for any error messages or warnings. The process typically takes several minutes depending on your internet connection and system performance.
Installation Verification
Verify the PHP 8.4 installation by checking the version:
php -v
Expected output:
PHP 8.4.7 (cli) (built: May 6 2025 12:31:58) (NTS gcc x86_64)
Copyright (c) The PHP Group
Confirm PHP modules are properly loaded:
php -m
This command lists all installed PHP modules, helping you verify that essential extensions are available and functioning correctly.
Alternative Installation Methods
Software Collections (SCL) Installation
For environments requiring multiple PHP versions, consider the Software Collections approach:
dnf install php84
This method installs PHP 8.4 in an isolated environment under /opt/remi/php84
, allowing coexistence with other PHP versions. The SCL installation provides version-specific binaries like php84
instead of the system-wide php
command.
Access PHP 8.4 through the SCL environment:
php84 --version
The SCL approach offers maximum flexibility for development environments where multiple PHP versions are required for testing compatibility across different application requirements.
Direct Module Installation Method
Alternatively, you can install PHP 8.4 as the system default by enabling the module first:
dnf module enable php:remi-8.4
dnf install php
This approach replaces any existing PHP installation with PHP 8.4, making it the system default. Choose this method when you want PHP 8.4 as the primary PHP interpreter without version isolation.
Consider the implications of replacing existing PHP installations, particularly in production environments where existing applications may require specific PHP versions or configurations.
Essential PHP Extensions Installation
Database and Core Extensions
Install database connectivity extensions essential for web applications:
dnf install -y php-mysqlnd php-pgsql php-sqlite3 php-pdo
These extensions provide connectivity to MySQL/MariaDB, PostgreSQL, and SQLite databases, covering the most common database scenarios in web development. The mysqlnd extension offers improved performance and memory efficiency compared to legacy MySQL extensions.
Web Development Extensions
Install extensions commonly required for modern web development:
dnf install -y php-zip php-curl php-gd php-intl php-soap php-xmlrpc
These extensions support file compression, HTTP client functionality, image processing, internationalization, SOAP services, and XML-RPC communication. Modern web applications frequently depend on these capabilities for integrating with external services and processing various data formats.
Performance and Security Extensions
Install performance and security-focused extensions:
dnf install -y php-opcache php-sodium php-redis php-memcached
OPcache dramatically improves PHP performance by caching compiled bytecode in memory. The sodium extension provides modern cryptographic functions, while Redis and Memcached extensions enable high-performance caching solutions.
Verify installed extensions:
php -m | grep -E "(opcache|sodium|redis)"
Configuration and Optimization
PHP Configuration Files
PHP 8.4 configuration files are located in /etc/php.ini
for the main installation or /etc/opt/remi/php84/
for SCL installations. The primary configuration file contains settings that affect PHP’s behavior, performance, and security.
Key configuration parameters to review include:
memory_limit
: Set appropriate memory limits based on your application requirementsmax_execution_time
: Configure script execution timeoutsupload_max_filesize
andpost_max_size
: Set file upload limitserror_reporting
: Configure error reporting for development vs. production
Security Configuration
Enhance PHP security by modifying critical settings in php.ini:
nano /etc/php.ini
Disable dangerous functions:
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
Configure error reporting for production:
display_errors = Off
log_errors = On
error_log = /var/log/php_errors.log
Set secure session configuration:
session.cookie_httponly = 1
session.cookie_secure = 1
session.use_strict_mode = 1
PHP-FPM Configuration
Configure PHP-FPM for optimal performance with web servers:
nano /etc/php-fpm.d/www.conf
Adjust process management settings:
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35
Start and enable PHP-FPM service:
systemctl start php-fpm
systemctl enable php-fpm
Web Server Integration
Apache HTTP Server Configuration
Install and configure Apache to work with PHP 8.4:
dnf install httpd -y
systemctl start httpd
systemctl enable httpd
Configure Apache to process PHP files by ensuring the PHP module is loaded. The installation should automatically configure this, but verify by checking Apache’s configuration:
httpd -M | grep php
Nginx Configuration
For Nginx users, configure FastCGI processing:
dnf install nginx -y
Add PHP processing to your Nginx server block:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Restart Nginx to apply the configuration:
systemctl restart nginx
Troubleshooting Common Issues
Repository Access Problems
If you encounter issues accessing repositories, verify your internet connection and repository configurations:
dnf clean all
dnf makecache
Check repository status:
dnf repolist enabled
Ensure firewall rules don’t block repository access. Temporarily disable the firewall for testing:
systemctl stop firewalld
Module Dependency Conflicts
Resolve module conflicts by resetting conflicting modules:
dnf module reset php httpd -y
If you encounter specific dependency errors, use the --allowerasing
flag:
dnf install php --allowerasing
Extension Loading Issues
If extensions fail to load, check PHP configuration:
php --ini
Verify extension files exist in the correct directory:
ls -la /usr/lib64/php/modules/
Check for configuration errors:
php -m 2>&1 | grep -i error
Permission and SELinux Issues
Address SELinux-related problems by checking context:
ls -laZ /var/www/html/
Set appropriate SELinux contexts for web content:
setsebool -P httpd_execmem 1
setsebool -P httpd_can_network_connect 1
Testing and Verification
Command Line Testing
Create a simple PHP script to test functionality:
echo '<?php phpinfo(); ?>' > /tmp/test.php
php /tmp/test.php
Test database connectivity with a sample script:
<?php
try {
$pdo = new PDO('mysql:host=localhost', 'username', 'password');
echo "Database connection successful\n";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage() . "\n";
}
?>
Web Interface Testing
Create a PHP info page in your web server’s document root:
echo '<?php phpinfo(); ?>' > /var/www/html/info.php
Access the page through your web browser:
http://your-server-ip/info.php
The PHP info page displays comprehensive information about your PHP 8.4 installation, including loaded extensions, configuration settings, and system information.
Performance Benchmarking
Test PHP 8.4 performance with a simple benchmark script:
<?php
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
$array[] = md5($i);
}
$end = microtime(true);
echo "Execution time: " . ($end - $start) . " seconds\n";
?>
Best Practices and Maintenance
Security Hardening
Implement comprehensive security measures:
- Regular security updates:
dnf update php* -y
- Monitor security advisories from PHP and REMI repositories
- Implement proper file permissions:
chmod 644
for PHP files,chmod 755
for directories - Use HTTPS for all web communications
- Regularly audit and update PHP extensions
Performance Optimization
Optimize PHP 8.4 for production environments:
Configure OPcache for maximum performance:
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
Monitor PHP-FPM status:
systemctl status php-fpm
Implement log rotation for PHP error logs:
logrotate /etc/logrotate.d/php
Monitoring and Maintenance
Establish monitoring procedures:
- Monitor PHP error logs:
tail -f /var/log/php_errors.log
- Track PHP-FPM performance: Monitor pool statistics
- Set up automated backups of PHP configurations
- Schedule regular security updates
Configure system monitoring tools to track PHP performance metrics, memory usage, and response times. This proactive approach helps identify potential issues before they impact production applications.
Congratulations! You have successfully installed PHP. Thanks for using this tutorial for installing PHP 8.4 on your AlmaLinux OS 10 system. For additional help or useful information, we recommend you check the official PHP website.