Author Photo

Being a Linux Enthusiast and a Fan of Open Source Software, I created Ahmer’s SysAdmin Recipes blog to share my experiences with other System Administrators. The curiosity doesn’t let me stop; therefore, I am constantly trying to learn new software tools and techniques. Whereas I also have the passion and the patience to teach the others.

I am always ready to accept new challenges and wish to explore the areas, that I haven’t worked on. Please give me your feedback and help me improve this blog.

Thursday, 25 February 2016

Installing LAMP Stack on CentOS 7

Installing LAMP Stack on CentOS 7LAMP is an archetypal model of web service solution stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP server, the MySQL relational database management system (RDBMS), and the PHP programming language.  As a solution stack, LAMP is suitable for building dynamic web sites and web applications.

LAMP stack components are largely interchangeable and not limited to the original selection. This results in evolution of many other stacks like LEMP, LEPP, etc.

In this article, we will install LAMP stack on CentOS 7 server. We will install each of four LAMP stack components separately on our CentOS 7 server.

Reading Advice: How to Build a LAMP Server

 

System Specification:

CPU: 3.4 Ghz (2 cores)
Memory: 2 GB
Storage: 60 GB
Swap: 4 GB
Hostname: lampserver.mydomain.com
IP Address: 170.172.0.30/16
Gateway: 170.172.0.1
DNS Server: 170.172.0.3

 

Installing CentOS 7:

As the Linux component of LAMP stack, we will install CentOS 7 on our machine.

Detailed guide of CentOS 7 installation is available here. Please follow it to install and configure CentOS 7.

In this article, we are using yum for installation on the Server, therefore, make sure that either you have accessed to CentOS 7 public yum repository using CNTLM proxy or you have configured a local yum repository for your server.

 

Installing Apache HTTP Server on CentOS 7:

Apache server is the preferred choice for the web server on a LAMP stack.

Connect to lampserver.mydomain.com using ssh as root user and execute following commands to install Apache HTTP Server on CentOS 7.

[root@lampserver ~]# yum install -y httpd

Start and enable Apache HTTP service.

[root@lampserver ~]# systemctl enable httpd.service [root@lampserver ~]# systemctl start httpd.service

Allow Apache HTTP service port in Linux firewall.

[root@lampserver ~]# firewall-cmd --permanent --add-service=http [root@lampserver ~]# firewall-cmd --reload

Browse URL http://170.172.0.30 to see the Apache HTTP Server’s default webpage.

Apache HTTP Server Homepage

Apache HTTP server has been installed on our CentOS 7 server.

 

Installing MySQL Database Server on CentOS 7:

For database component of LAMP stack, we have many choices like MySQL, MariaDB or PerconaDB. Here, we will install MySQL database server.

Go to MySQL:: Download MySQL Yum Repository and download & install the yum repository for MySQL.

[root@lampserver ~]# cd /soft [root@lampserver soft]# wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm [root@lampserver soft]# rpm -Uvh mysql57-community-release-el7-7.noarch.rpm [root@lampserver soft]# yum clean all [root@lampserver soft]# yum makecache

Install the latest version of mysql-community-server. In our case, it installed mysql-community-server 5.7, which is latest at the time of this writeup.

[root@lampserver soft]# yum install -y mysql-server

Start and enable the mysqld service.

[root@lampserver soft]# systemctl enable mysqld.service [root@lampserver soft]# systemctl start mysqld.service

When mysqld service starts for the first time, it generates a random password for root@localhost user in /var/log/mysqld.log file. Use the following command to get it.

[root@lampserver soft]# grep 'temporary password' /var/log/mysqld.log

Configure the mysql security using following command.

[root@lampserver soft]# /usr/bin/mysql_secure_installation

and select the following options.

set a password for root remove anonymous users: Y Disallow remote Root Login: Y Remove Test Database and access to it: Y Reload Privilege tables: Y

MySQL database server has been installed and configured on our CentOS 7 server.

 

Installing PHP on CentOS 7:

PHP is the hypertext preprocessor and it adds the application functionality in our LAMP server.

Use the following command to install PHP from CentOS yum Repository. In our case, it installed PHP 5.4. Although, stable version 7 of PHP is available at this time. If you want to use a latest version than you can download it from http://www.php.net

[root@lampserver soft]# yum install -y php

Depends upon your web application, you may required to install specific php modules on the server. To see the compatible modules for your php server use the following command:

[root@lampserver soft]# yum search php-

Install required php modules as follows:

[root@lampserver soft]# yum install -y php-mysql

Restart the httpd Service to load the php modules.

[root@lampserver soft]# systemctl restart httpd.service

Create the test page for php at document root of Apache Server.

[root@lampserver soft]# cat >> /var/www/html/info.php << EOF ><?php >phpinfo(); >?> >EOF

Browse URL http://170.172.0.30/info.php. It will show you a very long page with useful information that may be helpful during troubleshooting of your LAMP server.

PHPInfo

We have installed the CentOS, Apache, MySQL & PHP: the complete LAMP Stack with default configurations.

Installing LAMP Stack on CentOS 7


YOU MIGHT ALSO LIKE:

2 comments:

  1. Hi Sir,
    please teach how to use compiled php
    wiwh selected modules and compiled apache and both can work together because sometimes client requirements ...

    ReplyDelete
    Replies
    1. Do some research on try Phalang, Roadsend or phc. One of them must fulfill your requirement.

      Delete