Install multiple php versions almalinux

With PHP 8.x version stream out, it is important for Linux users such as those under AlmaLinux to quickly adapt to this new version change due to the feature improvements associated with it.

PHP 8.x boasts of remarkable features and feature improvements such as Union Types, JIT (Just in Time) compiler support, the NullSafe Operator, Named Arguments, Attributes, Match Expression, Constructor Property Promotion, Throw Expression, and Inheritance with Private Methods.

AlmaLinux being a free, open-source, and community-supported Linux distribution makes it a perfect candidate for PHP 8.x installation. This open-source server-side scripting language has a lot of contributive footprint in generating dynamic web pages towards the creation of performant web applications.

Prerequisites

Ensure that you are a root/sudoer user of the AlmaLinux operating system you are using.

We can now begin the article walk-through on installing and configuring PHP 8.x on AlmaLinux operating system.

Installing PHP 8 on AlmaLinux

Your AlmaLinux operating system needs to be up-to-date for the best performance.

$ sudo dnf update && sudo dnf upgrade -y

There is no direct way of installing PHP 8.x on AlmaLinux without going through the EPEL and Remi repositories. This repo makes it possible to not only install PHP’s latest version release but also keep track of future version releases.

You, therefore, do not have to worry about the PHP version you need to use on your web application projects.

$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

In order for AlmaLinux to recognize the addition of repositories, you need to run a system update for the second time.

$ sudo dnf update && sudo dnf upgrade -y 

We are now ready to use the Remi repo for PHP installation. The first step is to list all the available PHP versions this repository has to offer AlmaLinux. We will use the list module command.

$ sudo dnf module list php
Install multiple php versions almalinux
List PHP Module in AlmaLinux

As you can see, the above command lists PHP 7.x module. In order to get PHP 8.x modules, we first need to reset the default PHP 7.x module.

$ sudo dnf module reset php
Install multiple php versions almalinux
Reset PHP Module in AlmaLinux

After resetting PHP from its default module, we should now be able to see the PHP modules Remi repo has to offer by re-running the module list command.

$ sudo dnf module list php
Install multiple php versions almalinux
List PHP Module in AlmaLinux

As you can see, the Remi repository offers PHP versions from 7.2 to 8.1.

Since PHP 8.1 is the latest version release under Remi repo, we first need to enable it before we can proceed and install PHP 8.1, or else PHP 7.4 from AppStream will be installed.

$ sudo dnf module enable php:remi-8.1  
Install multiple php versions almalinux
Enable PHP Module in AlmaLinux

We can now proceed and install PHP 8.1 on AlmaLinux.

$ sudo dnf install php -y
Install multiple php versions almalinux
Install PHP in AlmaLinux

Check on PHP installed version.

$ php --version
Install multiple php versions almalinux
Check PHP in AlmaLinux

To install additional PHP extensions, adhere to the syntax:

$ sudo dnf install php-extension-name  

For instance, we can install the php-fpm extension:

$ sudo dnf install php-fpm

Your AlmaLinux system is now installed and configured with the latest version of PHP (8.1).

Steps to Install LAMP on AlmaLinux 8 #

The steps are described here to install and set up a Lamp server on AlmaLinux 8 can also be used for CentOS 8 Stream and RHEL 8 Linux server or desktop systems.

1. Run system update #

One of the necessary steps before running the installation programs is to run the command to update the system. This helps us to make sure all the installed packages are in their latest state but also rebuild the system repository cache. This helps in the process of any software or services installation running smoothly.

Install multiple php versions almalinux
Run system update

Write ” y ” and Enter.

2. Install Apache web server on AlmaLinux 8 #

The next step is to install the Apache webserver on AlmaLinux along with some other tools to run httpdon this free RHEL based on Linux operating system. Now install the Apache package with the following command:

Code

sudo dnf install httpd httpd-tools

Install multiple php versions almalinux
Command to install Apache on AlmaLinux 8

again, Write ” y ” and Enter.

3. Enable and start Apache #

Once the webserver is installed, let’s start its service and also make it automatically up with the system boot. This will ensure whenever you boot AlmaLinux you won’t need to start Apache manually.

Code

sudo systemctl start httpd
sudo systemctl enable httpd

After installing Apache and applying its settings, we will now check its Status:

Code

sudo systemctl status httpd

Install multiple php versions almalinux
Check Apache Status in Almalinux 8

4. Update FireWall rules #

If you want to access the Apache webserver outside your local machine using some browser, then first we have to open ports 80 and 443 on our AlmaLinux server.

How open port 80 or HTTP in Almalinux 8 :
#

Code

sudo firewall-cmd --permanent --zone=public --add-service=http

How open port 443 or HTTPS in Almalinux 8:
#

Code

sudo firewall-cmd --permanent --zone=public --add-service=https

Reload firewall to make changes into effect:

Code

sudo firewall-cmd --reload

Well the installation is complete! Now by entering the IP address in the browser we can see the result:

http://your-server-ipadress

Install multiple php versions almalinux

5. Install MySQL (MariaDB) on AlmaLinux8 #

MySQL is a freely available open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). SQL is the most popular language for adding, accessing, and managing content in a database. It is most noted for its quick processing, proven reliability, ease and flexibility of use.

MariaDB is a fork that works similarly and uses the same command line as MySQL. You can install any of them as per your choice. 

MySQL installation command:
#

Code

sudo dnf install mysql-server mysql

MariaDB installation command: #

Code

sudo dnf install mariadb-server mariadb -y

How Start & Enable MySQL and MariaDB services on Almalinux :
#

MySQL:

Code

sudo systemctl start mysqld
sudo systemctl enable mysqld

—–  check status

Code

sudo systemctl status mysqld

MariaDB

Code

sudo systemctl start mariadb
sudo systemctl enable mariadb

—–  check status

Code

sudo systemctl status mariadb

6. Secure MySQL installation #

This step will be the same whether you are using MySQL or MariaDB, it will give some options to follow and set some settings so that we can secure of Database from any common future threats.

Code

mysql_secure_installation

in this process, You will be asked to Set root PasswordRemove anonymous users, Disallow root login remotely, Remove test database, Reload privilege tables, and need Enter ” Y ” to do them.

  • Enter current password for root (enter for none): Enter
  • Set a root password? [Y/n] y
  • Remove anonymous users? [Y/n] y
  • Disallow root login remotely? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y
Install multiple php versions almalinux
Secure MariaDB Installation

7. Install PHP 7.2/7.3/7.4 or 8.0 on AlmaLinux 8 #

PHP (recursive acronym for PHP: Hypertext Preprocessor) is an open-source, popular general-purpose scripting language that is widely-used and best suited for developing websites and web-based applications. It is a server-side scripting language that can be embedded in HTML.

Currently, there are three supported versions of PHP, i.e PHP 5.6, 7.0, and 8.0. Meaning PHP 5.3, 5.4, and 5.5 have all reached the end of life; they are no longer supported with security updates.

First, check what are PHP versions available to install:

Code

$ sudo dnf module list php

Install multiple php versions almalinux
Search PHP modules or versions available to install on AlmaLinux 8

The output clearly shows that the default module is PHP 7.2 with the [d] tag.

To install PHP 7.4, first enable the module as provided.

Code

sudo dnf module reset php

sudo dnf module enable php:7.4

NOTE: To enable a different module, simply replace 7.4 with the preferred version. For example, to enable 7.3 run:

Once installed, install PHP and associated PHP extensions (php-extension_name) as indicated. The PHP extensions installed in this example are as shown.

Code

sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd

Install multiple php versions almalinux
Install the latest version of PHP on AlmaLinux 8

To get better performance for various applications using PHP, we can start (if not already) and enable PHP-FPM (FastCGI Process Manager) using the below commands:

Code

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

8. Verify the Version of PHP Installed #

Once the installation is complete, verify the version of PHP installed.

Install multiple php versions almalinux
Verify PHP Version

The output above confirms that we have successfully installed PHP 7.4.
But since we have installed Apache web server and php, it is better to see if PHP works properly with web server?

So we create a file called test.php in the following path and open it with our favorite editor:

Code

sudo nano /var/www/html/test.php

Add the following line in the test.php file we have created using the above command:

To save the file type: Ctrl+X, press the Y key, and then Enter key.

Now, open your browser and type your server IP address along with file name test.php, we have created above:

http://your-server-ipaddress/test.php

Install multiple php versions almalinux
Check PHP configuration details

9. Install PHP 8.0 (remi) on AlmaLinux 8 #

If you want to install the php version you want with the remi repository (for example, install php 8) follow these steps:

1. Add Remi Repository  #

Code

sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

2. Run system update #3. Check available Latest PHP versions #

Code

sudo dnf module list php

Install multiple php versions almalinux
Remi on Almalinux

To install it first you have to set Remi’s PHP 8.0 as the default version to install on AlmaLinux 8, for that run:

Code

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

Code

sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd

Code

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

10. Install phpMyAdmin on Almalinux 8 #

If you also want to manage your MySQL or MariaDB database using web graphical user interface then see our article: Install phpMyAdmin on AlmaLinux 8 with Apache

Can you install multiple PHP versions?

Add a PHP Repository So you'll need to add the PHP repository in your system to install the multiple PHP versions. Once the repository is up-to-date, you can proceed to install multiple PHP versions.

How do I install all PHP versions?

The easiest way to install multiple versions of PHP is by using the PPA from Ondřej Surý, who is a Debian developer. To add this PPA, run the following commands in the terminal. The software-properties-common package is needed if you want to install software from PPA.

Can we install multiple PHP versions CentOS 7?

Step 1 — Installing PHP Versions 7.0 and 7.2 with PHP-FPM. With the prerequisites completed, you will now install PHP versions 7.0 and 7.2. The SCL (Software Collections) repository maintains numerous versions of the PHP stack for the CentOS 7 system.

Can I install two versions of PHP Windows?

You can install as many versions of PHP as you need.