Install latest version of apache, mariadb and php on CentOS7

In one of out previous tutorials Install LAMP on CentOS we looked at installing LAMP on CentOS 7. Although this type if installation is fine for most of the deployments, in some cases you want to get the latest version of LAMP components. In most cases we will want to do this due to security concerns or new features available.

The above type of installation will give us the following version numbers.

php -v
5.4.6 php
httpd -v
2.4.6
mysql -V
5.5.56

Now lets see how we would setup the same LAMP server with latest LAMP stack.

Prerequisites

CentsOS 7 installed with latest updates and connected to the internet.

yum update -y 

Installation

Apache web server

yum install wget -y
yum install -y epel-release
cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo
yum install httpd
systemctl start httpd
systemctl enable httpd

MariaDB database

vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum install MariaDB-server MariaDB-client -y
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
mysql_secure_installation

PHP

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y mod_php71w php71w-cli php71w-common php71w-gd php71w-mbstring php71w-mcrypt php71w-mysqlnd php71w-xml

Restart apache srever

systemctl restart httpd 

Lets check out Version numbers

Apache

httpd -v
Server version: Apache/2.4.29 (codeit)
Server built:   Nov  3 2017 14:01:58

MariaDB

mysql -V
mysql  Ver 15.1 Distrib 10.1.30-MariaDB, for Linux (x86_64) using readline 5.1

PHP

php -v
PHP 7.1.13 (cli) (built: Jan 14 2018 09:55:02) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Performance Optimization

if you notice problems with performance one of the first things to look at is Apache MPM. MPM can have one of three modules enabled

  • Prefork
  • Worker
  • Event
  • In order to determine which module is enable run command below.

    httpd -V | grep -i 'version\|mpm'
    Server version: Apache/2.4.29 (codeit)
    Server MPM:     worker
    

    In order to activate one or the other you will need to edit configuration file for MPM

    /etc/httpd/conf.modules.d/00-mpm.conf