How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7


Introduction (LAMP Stack)

A “LAMP” stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.

As I’m sure that most of you know what is all about LAMP, so skipping introduction and details. This tutorial will concentrate on how to install and configure LAMP stack on CentOS 7.


Step 1 – Install and Configure Apache

The Apache (httpd) web server is currently the most popular web server in the world, which makes it a great default choice for hosting a website.

We can install Apache easily using CentOS’s package manager, yum. A package manager allows us to install most software pain-free from a repository maintained by CentOS.

1. For Apache installation use following yum command.

[root@localhost ~]# yum install httpd

2. Start Apache Service.

[root@localhost ~]# systemctl start httpd.service

3. Allow traffic through HTTP and HTTPS port in your firewall.

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http 
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https
[root@localhost ~]# firewall-cmd --reload

4. Test and verify installed Apache.


5. Enable the Apache service.

[root@localhost ~]# systemctl enable httpd.service


Step 2 – Install and Configure MySQL (MariaDB)

Now, we have web server up and running, it is time to install MariaDB, a MySQL replacement. MariaDB is a community-developed fork of the MySQL relational database management system. Basically, it will organize and provide access to databases where our site can store information.

1. For MySQL / MariaDB server installation use following yum command.

[root@localhost ~]# yum install mariadb-server mariadb

2. Start MySQL / MariaDB Service.

[root@localhost ~]# systemctl start mariadb

3. After MariaDB is installed, use mysql_secure_installation script to secure database (set root password, disable remotely logon from root, remove test database and remove anonymous users).

[root@localhost ~]# mysql_secure_installation

The prompt will ask you for your current root password. Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter. Then the prompt will ask you if you want to set a root password. Go ahead and enter Y, and follow the instructions:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.

New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

For the rest of the questions, you should simply hit the “ENTER” key through each prompt to accept the default values.

4. Enable the MariaDB service.

[root@localhost ~]# systemctl enable mariadb.service


Step 3 – Install and Configure PHP

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server (Apache) to display.

1. Install PHP and some optional packages with PHP, use following yum command.

[root@localhost ~]# yum install php php-mysql php-dba php-devel php-gd php-mbstring

2. After installation of PHP and its packages, we need to restart the Apache web server in order for it to work with PHP.

[root@localhost ~]# systemctl start httpd.service


Step 4 – Test PHP processing with Apache Web Servers

To get a full information list on PHP from your browser, create a info.php file on Apache Document Root using the following command from root account, restart httpd service and direct your browser to the http://your_server_IP_address/info.php address.

[root@localhost ~]# echo "" > /var/www/html/info.php
[root@localhost ~]# systemctl restart httpd




That’s all it takes for a basic LAMP installation CentOS 7.0.


Avinash Pawar

An automation enthusiast who presently working as DevOps Engineer.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Avinash Pawar

An automation enthusiast who presently working as DevOps Engineer.