Deploy LAMP & phpMyAdmin on RHEL 6.5

lamp

I know there are a ton of articles out there on this topic. But I had a hard time finding one for RHEL 6.5 (NOT CentOS). There are subtle differences that lead to undoubted failure if you solely follow instructions meant for CentOS. So for all you RHEL people out there tasked with this, here you go.

It may or may-not work on different versions/distributions–no guarantee. I’m assuming you’ve installed the base image from ISO with no additional options and are waiting at the command line with privilege and Internet access.

Get your Repositories

Register your box with RHN.

# subscription-manager register --username user --password password

EPEL is required to properly install phpMyAdmin.

# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

The ‘optional’ repository is also needed to properly resolve dependencies.

# yum-config-manager --enable rhel-6-server-optional-rpms

Validate your repositories. Something like this should be displayed:

# yum repolist
repolist

Prep Steps

Update Server
# yum update -y
# reboot
Disable Firewall

I like to disable the local firewall, I use my hardware firewall for that. Modify iptables if the local firewall is something you want to do. There’s plenty on that out there.

# service iptables stop
# chkconfig iptables off
Install Apache
# yum install -y httpd
# service httpd start
# chkconfig httpd on
Validate Apache
# curl localhost | grep test

The HTML content will be visible from the test page here if everything went well.

Install PHP

Optionally install php-mysql if your application requires MySQL support with PHP.

# yum install -y php
# yum install -y php-mysql (optional)

Create a test PHP page.

# echo '<?php phpinfo() ; ?>' > /var/www/html/test.php

Validate the content loads. The command will display content based on your PHP config and versions.

# curl localhost/test.php

Remove the test page for security purposes

# rm -f /var/www/html/test.php
Install and start MySQL
# yum install -y mysql mysql-server
# service mysqld start
# chkconfig mysqld on

Secure and setup MySQL by running the vendor script. Press Enter at each prompt and set the root password when asked.

# mysql_secure_installation
Install phpMyAdmin (Optional)

PHPmyadmin is a GUI frontend for MySQL database management.

# yum install -y phpmyadmin

Configure remote access to phpmyadmin by editing the following file:

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

Do a search and replace for 127.0.0.1 and change to the IP you will use to manage MySQL through a browser, or add a subnet. In my case everything on my internal network starts with 10.x.x.x, so I did the following.

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 10.0.0.0/8
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 10.0.0.0/8
     Allow from ::1
   </IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 10.0.0.0/8
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 10.0.0.0/8
     Allow from ::1
   </IfModule>
</Directory>

Change authentication type to http.

# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php 
# vi /usr/share/phpMyAdmin/config.inc.php

Change cookie to http

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

Finish Up

I like to reboot for good measure, making sure your services start on their own and are functional.

# reboot

Finally, open a browser on the machine you allowed in the steps above and browse to the following:

http://mylampserver/phpmyadmin 

Log in with the root user you created for MySQL.

That’s it, enjoy!!

Deploy LAMP & phpMyAdmin on RHEL 6.5