How To setup LAMP stack on CentOS 7

LAMP is short for Linux, Apache, MySQL or PHP which is an open source web development platform. It uses Linux as it’s operating system while Apache and MySQL are used as a web & database servers, the PHP is also used as an object oriented scripting language to work as a complete web stack, which is used to prepare servers for hosting web content.

In this article we are going to show you the step by step instructions to setup your own LAMP stack on CentOS 7 operating system.

Prerequisites

The Minimal system resources to setup LAMP server depends upon the requirements. We are going to setup the LAMP Server under the following base system with minimal installation.

Hostname: centos-7.vexxhost.com

Static IP: 203.0.113.1

Operating system: CentOS Linux 7 (Core)

Virtual CPU: 4 cores

Memory (RAM): 1GB

Disk Space: 40GB

After deploying the CentOS 7 with the mentioned resources, we will now proceed on setting up LAMP by installing Apache (web server), MySQL (database server) then PHP in the following order.

Apache Web Server

Apache web server is generally recognized as the world’s most popular open source HTTP web server and this allows us to easily install it from its available repositories in CentOS with following steps.

Installing Apache Web Server

Run the following command with root user to install apache http server with yum repositories.

[root@centos-7 ~]# yum install httpd

Once the installation is complete, we need to start it’s service and enable it to startup at boot using following commands.

Apache Test

To test the Apache web server installation, we need to open a web browser and give the server IP address. If you got the Apache test page as shown below, then it means that our Apache HTTP server is operational and successfully installed: http://203.0.113.1/

MySQL-MariaDB Server Setup

In CentOS 7, MySQL is replaced with MariaDB, it is an enhanced drop-in replacement for MySQL relational database management system. Under the following steps we will now install it with yum commands.

Installing MariaDB

We start by installing MariaDB-server package using the command below.

[root@centos-7 ~]# yum install mariadb mariadb-server

MariaDB server will now be installed with its required dependencies and updates. Once done we need to start it’s service, enabling it to start at boot and start it’s daemon for the first time as shown below.

Securing MySQL-MariaDB

Using mysql_secure_installation command, we can secure our database where we will be given the option to change or set its root password or remove anonymous user accounts and disallow remote root login with the test database and user removal.

After making modifications, we are required to restart the Apache services for the changes to take effect.

[root@centos-7 ~]# systemctl reload httpd

Testing PHP

In order to test the PHP, lets create a file phpinfo.php in document root directory /var/www/html/ and then add the below code of phpinfo as shown below.

[root@centos-7 html]# vim phpinfo.php
<?php phpinfo(); ?>

Then open the following link in your web browser and we will be able to see all the information about PHP and its other configurations: http://203.0.113.1/phpinfo.php (replacing your IP address with the one above).

Conclusion

In this detailed article we learned to setup LAMP Stack, where we installed and configured Apache, HTTP server, MySQL-MariaDB and PHP client to successfully install the LAMP web stack with it’s tested functionality of working as a web server for hosting websites to install any web applications on it.