How To Set Up Linux, Apache, MariaDB, PHP (LAMP) Stack on CentOS 7.0


This article will walk you through the steps to install and configure LAMP Stack on CentOS 7.0. These steps can also be performed on Red Hat Enterprise Linux if you are not using CentOS in your environment.


Install Apache Web Server

This tutorial assume that you have already performed a initial system installation and configuration of your CentOS 7.0 Server. You can begin installing Apache package provided form official repositories using the following command.
yum install httpd
systemctl start httpd
Allow Apache web service from CentOS builtin firewall using the following command.
firewall-cmd --permanent --add-service=http
systemctl restart firewalld
Verify your Apache web service using http://your_centos_server_ip in any browser and a default page should appear like in the screenshot below.


Install PHP

Before installing PHP dynamic language support for Apache, get a full list of available PHP modules and extensions using the following command.
yum search php
For a basic MariaDB support in PHP and PhpMyAdmin you need to install the following php modules.
yum install php php-mysql php-pdo php-gd php-mbstring
To test PHP installation, create a info.php file on Apache Document Root using the following command and then restart httpd service. 
echo "" > /var/www/html/info.php
systemctl restart httpd
Now access http://your_centos_server_IP/info.php in any browser and the following screen should appear.



Install MariaDB Database

You can install MariaDB database using the following command.
yum install mariadb-server mariadb
Once MariaDB package is installed, start database daemon and use mysql_secure_installation script to secure database (set root password, disable remotely logon from root, remove test database and remove anonymous users).
systemctl start mariadb
mysql_secure_installation
To test database functionality, login to MariaDB using its root account and exit using quit statement.
mysql -u root -p
MariaDB > SHOW VARIABLES;
MariaDB > quit


Install PhpMyAdmin

By default official CentOS 7.0 repositories doesn’t provide any binary package for PhpMyAdmin Web Interface but still you can install PhpMyAdmin package by enabling CentOS 7.0 rpmforge repositories using the following command.
yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
After enabling rpmforge repository, install PhpMyAdmin.
yum install phpmyadmin
Configure PhpMyAdmin to allow connections from remote hosts by editing phpmyadmin.conf file, located on Apache conf.d directory, commenting the following lines.
nano /etc/httpd/conf.d/phpmyadmin.conf
Comment these lines as below
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
To be able to login to PhpMyAdmin Web interface using cookie authentication method add a blowfish string to phpmyadmin config.inc.php file using the generate a secret string, restart Apache Web service and access the URL address http://your_centos_server_IP/phpmyadmin/ in any browser
nano /etc/httpd/conf.d/phpmyadmin.conf
systemctl restart  httpd


Make LAMP Startup Persistent

If you need MariaDB and Apache services to be automatically started after reboot type the following commands to enable them system-wide.
systemctl enable mariadb
systemctl enable httpd
You are done.
Powered by Blogger.