Choose a different version or distribution
Introduction
Before we begin talking about how to install PHP 8.3 on AlmaLinux 9, let's briefly understand – What is PHP?
PHP is a popular server-side scripting language used to create dynamic web pages. It stands for "Hypertext Preprocessor" and is open-source, making it widely accessible for web development. PHP seamlessly integrates with HTML, allowing developers to embed PHP code within HTML files to generate dynamic content.
It is versatile, supporting databases like MySQL for data management. Employed by major websites like Facebook and WordPress, PHP is crucial for building interactive websites and web applications. Start learning PHP to enhance your web development skills and create engaging online experiences.
In this tutorial, you will install PHP 8.3 on AlmaLinux 9. We will also address a few FAQs on how to install PHP 8.3 on AlmaLinux 9.
Advantages of PHP 8.3
- Just-In-Time Compilation (JIT): PHP 8.3 introduced JIT compilation, enhancing performance by compiling code during runtime. This boosts execution speed, making applications run faster.
- Enums Support: The addition of Enumerations in PHP 8.3 allows developers to define a set of named constants, making code clearer and more structured.
- Improved Error Handling: PHP 8.3 enhances error reporting, making it easier to identify and debug errors within the codebase, improving overall code reliability.
- Token Getters for Diagnostics: PHP 8.3 provides token getters to assist in diagnosing parsing issues, aiding developers in identifying and resolving syntax-related problems quickly.
- Enhanced Type System: With PHP 8.3's improved type system, developers can benefit from stricter type checking, reducing bugs and enhancing code robustness.
Import Remi PHP RPM for PHP 8.3 on AlmaLinux
Step 1: Update AlmaLinux Before PHP Installation
AlmaLinux must be updated prior to installing PHP 8.3. This improves stability and security by guaranteeing that the packages on your system are up-to-date.
sudo dnf upgrade --refresh
This command brings all installed packages up to date with the most recent versions and updates your package database.
Step 2: Add the Remi PHP RPM Repository to AlmaLinux
For the most recent versions of PHP, the Remi repository is an essential resource. Installing the Extra Packages for Enterprise Linux (EPEL) repository is required before continuing.
Importing Remi PHP Repository for AlmaLinux 9
Enable the CodeReady Linux Builder (CRB) repository for AlmaLinux 9 in order to gain access to extra development tools and libraries:
sudo dnf config-manager --set-enabled crb
Install the EL9 EPEL repository next:
sudo dnf install \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm
Lastly, include the EL9 Remi PHP repository:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
Importing Remi PHP Repository for AlmaLinux 8
Start with turning on the PowerTools repository for AlmaLinux 8 in order to get the required development and debugging tools:
sudo dnf config-manager --set-enabled powertools
Install the EL8 EPEL repository next:
sudo dnf install \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-8.noarch.rpm
Lastly, incorporate the EL8 Remi PHP repository:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
With these steps, you can be sure that AlmaLinux is running the most recent PHP versions compatible with your particular AlmaLinux version, which are available through the Remi repository.
Install PHP 8.3 on AlmaLinux
Step 1: Enable PHP 8.3 as Default Module
On your AlmaLinux system, start by configuring PHP 8.3 as the default PHP version. In order to enable PHP 8.3 from Remi's repository, use the following command:
sudo dnf module enable php:remi-8.3 -y
By designating PHP 8.3 as the default PHP version, this action guarantees that PHP installations and updates in the future will utilize this version.
Step 2: Install PHP 8.3 via DNF Command
Install PHP 8.3 after turning on the PHP 8.3 Module. Run the following command to finish the installation:
sudo dnf install php
Remi's RPM GPG keys will need to be imported; make sure to type "Y".
PHP 8.3 is installed on your system and ready for use with this command.
Step 3: Install PHP 8.3 Developer Tools (Optional)
Installing the following packages is something developers who need extra tools and packages for PHP development should think about doing:
sudo dnf install php-devel php-xdebug php-pcov
For PHP 8.3, these packages offer necessary debugging features, code coverage functionality, and development tools.
Step 4: Verify PHP 8.3 Installation
Verify the installed version of PHP 8.3 to make sure it is installed correctly:
php --version
By using this command, you can verify that PHP 8.3 was successfully installed on your AlmaLinux system by seeing the installed PHP version.
Install PHP 8.3 Extensions on AlmaLinux
Step 1: Check Default PHP 8.3 Modules
It's crucial to know which modules are already installed with PHP 8.3 on AlmaLinux before adding new extensions. The command to list these modules is as follows:
php -m
This can be difficult to see because it prints a lengthy list in your terminal by default. Alternatively, you can use the following command, which will output a single line:
php -m | tr '\n' ' '
All module names will print on a single line as a result of this command's replacement of each newline character (\n) with a space. It's much simpler to read this.
Another option is to print a small, multi-column output:
php -m | paste -s -d '\t\t\n'
This command formats the output into a more condensed, multi-column layout using paste
. The delimiters, in this case two tabs followed by a newline, are specified by the -d
option.
All in all, this command lists every module that is installed with your PHP 8.3 installation and gives you an idea of what extra extensions you might require.
Step 2: Install New PHP 8.3 Extensions
Look for the desired module first if you need any additional PHP 8.3 extension modules that aren't included in the default installation. As an illustration:
sudo dnf search php8.3-{extension name}
Change {extension name}
to the exact extension you require, php8.3-redis
, for example.
You can install the frequently used extensions on this list. Please feel free to alter this list to meet your needs:
sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache
Always install the extensions you actually need and remove the ones that are no longer needed.
Configure PHP 8.3-FPM on AlmaLinux
Editing PHP-FPM Configuration for Nginx
PHP-FPM's default user in AlmaLinux is "Apache", which is incompatible with Nginx. To make this setting compatible with Nginx, modify it.
Accessing PHP-FPM Configuration
To modify the parameters for PHP-FPM's communication with Nginx, open the PHP-FPM configuration file:
sudo nano /etc/php-fpm.d/www.conf
Using the Nano text editor, this command opens the PHP-FPM configuration.
Modifying User and Group Settings
Search for the user and group settings in the www.conf
file. These are initially configured to "Apache". Change the user and group to "Nginx" in order to integrate PHP-FPM with Nginx:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
This modification makes sure PHP-FPM is in line with Nginx, which improves compatibility.
Saving and Exiting the Configuration File
To save your edits, hit CTRL+O
. To exit Nano, hit CTRL+X
. After storing your changes, the editor is closed.
Restarting PHP-FPM Service
To make the changes effective, restart PHP-FPM:
sudo systemctl restart php-fpm
The new user and group settings are applied upon restarting PHP-FPM, which optimizes PHP-FPM for use with Nginx on AlmaLinux.
FAQs to Install PHP 8.3 on AlmaLinux 9
Can PHP 8.3 coexist with other PHP versions on AlmaLinux 9?
PHP 8.3 can be installed alongside other PHP versions on AlmaLinux 9, allowing you to choose the PHP version required for different projects.
Does PHP 8.3 on AlmaLinux 9 support all PHP extensions?
PHP 8.3 on AlmaLinux 9 supports a wide range of PHP extensions, ensuring compatibility with various PHP applications and frameworks.
How can I verify the PHP 8.3 installation on AlmaLinux 9?
You can verify the PHP 8.3 installation by running php --version
command in your terminal to confirm the installation status.
Are there any performance improvements in PHP 8.3 compared to earlier versions on AlmaLinux 9?
PHP 8.3 brings performance enhancements, including Just-In-Time Compilation (JIT), improving the execution speed of PHP applications on AlmaLinux 9.
Can I revert to an older PHP version after installing PHP 8.3 on AlmaLinux 9?
If needed, you can switch back to an older PHP version by following the appropriate procedures for switching PHP versions on AlmaLinux 9.
Can I run multiple PHP versions concurrently on AlmaLinux 9 and select them based on project requirements?
Yes, by utilizing tools like PHP-FPM and virtual hosts configuration, you can run multiple PHP versions simultaneously on AlmaLinux 9 and choose the one needed for each project.
Can I integrate PHP 8.3 with popular web servers like Apache or Nginx on AlmaLinux 9?
Yes, PHP 8.3 can seamlessly integrate with web servers like Apache and Nginx on AlmaLinux 9 using proper configuration directives to enable PHP processing.
Conclusion
We hope this tutorial helped you understand how to install PHP 8.3 on AlmaLinux 9.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.