How to Install Web Server on CentOS 8 with LAMP

Hello Linux lovers. Welcome to another tutorial of CentOS 8. In this article, I am going to build a web server on my CentOS 8. I am going to use the LAMP Stack. LAMP is a short name for Linux, Apache, MySQL and PHP. A Great combination for a web server. Basically, you can build your own web server with any Linux distribution. I put links to some tutorials below.

CenTOS is a free, powerful Linux distribution that suitable for bot desktop and server use. Do not get confused with term Desktop and Server. You still be able to install any Server application on the CentOS Desktop. It’s going to be a pretty long article. Grab your coffee and let’s start.

Download CentOS 8 ISO

Steps to Install Web Server on CentOS 8

Step 1. Update your system

It is important to have an updated system. Before doing this installation, we need to update CentOS first.

Maybe it is necessary to reboot your system.

Step 2. Install Apache Web Server

Now, let’s install the Apache web server.

Output:

After install, we need to start and enable the Apache web server on startup.

Now check the service status and make sure it is running and active as follow

Change Firewall Settings

By default, CentOS firewall blocks the remote access to port 80 (HTTP) and 443 (HTTPS). So, we need to add the exception.

Finally, we need to make “apache” user as the owner of the web directory (/var/www/html)

Test the web server

In case you want to test your web server, you can do the following. Create a new file called index.html in the /var/www/html folder.

echo “Welcome to this site!” > /var/www/html/index.html

Now open your web browser and type: localhost or 127.0.0.1 in the address bar. You should see the following message.

At this point, the Apache web server is up and running. Get ready for the next steps.

Step 2. Install MySQL Server (MariaDB) on CentOS 8

Now we are going to install MariaDB Server. MariaDB is a fork of MySQL Server.

Next, do the following to enable and start the database server

Don’t forget to check the Mariadb service status

Output:

Next, we need to configure the database

You will need to answer some questions

Done.

Step 4. Install PHP on CentOS 8

The following step we are going to install PHP on CentOS 8. Use this command to start

And then, we need to start the php-fpm

Now restart the Apache web server

We need to tell the SELinux to allow Apache to execute PHP code via PHP-fpm

setsebool -P httpd_execmem 1

Done.

Test PHP

It is good to test the PHP and ensure it works properly. We need to create a new info.php in /var/www/html directory.

nano /var/www/html/info.php

And then paste this line

Close and save the file. And now, open the web browser and type:

localhost/info.php

You should see something like this

That’s it. Basically now you should have a working web server with MySQL/MariaDB database back end.

Admin

Leave a Reply

Your email address will not be published. Required fields are marked *