Install Apache2, MariaDB And PHP5 Support In CentOS 7

0
Yesterday I installed CentOS 7 to test it out. Today, I am going to show you how to install LAMP Stack (Linux, Apache2, MySQL (MariaDB) and PHP) in CentOS 7.This tutorial should be brief and simple, and for those who are new to CentOS, should have no problem reading and applying the steps below in their own environments.

In this step-by-step tutorial, I will show you how to install Apache2, then show you how to install MariaDB, an alternative to MySQL and support for PHP5. These servers and packages allow for hosting PHP websites like WordPress, Joomla and other CMSs.

If you haven’t already installed CentOS 7, please check this post I wrote yesterday. It should help you install CentOS 7 via NetInstall. After installing CentOS 7, continue below to install these servers and packages.

 

  • Installing Apache2 Server

 

Apache is a web server. Web servers are programs that manage the distribution of web pages. If you open a web browser on your computer and type www.liberiangeek.net, a web server will go and fetch and retrieve the default index page for liberiageek.net and return it to the client computer to display. There are many web server available today, but Apache is the most popular of them all.

To install Apache in CentOS, run the commands below.

<code>yum -y install httpdcode>

After installing Apache run the commands below to configure it so that it automatically starts up every time you reboot your server. To do that, run the commands below

systemctl enable httpd.service

The commands below will manually start Apache

systemctl start httpd.service

 

  • Installing MariaDB Database Server

 

MariaDB is a database server. Database servers are programs that facilitate storing and manipulation of data or information. Data are stored in databases.

In a client/server setup, the client requests information and the database server goes and retrieve the stored information for the client.

To install MariaDB in CentOS 7, run the commands below

yum -y install mariadb-server mariadb

After installing run the commands below to manually start MariaDB server.

systemctl start mariadb.service

To configure your server to automatically starts MariaDB after reboots, run the commands below.

systemctl enable mariadb.service

Finally, run the commands below create a password for the database root user, remove the temporary database, and enable to security feature.

mysql_secure_installation

When prompted with the choices, always choose the default answers wish is Yes, or Y.

 

  • Enabling PHP5 Support in CentOS 7

 

Finally, the last service we’ll want to enable is PHP5 along with other important modules. PHP5 support allows web server to run and manage PHP5 scripts.

If Apache is to run PHP scripts, then you must install tools and packages to enable PHP support. The commands below to make that possible.

yum -y install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

Restart Apache to enable the new PHP scripts function

systemctl restart httpd.service

 

That’s it!.

 

Before you can access the web server remotely you must enable http port on the firewall. To enable Apache port on the firewall, run the commands below

firewall-cmd --permanent --zone=public --add-service=http

Then reload the firewall using the commands below.

firewall-cmd --reload

 

To test these servers and services, follow the step below.

Apache is the easiest to test. All you have to do is open a web browser and type the computer IP address or host name in it, if Apache default web page is shown, then Apache is up and functioning.

 

Apache default page in centos 7

 

To test PHP support, create a file in the default root directory of Apache which is at /var/www/html.

The add these lines in it and save it. Call it phptest.php.

<?php
phpinfo();
?>

Then open a web browser, and go to the page, ex. http://hostname/phptest.php

 

Testing php 5 in centos 7

 

 

If you see the page below, then PHP is up and functioning.

 

Enjoy!