LAMP on CentOS 7

By | 28 Mar 2015

The most common web platform out there is Linux, Apache, MySQL, and PHP or LAMP for short.  Below is my quick guide for setting up LAMP on CentOS 7 (or RHEL 7).


LAMP Installation

For this configuration CentOS was installed with minimal packages (no GUI) and all commands are run with root privileges.

Package Install

Core components of Apache, MariaDB (MySQL), and PHP.

yum install httpd mariadb-server mariadb php php-mysql

Start

systemctl start httpd
systemctl start mariadb

Secure MariaDB (MySQL)

mysql_secure_installation

Follow the prompts to set a SQL root password and secure the DB server.

Automatic Start Up

systemctl enable httpd.service
systemctl enable mariadb.service

Testing

Verify Apache (httpd) is running by browsing to:  http://<server_ip_address>/

Should look like:
Apache Default

Verify PHP / MariaDB is working with Apache by creating a file info.php in /var/www/html/ with the contents:

<?php phpinfo(); ?>

Browse to: http://<server_ip_address>/info.php

Should look like:
PHP Info

Verify PHP/MySQL linking in above.

Should look like:
PHP MySQL Details


phpMyAdmin install..

phpMyAdmin the most common tool for the administration of MySQL over the web, supporting a wide range of operations on MySQL, and MariaDB. Operations including managing databases, tables, users, permissions, etc. can be performed via the user interface.

yum install epel-release
yum install phpmyadmin

Securing phpMyAdmin

vi /etc/httpd/conf.d/phpMyAdmin.conf

Change any lines that contain “Require ip 127.0.0.1” or “Allow from 127.0.0.1” to refer to your workstations IP address.  The locations in the file that must be changed are:

Require ip your_workstation_IP_address
. . .
Allow from your_workstation_IP_address
. . .
Require ip your_workstation_IP_address
. . .
Allow from your_workstation_IP_address

Restart Apache:

systemctl restart httpd.service

Testing

Browse to http://<server_ip_address>/phpmyadmin


Firewall configuration

Finally it’s time to allow access to your web server.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Leave a Reply

Your email address will not be published. Required fields are marked *