Install PHP 8.3 on Rocky Linux and AlmaLinux

Published July 08, 2024

Prerequisites for PHP 8.3 Installation

Supported Operating Systems

PHP 8.3 can be installed on these Rocky Linux and AlmaLinux versions:

Operating System Supported Versions
Rocky Linux 8, 9
AlmaLinux 8, 9

To check your system's version, run this command in your terminal:

cat /etc/redhat-release
Rocky Linux release 9.1 (Blue Onyx)

Administrative Access

You need root or sudo access to install PHP 8.3. This lets you:

  • Install software packages
  • Change system settings
  • Manage services

To check if you have sudo access, run:

sudo -v

If you don't get an error message, you have sudo privileges.

System Update

Before installing PHP 8.3, update your system packages:

sudo dnf update -y

This command:

  • Updates the package list
  • Upgrades installed packages to their latest versions
  • Answers "yes" to prompts (-y flag)

Other Considerations

PHP Extensions

Decide which PHP extensions you need for your projects. Common extensions include:

  • mysqli: for MySQL database connections
  • pdo_mysql: for PDO-style MySQL connections
  • gd: for image processing
  • curl: for making HTTP requests
  • mbstring: for multibyte string handling

Web Server Compatibility

Make sure your web server works with PHP 8.3. Common web servers include:

Backup Existing PHP Installation

If you're upgrading from an older PHP version, back up your current PHP configuration:

sudo cp -R /etc/php /etc/php_backup

This creates a backup of your PHP configuration in case you need to undo changes.

Enable Required Repositories

Setting up EPEL Repository

The EPEL (Extra Packages for Enterprise Linux) repository helps install PHP 8.3 on Rocky Linux or AlmaLinux. It provides extra packages and dependencies not in standard repositories.

To set up the EPEL repository:

  1. Install EPEL:

    sudo dnf install epel-release
  2. Update your system:

    sudo dnf update

Configuring Remi Repository

The Remi repository provides the latest PHP versions and is needed for installing PHP 8.3.

To configure the Remi repository:

  1. Install Remi:

    sudo dnf install$(rpm -E %rhel).rpm
  2. Enable PHP 8.3 module:

    sudo dnf module reset php
    sudo dnf module enable php:remi-8.3

Installing PHP 8.3

Using DNF Package Manager

To install PHP 8.3 and its core components, use this command:

sudo dnf install php

This installs the main PHP package and its core components.

To install common PHP extensions, add them to the installation command:

sudo dnf install php 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

Common PHP Extensions

Extension Purpose
php-cli Command-line interface for PHP
php-fpm FastCGI Process Manager
php-mysqlnd MySQL Native Driver
php-zip ZIP archive support
php-devel Files for PHP module development
php-gd Image processing library
php-mcrypt Encryption library
php-mbstring Multibyte string handling
php-curl cURL support
php-xml XML parsing and generation
php-pear PHP Extension and Application Repository
php-bcmath Arbitrary precision mathematics
php-json JSON support

You can add or remove extensions based on your project needs.

Verifying PHP 8.3 Installation

After installation, check the PHP version:

php -v

Expected output:

PHP 8.3.0 (cli) (built: Nov 21 2023 10:24:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies

To confirm the installation of PHP extensions:

php -m

To check the PHP configuration:

php -i

If you installed PHP-FPM, check its status:

sudo systemctl status php-fpm

Configuring PHP 8.3

Editing php.ini File

The php.ini file is the main configuration file for PHP. On Rocky Linux and AlmaLinux, it's usually at /etc/php.ini. To edit this file, use this command:

sudo nano /etc/php.ini

Some important settings to consider:

Setting Description Example
Memory Limit Sets the maximum memory a PHP script can use memory_limit = 256M
Max Execution Time Limits how long a PHP script can run max_execution_time = 30
File Upload Size Controls the maximum size of uploaded files upload_max_filesize = 20M
post_max_size = 20M
Error Reporting Manages how PHP handles and displays errors error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
display_errors = Off
Date and Time Zone Sets the local time zone date.timezone = "America/New_York"

After making changes, save the file and restart your web server.

Managing PHP-FPM Service

PHP-FPM (FastCGI Process Manager) handles PHP requests.

Starting and Enabling PHP-FPM

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

Checking PHP-FPM Status

sudo systemctl status php-fpm

Configuring PHP-FPM for Web Servers

For Apache

Edit /etc/httpd/conf.d/php.conf:

<FilesMatch \.php$>
    SetHandler "proxy:unix:/var/run/php-fpm/www.sock|fcgi://localhost"

For Nginx

Edit your Nginx server block, usually in /etc/nginx/conf.d/default.conf:

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/www.sock;
    fastcgi_index index.php;
    include fastcgi_params;

Restarting Web Servers

After configuring, restart your web server:

  • For Apache:

    sudo systemctl restart httpd
  • For Nginx:

    sudo systemctl restart nginx

Additional PHP 8.3 Optimizations

OpCache Settings

OpCache improves PHP performance by storing precompiled script bytecode in shared memory.

Edit php.ini to include:


Realpath Cache

Optimize file path resolution:

realpath_cache_size = 4096k
realpath_cache_ttl = 600

Session Handling

For better session management:

session.gc_maxlifetime = 1440
session.gc_probability = 1
session.gc_divisor = 100

Testing PHP 8.3 Setup

Creating a PHP Info Page

To test your PHP 8.3 installation, follow these steps to create and access a PHP info page:

  1. Create a new PHP file:
sudo nano /var/www/html/phpinfo.php
  1. Add this code to the file:
  1. Save and close the file.

  2. Set the correct permissions:

sudo chown apache:apache /var/www/html/phpinfo.php
sudo chmod 644 /var/www/html/phpinfo.php
  1. Access the page in your web browser:

This page shows details about your PHP installation, including:

  • PHP version
  • Loaded extensions
  • Server environment
  • PHP settings

After testing, remove the file for security:

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

Useful Information from PHP Info Page

The PHP info page provides information for developers and system administrators. Here are some key sections and their uses:

PHP Core

Section Use
PHP Version Check the installed PHP version
Loaded Configuration File Find the main PHP configuration file
memory_limit Check available memory for PHP scripts
max_execution_time View the maximum time a script can run
upload_max_filesize See the maximum allowed file upload size

Loaded Extensions

The PHP info page lists all loaded extensions. This information is useful for:

  • Confirming required extensions are installed
  • Identifying potential conflicts between extensions
  • Verifying extension versions

Server Information

Information Use
Server API Identify how PHP is running (e.g., FPM, CGI)
Server Software Check the web server software and version
Document Root Confirm the main directory for web files

Environment Variables

This section shows environment variables available to PHP, which can be useful for:

  • Debugging configuration issues
  • Verifying custom environment settings
  • Understanding the server environment

Troubleshooting Common Issues

Addressing Permission Problems

  1. File Ownership: Make sure PHP files are owned by the web server user:

    sudo chown -R apache:apache /var/www/html
  2. Directory Permissions: Set correct permissions for web directories:

    sudo find /var/www/html -type d -exec chmod 755 {} \;
    sudo find /var/www/html -type f -exec chmod 644 {} \;
  3. SELinux Context: If using SELinux, set the correct context:

    sudo restorecon -Rv /var/www/html

Resolving Extension Conflicts

Follow these steps to identify and resolve extension conflicts:

  1. Check Loaded Extensions: View loaded extensions:

    php -m
  2. Identify Conflicts: Look for error messages in PHP logs:

    sudo tail -f /var/log/php-fpm/error.log
  3. Disable Conflicting Extensions: Comment out conflicting extensions in PHP configuration:

    sudo nano /etc/php.ini

    Comment out the extension line:

  4. Update Extension Order: Change the loading order in PHP configuration if needed.

  5. Restart PHP-FPM: After making changes, restart PHP-FPM:

    sudo systemctl restart php-fpm