Install Apache, PHP And MariaDB On CentOS

This tutorial shows how you can install an Apache2 webserver on a CentOS 7.0 server with PHP5 support (mod_php) and MariaDB (MySQL fork) support. LAMP is short for Linux, Apache, MySQL, PHP but actualy, it’s a CAMP: CentOS, Apache, MariaDB, PHP.

 Install Apache server:

# yum -y install httpd

after resolving depedencies (apr, httpd tools, mailcap), your server is installed but you have to add firewall configuration:

# firewall-cmd --get-default-zone
public
# firewall-cmd --list-all-zones
...
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules:
...

So, I add http(s) services to the active default zone “public”:

# firewall-cmd --permanent --zone=public --add-service=http 
success
# firewall-cmd --permanent --zone=public --add-service=https 
success
# firewall-cmd --reload
success

Now, you can see it in your browser:

centos_httpd

then, we configure our server to start httpd service at boot time (see enable on status):

# systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: inactive (dead)
# systemctl start httpd.service

 

Install PHP5:

In CentOS 7, the version of PHP is 5.4.16.

# yum -y install php

restart apache server to take effect of change:

# service httpd reload

now, create our first php file:

# touch /var/www/html/info.php
# echo -e "<?php\nphpinfo();\n?>" > /var/www/html/info.php

Load in your browser http://<server>/info.php

 centos_httpd_php

 

Install MariaDB:

Why not MySQL? Perhaps, ever since Oracle bought MySQL a fair number of MySQL users started looking for an alternative, due mainly to doubts that Oracle would be a good steward of a key software project or even if the goal for Maria-DB is to be a drop-in replacement for MySQL, MariaDB has more features and better performance. [1] [2] [3] [4]

So, let’s install it:

yum install mariadb-server

After many dependcies like mariadb (client) and perl packages, I enable at boot time and start it:

# systemctl enable mariadb
 ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
# mysql_secure_installation
 /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
...
Set root password? [Y/n]
New password: <NEW PASSWORD>
Re-enter new password: <NEW PASSWORD>
Password updated successfully!
Reloading privilege tables..
... Success!
...
...
Remove anonymous users? [Y/n] <ENTER>
 ... Success!
Disallow root login remotely? [Y/n] <ENTER>
... Success!
Remove test database and access to it? [Y/n] <ENTER>
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] <ENTER>
... Success!
Cleaning up...

 

To admin SQL DB, I like to use phpmyadmin but by default CentOS 7.0 repositories doesn’t provide any binary package for PhpMyAdmin Web Interface:

# yum -y install https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
# yum search phpmyadmin
# yum install phpmyadmin

Package manager add these dependencies which CMS (WordPress, Drupal, Joomla) want too:

Installed:
 phpMyAdmin.noarch 0:4.2.10-1.el7

Dependency Installed:
dejavu-fonts-common.noarch 0:2.33-6.el7
dejavu-sans-fonts.noarch 0:2.33-6.el7
fontpackages-filesystem.noarch 0:1.44-8.el7
libX11.x86_64 0:1.6.0-2.1.el7
libX11-common.noarch 0:1.6.0-2.1.el7
libXau.x86_64 0:1.0.8-2.1.el7
libXpm.x86_64 0:3.5.10-5.1.el7
libjpeg-turbo.x86_64 0:1.2.90-5.el7
libmcrypt.x86_64 0:2.5.8-13.el7
libpng.x86_64 2:1.5.13-5.el7
libtidy.x86_64 0:0.99.0-31.20091203.el7
libxcb.x86_64 0:1.9-5.el7
libxslt.x86_64 0:1.1.28-5.el7
php-bcmath.x86_64 0:5.4.16-23.el7_0.3
php-gd.x86_64 0:5.4.16-23.el7_0.3
php-mbstring.x86_64 0:5.4.16-23.el7_0.3
php-mcrypt.x86_64 0:5.4.16-2.el7
php-mysql.x86_64 0:5.4.16-23.el7_0.3
php-pdo.x86_64 0:5.4.16-23.el7_0.3
php-php-gettext.noarch 0:1.0.11-10.el7
php-tcpdf.noarch 0:6.0.095-1.el7
php-tcpdf-dejavu-sans-fonts.noarch 0:6.0.095-1.el7
php-tidy.x86_64 0:5.4.16-2.el7
php-xml.x86_64 0:5.4.16-23.el7_0.3
t1lib.x86_64 0:5.1.2-14.el7

Complete!

Now, configure phpMyAdmin to be accessed from our lan by adding a lan network or workstation ip address:

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

<Directory /usr/share/phpMyAdmin/setup/>
  <IfModule mod_authz_core.c>
    # Apache 2.4
    <RequireAny>
      Require ip 127.0.0.1
      Require ip ::1
      Require ip 192.168.12.0/24
    </RequireAny>
  </IfModule>
  <IfModule !mod_authz_core.c>
    # Apache 2.2
    Order Deny,Allow
    Deny from All
    Allow from 127.0.0.1
    Allow from ::1
    Allow from 192.168.12.0/24
  </IfModule>
</Directory>
...

Reload Apache server:

# service httpd reload

 

centos_httpd_phpmyadmin

 

That’s all folks 🙂

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.