How to Install Apache, MariaDB and PHP on CentOS Stream 9
This is one of the most commonly used Software Stack for building your web applications. This is also known as LAMP (Linux, Apache, MySQL/MariaDB, PHP/Perl/Python) Stack. See how IBM explains it.
Update CentOS Stream 9 Software Packages
Let's update software packages first. To perform updates, run the following command:
Install Apache Web Server
First, we will start by installing the Apache webserver. To complete the installation, use the following command:
dnf install httpd httpd-tools
Once the installation is complete, enable Apache (to start automatically upon system boot), start the webserver, and verify the status using the commands below.
systemctl enable httpd systemctl start httpd systemctl status httpd
To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands.
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=http success [root@server ~]# firewall-cmd --permanent --zone=public --add-service=https success [root@server ~]# firewall-cmd --reload success
Verify that the webserver is running and accessible by accessing your server’s IP address from your browser,
IP_addresswith the actual IP of the server.
Install MariaDB Server
MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.
dnf install mariadb-server mariadb -y
Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB, and verify the status using the commands below.
systemctl start mariadb systemctl enable mariadb systemctl status mariadb
Finally, you will want to secure your MariaDB installation by issuing the following command.
Once secured, you can connect to MySQL and review the existing databases on your database server by using the following command.
mysql -e "SHOW DATABASES;" -p
[root@server ~]# mysql -e "SHOW DATABASES;" -p Enter password: +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ [root@server ~]#
Install PHP 8
To install PHP on your RHEL 8 use the command below.
yum install php php-mysqlnd php-pdo php-gd php-mbstring
Now restart your web server so that Apache knows that it will be serving PHP requests as well.
systemctl restart httpd
Test your PHP, by creating a simple info.php file with a
phpinfo() function in it. The file should be placed in the directory root for your web server, which is
To create the file use:
echo "<?php phpinfo() ?>" > /var/www/html/info.php
Now again, access http://localhost/info.php or http://yourserver-ip-address/info.php. You should see a page similar to the below one.
Once confirmed, we recommend removing the info.php as it could be a security issue later on.