Linux, Tutorials

How to install Apache, PHP 7.1 and MySQL on CentOS 7.3 (LAMP)

In this quick tutorial I will show you how to install an Apache web server on CentOS 7 server with PHP and MySQL support. LAMP stands for Linux Apache MySQL PHP. There are also Windows and Mac variations of this named WAMP and MAMP respectively.

To start, we will have to add the EPEL repo to install the latest phpMyAdmin:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* yum -y install epel-release

In case you are on a fresh install of CentOS, we will need to install a tool to do some file editing. For the purposes of this tutorial we will use nano:

yum -y install nano

Install MySQL

We are now ready to install MySQL / MariaDB. What’s MariaDB? MariaDB is a fork of MySQL by the original MySQL developer Monty Widenius. We will be using MariaDB which is fully compatible with MySQL

yum -y install mariadb-server mariadb

Next we need to create system startup links for MySQL and also start the MySQL Server:

systemctl start mariadb.service systemctl enable maraidb.service

We will now perform the initial setup for MySQL


Next, you will be presented with some options. You can accept the defaults for these, be sure to pick a password you will remember.

Install Apache

The apache installation is pretty straight forward.

yum -y install httpd

After the installation completes, we will need to add Apache to start at boot time

systemctl start httpd.servicesystemctl enable httpd.service

Next we have to ensure that the firewall is not blocking incoming connections to port 80 and 443 http and https respectively.

firewall-cmd --permanent --zone=public --add-service=httpfirewall-cmd --permanent --zone=public --add-service=httpsfirewall-cmd --reload

You should now be able to direct your browser to the IP address of your server and you should see the following:

Install PHP

For the purposes of this tutorial we are going to install PHP 7.1, just be aware that there are other versions such as 5.4 or 7.0 to choose from.

Lets add the Remi CentOS repository

rpm -Uvh

We will now install the yum-config-manager which is part of yum-utils

yum -y install yum-utils

Now lets update ym

yum update

Finally, we can install PHP:

yum-config-manager --enable remi-php71yum -y install php php-opcache

We now have to restart Apache

systemctl restart httpd.service


Install MySQL Support in PHP

To use MySQL with PHP we have to install the php71w-mysql package. It’s also not a bad idea to install some other modules while we’re at it.

yum -y install php71w-mysql

Next lets install some commonly used PHP modules that are required by CMS systems like WordPress and Joomla.

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

Now we need to restart Apache for the new modules to be activated.

systemctl restart httpd.service


Install phpMyAdmin

phpMyAdmin is a web interface to manage databases and users for MySQL which makes management quick and simple.

yum -y install phpMyAdmin

After the install completes, we have to do just a little bit of configuring.

nano /etc/httpd/conf.d/phpMyAdmin.conf

You’ll need to comment out the RequireAny and Require IP statements as well as add the Require all granted line. The changes are highlighted in the text below:

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
 AddDefaultCharset UTF-8

 <IfModule mod_authz_core.c>
 # Apache 2.4
 # <RequireAny>
 # Require ip
 # Require ip ::1
 # </RequireAny>
 Require all granted
 <IfModule !mod_authz_core.c>
 # Apache 2.2
 Order Deny,Allow
 Deny from All
 Allow from
 Allow from ::1

<Directory /usr/share/phpMyAdmin/>
        Options none
        AllowOverride Limit
        Require all granted

To save the file press Control – X and you will be asked to save, just press Y

We are going to change the authentication method from cookies to http

nano /etc/phpMyAdmin/
$cfg['Servers'][$i]['auth_type']     = 'http';    // Authentication method (config, http or cookie based)?

To save the file press Control – X and you will be asked to save, just press Y

Finally, we need to restart Apache one last time

systemctl restart httpd.service

You should now be able to access phpMyAdmin using your servers IP address

To login, you would use the username root and the password you setup during the MySQL installation portion of the tutorial.

So that’s it, this tutorial was mostly just a reference for myself. I’m always setting these up and every time I do I end up searching google for a tutorial, well now I can just come here. If you guys have questions or comments, please feel free to leave those below.

Thanks for stopping by.

Tagged , , , , , , , , , ,

Leave a Reply