How to install Apache, MySQL and PHP on AlmaLinux 8
LAMP is an open source software stack to provide a fully functional web server environment for various PHP and other applications. LAMP means Linux, Apache, MySQL, PHP / Perl / Python, and here we learn how to install them on CentOS alternative AmlaLinux 8.x server.
The basic function of a web server is to deliver HTML and image content over the HTTP or HTTPS protocol. Every time we type a web address into our browser, it asks the web server for the delivery of the called web page available on the web server using port 80 (“HTTP: //”) or port 443 (“HTTPS: // “).
The Apache HTTP Server is one of the most widely used web servers. It’s been around for a good 20 years and powers millions of web servers. However, there are some good alternatives such as the Nginx web server which uses PC resources more sparingly and is often better suited for less powerful hardware and servers with a large number of accesses. In some cases, combining Apache with Nginx as a reverse proxy can also be helpful.
Steps to install the LAMP server on AlmaLinux 8
The steps described here to install and configure a Lamp server on AlmaLinux 8 can also be used for CentOS 8 Stream and RHEL 8 Linux server or desktop systems.
1. Run the system update
Like most of the time before starting a tutorial, I recommend readers to run a system update command, which will not only ensure that all installed packages are in their latest state, but also rebuild the system repository cache. This helps the smooth installation of any software or service.
sudo dnf update
2. Install the Apache web server on AlmaLinux 8
The next step is to install the Apache web server on AlmaLinux with other tools to run
httpd on this free RHEL based on the Linux operating system. Just run the command below:
sudo dnf install httpd httpd-tools
3. Activate and start Apache
After the web server is installed, let’s start its service and also start it automatically with system startup. This will ensure that each time you start AlmaLinux, you will not need to start Apache manually.
sudo systemctl start httpd
sudo systemctl enable httpd
Check condition of the Webs Server service to make sure everything is working without errors.
sudo systemctl status httpd
4. Update the firewall rules
If you want to access the Apache web server outside of your local computer using a browser, we need to open ports 80 and 443 on our AlmaLinux server first.
To open port 80 or HTTP:
sudo firewall-cmd --permanent --zone=public --add-service=http
To allow port 443 or HTTPS:
sudo firewall-cmd --permanent --zone=public --add-service=https
Reload the firewall to apply the changes
sudo firewall-cmd --reload
Now we can connect to our AlmaLinux Apache web server by calling it in the browser. To do this, open your browser and type the IP address of the server on which you installed Apache.
5. Install MySQL or MariaDB on AlmaLinux8
MySQL is an open source database developed by Oracle while 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.
Command for MySQL
sudo dnf install mysql-server mysql
sudo dnf install mariadb-server mariadb -y
Command to start and activate MySQL and MariaDB services
sudo systemctl start mysqld sudo systemctl enable mysqld
To check the status:
sudo systemctl status mysqld
sudo systemctl start mariadb sudo systemctl enable mariadb
sudo systemctl status mariadb
6. Secure installation of MySQL
This step will be the same whether you are using MySQL or MariaDB, it will give some options to follow and set some parameters so that we can secure the database against all common future threats.
You can set a root password for MySQL or MariaDB as well as delete empty databases, restrict remote access except localhost, delete anonymous users, etc.
7. Install PHP 7.2 / 7.3 / 7.4 or 8.0 on AlmaLinux 8
PHP is a popular scripting language that powers dynamic content for millions of websites and applications. Therefore, if you plan to install a web CMS like WordPress, you need to configure PHP on your AlmaLinux server.
First, check which PHP versions are available for installation:
sudo dnf module list php
As you can see from writing the article, the latest version of PHP in the AppStream repository of the system by default was 7.4, although PHP 8 is already there, as many web applications still support PHP 7.x, offering thus extended compatibility and stability. should go for PHP 7.4 …
Also by default it will install PHP 7.2, to change we need to configure and set 7.4 as default / enable in the repository. For this race:
sudo dnf module reset php
sudo dnf module enable php:7.4
The above command changes the default version of the system repository to install.
(Optional step): Those who want the latest PHP 8.0 or any other version on their AlamLinux 8, can follow these steps:
1. Add the Remi repository
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
2. Run the system update
sudo dnf update
3. Check the latest PHP versions available
sudo dnf module list php
To install it, you must first define Remi’s PHP 8.0 as the default version to install on AlmaLinux 8, for this run:
sudo dnf module reset php sudo dnf module enable php:remi-8.0
Finally, run the command to install PHP and the common extensions we need to use with Apache and Mysql on our system:
sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd
To get better performance for various applications using PHP, we can start (if we haven’t already) and enable PHP-FPM (FastCGI Process Manager) using the commands below:
sudo systemctl start php-fpm sudo systemctl enable php-fpm
8. Test PHP
We have already installed Apache, MySQL and PHP on our system, check if PHP is working fine by calling its configuration details in the browser.
sudo nano /var/www/html/info.php
If you don’t have a nano text editor, use vi and the above command will be:
sudo vi /var/www/html/info.php
Add the following line in the info.php file that we created using the above command:
To save the file type: Ctrl + X, press the Yes key, then Enter key.
While, users using VI editor- first to copy paste the line above they have to press
Escwhen editing is complete, followed by
:qwto save and exit it.
Now open your browser and enter the IP address of your server as well as the info.php file name, which we created above:
To delete this type of file:
sudo rm /var/www/html/info.php
9. Install phpMyAdmin
If you also want to manage your MySQL or MariaDB database using a web GUI, see our article: Install phpMyAdmin on AlmaLinux 8 with Apache
So here are some simple but detailed steps for installation and configuration Apache, MySQL and PHP on the AlamLinux 8 server. In case you want to know anything else related to this Linux or topic, the comments section is yours …