How to Install LAMP Stack on CentOS 8
In this tutorial, we will install the LAMP stack on CentOS 8. LAMP is an acronym for Linux with an Apache web server, MariaDB database management system, and PHP for working with dynamic content. All actions must be performed by the root account.
In the Serverspace you can create a server with already installed app "LAMP".
Installing Apache on CentOS 8
Let’s install Apache web server.
dnf install httpd
Start the Apache daemon and make it start automatically during system boot.
systemctl start httpd
systemctl enable httpd
If you have a firewalld enabled, you must open the http or https ports, or both of them.
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
systemctl reload firewalld
To test the web server symply enter the IP address of your server in the browser.
MariaDB installation
MariaDB is an alternative for MySQL database management system. It is developed by former members of the MySQL team, since the last one can become a proprietary Oracle product.
Let’s install MariaDB DBMS.
dnf install mariadb-server
Now start the service and make it run automatically during system boot.
systemctl start mariadb
systemctl enable mariadb
To complete the basic DBMS security configuration, run the script and follow the instructions:
mysql_secure_installation
You can now enter the MariaDB command line.
mysql
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 15
Server version: 10.3.17-MariaDB MariaDB Server
...
If you see this text, MariaDB is working now.
PHP installing
The first package is PHP, and the second one allows PHP to interact with the DBMS. Let's install them.
dnf install php php-mysqlnd
Now restart Apache to enable PHP modules.
systemctl restart httpd
To test how PHP works, let’s create a file php.php in the /var/www/html/ folder.
nano /var/www/html/php.php
And insert the following lines there:
<!--?php phpinfo(); ?-->
Save and close this file. Now enter the IP address of your server in the browser and add /php.php to it. You will see PHP service information.
Attention! Do not leave this file on the server, it is a security risk.