Quick Start: Setup CentOS 7 as a LAMP Server

MySQL
In this tutorial, I’m going to show you simple steps using which you can setup your own LAMP (Linux-Apache-MySQL-PHP) on a CentOS 7 system.

Prerequisites
CentOS 7 Minimal ISO
Make sure your system has a static IP address assigned to it and a fully qualified domain name.

System Details:
Base OS:        CentOS 7 64 Bit (Minimal ISO)
HOSTNAME:  master.cloud.com
IPADDRESS: 192.168.0.15

Steps:

LINUX
Start by Installing a CentOS 7 system.

APACHE WEB SERVER
Once the base OS is ready, we now install the Apache web server package.

# yum install httpd

The httpd package downloads some additional dependencies as well. Hit “Y” and download all the required RPMs as shown.

Next, edit the “httpd conf” file

# vi /etc/httpd/conf/httpd.conf

In this file, you only need to edit at two places:

# Replace ServerAdmin [email protected]
ServerAdmin root@<YOUR_CENTOS_IP_ADDRESS>

# Replace ServerName localhost:80
ServerName <YOUR_CENTOS_IP_ADDRESS>:80

NOTE: ServerName attribute is commented out by default, so remember to uncomment it out first.

Save and exit the editor once the changes are made.

Start and enable the httpd service

# systemctl start httpd

# systemctl enable httpd

Enable the HTTP port (Port 80) on the firewall and reload the firewall.

# firewall-cmd –permanent –add-port=80/tcp

# firewall-cmd –reload

Test your Web Server by typing in the CentOS system’s IP address in a browser. You should see the following web page if your settings are done correctly.

http://<YOUR_CENTOS_IP_ADDRESS>

MySQL
Next up we install the MySQL Database. An important point to note here is that with CentOS 7, MariaDB is shipped as the default MySQL Engine unlike the earlier versions where MySQL was the de facto choice.

In this guide, I’ll show you how to install both MariaDB and MySQL Server.

First off, its MariaDB

# yum install mariadb mariadb-server

This will install the necessary DB packages for MariaDB, rest of the configuring steps remain the same for MySQL so I’ll now show you how to install MySQL Community Edition on a CentOS 7 system.

First off, we download some prerequisites:

# yum install wget

Next, download the MySQL Community Release RPM using the following command:

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Install the downloaded RPM

# rpm -ivh mysql-community-release-el7-5.noarch.rpm

 

The RPM installs two repos at /etc/yum.repos.d directory, both will be used to install the MySQL Community Server packages

Once prepped, you can now install the MySQL packages as required

# yum install mysql-server mysql

Start and enable the MySQL service

# systemctl start mysqld

# systemctl enable mysqld

Run the mysql_secure_installation script to set the root password and other necessary parameters

# mysql_secure_installation

Test your MySQL server by logging on the DB:
 
# mysql -u root -p

PHP
The final install is PHP. Run the following command to install the basic PHP packages:

# yum install php php-mysql

Hit “Y” to download and install the packages

Next, create a simple file to test whether PHP was successfully installed or not

# vi /var/www/html/info.php

<?php phpinfo(); ?>
Restart the httpd service before you proceed.

# systemctl restart httpd

Open up a browser and type in the following. You should see the PHP info page as shown below:

http://<CENTOS_SERVER_IP_ADDRESS>/info.php

 

Thats it for this post..Thanks for Reading..!