Install LAMP on CentOS 7.x (Apache, PHP 7.x, SQL MariaDB 10.x, phpMyAdmin) 2017

This guide shows you how to install a LAMP (Linux, Apache, MySQL, PHP) stack on a CentOS 7 system. In this tutorial I will show you how to install the latest version of php (PHP 7.1), MySQL (MariaDB 10.1), phpMyAdmin (4.6.6) and Apache. This installation guide is only for CentOS 7.x.

LAMP is an archetypal model of web service stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP Server, the MySQL relational database management system (RDBMS), and the PHP programming language. The LAMP components are largely interchangeable and not limited to the original selection. As a solution stack, LAMP is suitable for building dynamic web sites and web applications.

Server updating


1.1 Update server

yum -y update

1.2 Install EPEL Repository

yum -y install epel-release

1.3. Install REMI Repository

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm

1.4. Verify EPEL Repo

yum repolist

 

Install MySQL (MariaDB) server


2.1 Create MariaDB repo

vi /etc/yum.repos.d/MariaDB.repo

2.2. Add the MariaDB YUM repository
Before add yum repository make sure 10.1 is the latest version of MariaDB

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

2.3. Enable REMI repository (change enabled=0 to enabled=1)

vi /etc/yum.repos.d/remi.repo

sample output
[remi]
name=Remis RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

2.4. Install MySQL (MariaDB)

yum -y install mariadb-server mariadb

2.5. Start MySQL (MariaDB)

systemctl start mariadb.service

2.6. Create the system startup link for MySQL (MariaDB) to start MySQL (MariaDB) automatically on the system boot

systemctl enable mariadb.service

2.7 Set passwords for the MySQL (MariaDB) root account:

mysql_secure_installation

sample output

# mysql_secure_installation #

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, well need the current
password for the root user. If youve just installed MariaDB, and
you havent set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): (just press enter here)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] (just press enter here)
New password: (enter new root SQL password)
Re-enter new password: (re-enter new root SQL password)
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] (just press enter here)
... Success!

Normally, root should only be allowed to connect from localhost. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] (just press enter here)
... Success!

By default, MariaDB comes with a database named test that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] (just press enter here)
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] (just press enter here)
... Success!

Cleaning up...

All done! If youve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

Install Apache web server


3.1 Installing Apache

yum -y install httpd

3.2 Start Apache web server

systemctl start httpd.service

3.3. Create the system startup link for httpd to start httpd automatically on the system boot

systemctl enable httpd.service

3.4. CentOS 7.X uses Firewall-CMD, so you must customize it to allow external access to port 80 (http) and 443 (https). Lave this step if you want to stay on IP tables.

systemctl start firewalld
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

3.5 Make sure Apache server is running: http://your.server.ip.adders/

PHP 7.1 installation


4.1. Make sure remi-php71.repo is there

ls /etc/yum.repos.d

smple output
CentOS-Base.repo       CentOS-Vault.repo      remi-php54.repo
CentOS-CR.repo CentOS-fasttrack.repo remi-php70.repo
CentOS-Debuginfo.repo MariaDB.repo remi-php71.repo
CentOS-Media.repo epel-testing.repo remi-safe.repo
CentOS-Sources.repo epel.repo remi.repo

4.2 Enable REMI repository for php7.1 (change enabled=0 to enabled=1)

vi /etc/yum.repos.d/remi-php71.repo

sample output
[remi-php71]
name=Remis PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror
mirrorlist=http://rpms.remirepo.net/enterprise/7/php71/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

4.3. Install PHP

yum -y install php

4.4. Install MySQL Support for PHP7

yum -y install php-mysql

4.5 You can install some common PHP modules that are required by CMS Systems like WordPress, Joomla and Drupal

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

4.6. Restart Apache:

systemctl restart httpd.service

4.7. Let’s test: Create php info file

vi /var/www/html/info.php

add the following lines to info.php
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>

Make sure PHP works and php modules are there http://your.server.ip.address/info.php

phpMyAdmin installation


5.1. Install phpMyAdmin. phpMyAdmin is a web interface through which you can manage your MySQL databases.

yum install phpMyAdmin

5.2 Let’s change the Apache configuration so that phpMyAdmin allows connections not just from localhost.

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

Add the following lines:

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

sample output

# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

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
Require local
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>

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

5.3 Change the authentication in phpMyAdmin config.inc.php from cookie to http:

vi /etc/phpMyAdmin/config.inc.php

smple output
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
/* Server parameters */
[...]

5.4 Restart Apache:

systemctl restart httpd.service

5.5 Make sure phpMyAdmin works. Go to http://your.server.ip.address/phpmyadmin/
Login name: root, Password what you added on step 2.7

Congratilations, you’re done! 🙂

Sources used:
https://www.apache.org/
http://php.net/
https://www.phpmyadmin.net/
https://mariadb.org/

  • TY TY TY TY TY TY, Best ever