How to install the LAMP stack on CentOS 8

s2 0

LAMP is an acronym for Linux, Apache, MySQL, and PHP. It’s a free, open source stack used by developers and website administrators to test and host their web applications. It contains 4 components namely Apache (for hosting a website), MySQL or MariaDB and PHP – a popular scripting language for creating dynamic web pages. MariaDB or MYSQL are used to store and manage the data.

In this tutorial you will learn how to install a LAMP server on CentOS 8. So, let’s go.

CentOS LAMP installation

Before installing, keep your system package repository up to date. To do this, open the terminal and use the following command:

# sudo dnf update

Install the Apache web server on CentOS8

After updating the system packages, the next step is to install the Apache web server and its tools, to do this, run the following command:

# sudo dnf install –y httpd httpd-tools

Once the installation is complete, enable and start the Apache service by running the following command:

# systemctl start httpd
# systemctl enable httpd

Run the following command to verify that the service is running:

# systemctl status httpd

Apache is ready to use

As you can see, you can see that the Apache web service is running.

Configure the CentOS firewall

After installing Apache, update the firewall rules to allow requests for it, use the following command:

# sudo firewall-cmd –add-service=http/tcp –permanent
# sudo firewall-cmd –add-service-https/tcp –permanent
# sudo firewall-cmd –reload

You can also open a web browser and test your web services by typing: IP address or localhost As shown below.

Apache test pageadvertising

Now we have the web server installed and running.

Install MariaDB on CentOS 8

The next step is to install the Maria DB to store data and manage data for the website, use the following command to do this:

# sudo dnf install –y mariadb-server mariadb

Install MariaDB

Once the installation is complete, enable and start the Maria DB service by running the following command:

# systemctl enable mariadb
# systemctl start mariadb

Use the following command to verify that the service is running:

# systemctl status mariadb

MariaDB status

As you can see above, MariaDB is running.

To improve the security of the database, it is recommended to run a security script that comes with the MariaDB. It removes the insecure default settings and blocks access to your database. To secure MariaDB by running the following command:

# mysql_secure_installation

You will be prompted to enter or set up the root password. You should therefore answer “Y” for each subsequent request.

Secure MariaDB

Install PHP on CentOS 8

The last component in the LAMP stack is PHP, I mentioned earlier that PHP is used to create a dynamic webpage to install PHP with the following command:

# sudo dnf install –y php php-mysqlnd

Install PHP

Testing the PHP

To test the PHP, create a page under / var / www / html / Directory (default directory). Paste the code as shown below:

Test PHP file - phpinfo

<?php

phpinfo (); // it will print the PHP Information that we have installed

?>

You need to tell SELinux to run PHP code using the following command:

# setsebool –P httpd_execmem 1

Finally, restart the httpd service.

# systemctl restart httpd

Now open the web browser and enter the IP address of your server in the search bar. You will get the output as shown below:

https://<ip-address>/info.php

PHP tested successfully

We have PHP version 7.2.11 installed and we can see the full PHP information on the website.

diploma

In this tutorial we learned how to set up LAMP Server with its components Apache, MariaDB and PHP on CentOS 8. We also see how to deal with PHP requests. I hope this tutorial will help you set up a LAMP server.

How to install the LAMP stack on CentOS 8