Table of Contents#
- Prerequisites
- Step 1: Update Your System
- Step 2: Enable EPEL Repository
- Step 3: Enable Remi Repository
- Step 4: Install PHP 8.0
- Step 5: Install PHP Extensions
- Step 6: Verify PHP Installation
- Step 7: Configure PHP (Optional)
- Step 8: Test PHP with a Web Server (Apache/Nginx)
- Troubleshooting Common Issues
- Conclusion
- References
Prerequisites#
Before starting, ensure you have:
- A server running Rocky Linux 8/9 or AlmaLinux 8/9.
- Sudo or root access to execute administrative commands.
- An active internet connection to download packages.
Step 1: Update Your System#
First, update your system’s package index to ensure you have the latest dependencies. Run:
sudo dnf update -y This command updates all installed packages and resolves potential conflicts.
Step 2: Enable EPEL Repository#
EPEL provides additional packages for Enterprise Linux. Install it using:
sudo dnf install epel-release -y Verify EPEL is enabled:
dnf repolist | grep epel You should see epel in the output (e.g., epel/x86_64 Extra Packages for Enterprise Linux 8 - x86_64).
Step 3: Enable Remi Repository#
Remi is a third-party repository that offers the latest PHP versions. Install the Remi release package for your OS version:
For Rocky Linux/AlmaLinux 8:#
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y For Rocky Linux/AlmaLinux 9:#
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y Next, enable the PHP 8.0 module from Remi. List available PHP modules to confirm:
dnf module list php You’ll see entries like php:remi-8.0 (for PHP 8.0). Enable it with:
sudo dnf module enable php:remi-8.0 -y This sets Remi’s PHP 8.0 as the default PHP version.
Step 4: Install PHP 8.0#
Now install PHP 8.0 core packages. Run:
sudo dnf install php -y This installs the base PHP 8.0 binaries, including the CLI (Command-Line Interface).
Step 5: Install PHP Extensions#
Most applications require additional PHP extensions (e.g., for databases, XML, or image processing). Install common extensions using:
sudo dnf install php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json -y Here’s what these extensions do:
php-fpm: FastCGI Process Manager (for web servers like Nginx).php-mysqlnd: MySQL native driver (for database connectivity).php-gd: Image processing.php-mbstring: Multibyte string support.php-curl: HTTP requests.
Install only the extensions your application needs. Use dnf search php- to find others (e.g., php-redis for Redis support).
Step 6: Verify PHP Installation#
Check the installed PHP version to confirm success:
php -v You should see output like:
PHP 8.0.30 (cli) (built: Jun 6 2023 15:11:08) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
Step 7: Configure PHP (Optional)#
PHP settings are managed via the php.ini file. The location varies by SAPI (Server API):
- CLI:
/etc/php.ini - PHP-FPM:
/etc/php-fpm.d/www.conf(pool-specific settings)
Example: Adjust PHP Memory Limit#
Edit php.ini with a text editor like nano:
sudo nano /etc/php.ini Find the memory_limit directive (default: 128M) and update it (e.g., to 256M for larger applications):
memory_limit = 256M Save and exit (Ctrl+O, Enter, Ctrl+X).
Restart PHP-FPM (If Using It)#
If you installed php-fpm, restart the service to apply changes:
sudo systemctl restart php-fpm
sudo systemctl enable php-fpm # Start on boot Step 8: Test PHP with a Web Server (Apache/Nginx)#
To use PHP with a web server, configure Apache or Nginx to process PHP files.
Option 1: Apache Web Server#
If using Apache, install the Apache PHP module and restart Apache:
sudo dnf install php-apache -y
sudo systemctl restart httpd
sudo systemctl enable httpd Create a test PHP file in Apache’s web root (/var/www/html):
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php Access the file via your server’s IP or domain: http://your-server-ip/info.php. You’ll see the PHP info page.
Option 2: Nginx Web Server#
Nginx uses PHP-FPM to process PHP files. Install Nginx first:
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx Edit Nginx’s default server block to handle PHP:
sudo nano /etc/nginx/conf.d/default.conf Add the following location block to process .php files:
server {
listen 80;
server_name your-domain.com; # Replace with your domain/IP
root /usr/share/nginx/html;
index index.php index.html;
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;
}
} Save and exit, then test Nginx configuration:
sudo nginx -t If valid, restart Nginx:
sudo systemctl restart nginx Create a test PHP file in Nginx’s web root (/usr/share/nginx/html):
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php Access http://your-server-ip/info.php to confirm PHP is working.
Troubleshooting Common Issues#
1. PHP Version Still Old?#
If php -v shows an older version, ensure the Remi module is enabled:
dnf module list php | grep enabled If php:remi-8.0 isn’t enabled, re-run:
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.0 -y
sudo dnf install php -y 2. PHP-FPM Service Fails to Start?#
Check the logs for errors:
journalctl -u php-fpm Common fixes:
- Ensure
php-fpmis installed:sudo dnf install php-fpm -y. - Verify
www.confsyntax:sudo nginx -t(for Nginx) or checkphp-fpmlogs.
3. Firewall Blocking Web Access?#
Allow HTTP/HTTPS through firewalld:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload Conclusion#
You’ve successfully installed PHP 8.0 on Rocky Linux or AlmaLinux. This guide covered adding repositories, installing PHP and extensions, configuring PHP settings, and testing with Apache/Nginx. PHP 8.0’s performance and features make it a great choice for modern web applications.