How to install a complete LAMP stack on CentOS 8

With the latest release of CentOS, you want to know how to install a full LAMP stack on this powerful, open source platform.

How to install a complete LAMP stack on CentOS 8
With the latest release of CentOS, you want to know how to install a full LAMP stack on this powerful, open source platform.

CentOS is often the operating system par excellence for both web and network administrators. The reasons for this are numerous, but security and reliability are always at the top of the list. But some assume that CentOS is not entirely the best choice for those new to Linux. In some cases that may be the case, but not always.

There are even cases where CentOS is as easy to manage as Ubuntu Server. Although installing a LAMP stack on CentOS may not be such an instance (because there is no equivalent for sudo apt-get install lamp server ^ on CentOS), it is not nearly as challenging as you might expect.

An example: every IT administrator of every level can add a full web stack to your CentOS server. In fact, I’m going to show you exactly how you can do that, on the latest release of the platform, CentOS 8.

SEE: 10 free alternatives to Microsoft Word and Excel (TechRepublic download)

What you need

The only things you need to make this possible are:

Ensure that CentOS is up-to-date

The first thing we want to do is make sure that CentOS is up-to-date. Log in to your CentOS 8 server and give the command:

sudo yum update -y

Once the update is complete, restart (only if the kernel has been updated) and continue.

How to install Apache

We will then install the Apache web server. To do this, execute the command:

sudo yum install httpd httpd-tools -y

When the installation is complete, start and enable the http daemon with the commands:

sudo systemctl starts httpd
enable sudo systemctl httpd

How to change the firewall rules

The installation of Apache does not change the firewall rules, so we have to do that manually. To allow traffic on port 80, su to the root user and give the command:

firewall-cmd – permanent – zone = public – add-service = http

You may also want to allow HTTPS traffic on port 443 with the command:

firewall-cmd – permanent – zone = public – add-service = https

Reload the firewall with the command:

reload systemctl firewalld

Unlike Apache on Ubuntu, this installation does not add a standard welcome page for the web server. Let’s create a sample page to check if the server works. To do this, execute the command:

echo

“Welcome to TechRepublic

“> /var/www/html/index.html

Point your browser at the IP address of your server and you should see the test page (Figure A).

Figure A

Close the root user with the command:

Exit

How to install the database

Now it’s time to install the database. I’m going to choose MariaDB. Run the command to install this database:

sudo yum install mariadb server mariadb -y

After the installation is complete, start and enable the database with the commands:

sudo systemctl starts mariadb
Enable sudo systemctl mariadb

Now we have to protect the database installation with an administrator password. To do this, execute the command:

sudo mysql_secure_installation

You will be prompted to type the current administrator password. Since there is none, just press Enter. Type and verify a new admin user password. After setting the password, answer Y to the following questions:

  • Delete anonymous users?

  • Do not allow remote root login?

  • Delete test database and access it?

  • Reload privilege lists now?

How to install PHP

Run the command to install PHP and some necessary modules:

sudo yum install php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring -y

When that installation is complete, start and enable PHP with the commands:

sudo systemctl starts php-fpm
sudo systemctl enables php-fpm

Congratulations, you now have a fully functioning LAMP server, based on CentOS 8. You can now start developing websites and web applications that depend on these tools.

Open source weekly newsletter

You do not want to miss our tips, tutorials and comments about the Linux operating system and open source applications.
Delivered Tuesday

Register today

Also see

Similar Posts

Leave a Reply