Education Series Part 06 – Installing PHP and MySQL in CentOS 7

Note, MySQL is actually called Maria-DB which apparently is a fork of MySQL.  I should also note that my experience with MySQL is very minimal, while I have been able to make my way through it in the past, it was almost always thanks to Google.  This way I can hopefully gain some experience with it.

First we need to install the packages:

# yum -y install mariadb-server mariadb

Next create system start up links so that it starts at boot and begins running now:

# systemctl start mariadb.service
# systemctl enable mariadb.service

Set passwords for MySQL:

# mysql_secure_installation

After this you will be taken through a few steps.  Note that the root password is NOT the root password for the root user of CentOS instead it is for root of MySQL.  Also note that my answers are placed in BOLD RED TEXT.

Enter current password for root (enter for none): ENTER
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization.
Set root password? [Y/n]  Y
New password:
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...

Now it is time to install PHP 5.  

# yum -y install php

Create a simple info.php file in order to view and ensure it’s working/installed correctly

# vi phpinfo.php
<?php
phpinfo() ;
?>

Restart apache service

# systemctl restart httpd.service

Success!!

There is currently no support in my PHP for MySQL so I will need to connect this.

# yum search php

The results are quite large, and since I am not sure exactly what I will be using this for, I am going to attempt to install the most common ones.

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

Restart Apache again:

# systemctl restart httpd.service

Recheck your phpinfo.php page…

URL:  http://sample.com/phpinfo.php

I want to install phpMyAdmin however it does not appear to be in any of the Cent OS 7 repos.  Therefore after quickly checking out Google I have to install a new repo.

# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# yum -y update 
# yum -y install phpmyadmin

Before phpMyAdmin will work we will have to edit the phpMyAdmin.conf file:

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

I commented out the deny commands.  It worked just fine for me.  

<Directory /usr/share/phpMyAdmin/>
 <IfModule mod_authz_core.c>
 # Apache 2.4
 <RequireAny>
 Require ip 127.0.0.1
 Require ip ::1
 </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
 </IfModule>
</Directory>

Next we change the authentication over from cookie to http://

# vi /etc/phpMyAdmin/config.inc.php

Find the following line:

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

Change the line to this:

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

And again I need to restart the apache service:

# systemctl restart httpd.service

Now open up your web browser and access phpMyAdmin

URL:  http://sample.com/phpMyAdmin

To log in use the account:  root and the password you choose when you install MySQL/Maria-DB

Education Series Part 06 – Installing PHP and MySQL in CentOS 7