Blog

Recent Posts with phpMyAdmin tag

Installing the necessary software on an AWS Amazon Linux AMI server

There is a variety of software you will need to get your new AWS web server up and running. You probably already have the desktop clients if you every did any server work previously, the core server software however will need to be installed, depending on your purposes for the server. This page will be updated from time to time as new installation and configuration guides are added.

Desktop Clients

SoftwareDescriptionAvailable at:Documentation
  Free SSH client. Utilizes basic command line style interface   |
  Free SCP/SFTP/FTP client for Windows. Offers a graphical user interface to move and edit files.    

I am bias to Windows software. All of these programs run on Windows XP and Windows 7 (32-bit & 64-bit systems). If you are running a Linux or Mac system....well...they may work. The program's name link will go to instructions on configuring the software to access your AWS Instance.

Core Server Software

SoftwareUsageDescriptionDocumentation
Apache2 Website hosting The basic web server which deals with internet (http/https) traffic to the server.  
PHP Dynamic Websites (optional) Requires:Apache2 Scripting language for creating dynamic webpages. Used by most CMS, Wiki & Blog systems to manage content  
MySQL Database The basic free SQL database server. Used by many CMS, Wiki & Blog systems to store content.  
phpMyAdmin Database Administration (optional) Requires:Apache2, PHP & MySQL Graphical, HTML based admin tool for accessing and managing mySQL databases.  
Postfix Mail-Transfer-Agent (ie: email server) Accepts and sends email. Versatile and can be used with a variety of database structures.  
Courier Email Client Portal (optional) Requires:Postfix Offers a portal to access email via any client, including MS Outlook, Thunderbird & smart phones. Offers IMAP and POP3 systems.  
Spamassassin Email Spam filter (optional) Requires:Postfix Works with MTAs to prevent spam from arriving on server  
BIND9 DNS Server (optional) DNS server which allows you to create your own dns records.  

Note all of these programs are free, and most are open source. All of the installation instructions are specific to the Amazon Linux AMI. This stripped down version of Linux is a special Amazon derivative of Fedora. When I was originally setting up our servers, some of the differences between RedHat, Ubuntu, Debian and this version of Linux drove me crazy, therefore all of these instructions worked on the newest Amazon Linux AMI version (currently 2012.03).

Installing and Configuring phpMyAdmin on AWS Amazon Linux AMI running Apache2 PHP and MySQL

 This is actually really easy, assuming you are using the base version of PHP (5.3.X) from the AWS package repository. YUM has phpMyAdmin as a package and most of the default settings work just fine. The first time I install on an AWS instance it took maybe 15 minutes to complete.

Installing phpMyAdmin

These instructions assume you have already setup an AWS instance and have an SSH client (like PuTTY) available and a SCP client (like WinSCP) to use when editing the configuration files.

  1. Log in to your instance via the SSH client. Transfer to the root user ("sudo su").
  2. Use YUM to install phpMyAdmin
  3. Press "Y" when it asks if you want to install phpMyAdmin
  4. Open the SCP client and go to the apache2 configuration files directory (default is "/etc/httpd/conf.d")
  5. Open the "phpMyAdmin.conf" file.
  6. Add an access exception to apache2 authentication protocol. There are three safe ways to allow access to phpMyAdmin;
    1. Allow Exception from a static IP Address Under the Directory tag "/usr/share/phpMyAdmin/", add the following line at the end of the tag, "Require ip XXX.XXX.XXX.XXX" and the following line at the end of the tag, "Allow from XXX.XXX.XXX.XXX". In each situation you should be replace XXX.XXX.XXX.XXX with the actual IP address.
    2. Allow access from a VPN You will need a Virtual Private Network setup already, which is well beyond these instructions. Under the Directory tag "/usr/share/phpMyAdmin/", add the following line at the end of the tag, "Require ip XXX.XXX.XXX.XXX" and the following line at the end of the tag, "Allow from XXX.XXX.XXX.XXX". In each situation you should be replace XXX.XXX.XXX.XXX with the actual IP address.
    3. Use SSL Certificate for authentication These instructions are not complete yet.
  7. Save the edited "phpMyAdmin.conf" file.
  8. Verify the installation occurred correctly by starting/restarting the httpd service (in SSH "service httpd restart")

Summary of command line inputs

  • $ sudo su
  • $ yum install phpmyadmin
  • .....
  • Do you want to install phpMyAdmin 5.x (Y/N): Y
  • $ service httpd restart

First few lines of phpMyAdmin.conf file with default installation path, edited for access by a single 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/>
  • <IfModule mod_authz_core.c>
  • # Apache 2.4
  • <RequireAny>
  • Require ip 127.0.0.1
  • Require ip ::1
  • Require ip XXX.XXX.XXX.XXX
  • </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 XXX.XXX.XXX.XXX
  • </IfModule>
  • </Directory>
  • ...

Configuring phpMyAdmin

The default configuration of phpMyAdmin needs only a few changes to get it working correctly.

  1. Log in to your instance via the SCP client (like WinSCP)
  2. Open the phpMyAdmin base directory (default AWS installation directory is "/usr/share/phpMyAdmin")
  3. Open the file "config.sample.inc.php"
  4. Go down to the line "$cfg['blowfish_secret'] = 'XXXXXXXX';" where XXXXXX is some alphanumeric combination. Add a bunch more letters and numbers within the single quotes.
  5. Go down to the line "$cfg['Servers'][$i]['controlhost']" and make sure it is uncommented. After it, add "= 'localhost';"
  6. The next line should be "$cfg['Servers'][$i]['controluser']"and make sure it is uncommented. After it, add "= 'USERNAME';" where USERNAME is the username you want to log into phpMyAdmin using.
  7. The next line should be "$cfg['Servers'][$i]['controlpass']"and make sure it is uncommented. After it, add "= 'PASSWORD';" where PASSWORD is the password associated with the previously entered username.
  8. Save the file as "config.inc.php".
  9. Use YUM to install phpMyAdmin
  10. Press "Y" when it asks if you want to install phpMyAdmin
  11. Open the SCP clint and go to the apache2 configuration files directory (default is "/etc/httpd/conf.d")
  12. Open the "phpMyAdmin.conf" file.
  13. Direct your browser to "http://XXX.XXX.XXX.XXX/phpMyAdmin" where XXX.XXX.XXX.XXX is the IP address of your server. You should be prompted for a username and login. Enter the pair you just saved in the config file and you should run phpMyAdmin.

Error with phpMyAdmin 3.5.4 showing Blank Screen

Earlier this week, I was going to update some database tables and attempted to log in to phpMyAdmin when I got a blank screen. If you've ever programed much in PHP, a blank screen almost always means one of two things:

  1. You never accessed the PHP file
  2. The PHP Script had a fatal error and error codes are set to off

After some debugging (detailed below) it turns out phpMyAdmin v3.5.4 has a fatal error where the script files are loaded in the wrong order. With PHP errors fully on, PHP kicked "Fatal error: Call to undefined function PMA_sanitize() in /usr/share/phpMyAdmin/libraries/Message.class.php on line 540". All it took to fix was adding a line to call the sanitizing libraries before allowing the message class to be loaded. Hopefully Amazon's repository will be updated with v3.5.5 soon, so no one else encounters this problem.

Debugging Blank Screen

Accessing the PHP Issue

For me, I found out after the fact that this step was not even necessary, but that is how debugging goes.

  1. Log into your AWS via SCP (like WinSCP)
  2. Find you installation of phpMyAdmin (the default YUM installed phpMyAdmin on an AWS Linux system is /usr/share/phpMyAdmin)
  3. Open the file "index.php" and add the following two lines on two new lines directly after the "
    • echo "I AM phpMyAdmin";
    • exit;
    • /* vim: set expandtab sw=4 ts=4 sts=4: */
    • /**
  4. Attempt to access phpMyAdmin as you normally would. You should see a white screen with "I AM phpMyAdmin" on it. If you do, delete the two lines you just added, save the file and try to access phpMyAdmin again. If you get a blank screen this time then skip to the next section, since the web server is accessing phpMyAdmin.
  5. Log into your AWS server via a SSH client (like PUTTY)
  6. Type "sudo su" to transfer to the root user
  7. Restart the Apache2 web server (type "service httpd restart"). You should get two "OK"s
  8. Attempt to access phpMyAdmin as you normally would. You should see a white screen with "I AM phpMyAdmin" on it. If you do, delete the two lines you just added, save the file and try to access phpMyAdmin again. If you get a blank screen this time then skip to the next section, since the web server is accessing phpMyAdmin.
  9. Open the "phpMyAdmin.conf" file for apache2. The default AWS Linux location is /etc/httpd/conf.d/phpMyAdmin.conf.
  10. The default installation prevents everything but the localhost from accessing phpMyAdmin. Most likely you will add an exception for your computer's IP address, or that of your VPN system. DO NOT, as per phpMyAdmin's instructions, add the line "Require 0.0.0.0" or "Allow All" or "Allow 0.0.0.0". All three of these settings create significant security holes. The resilience to brute force attacks is minimal and you will be hacked eventually.
  11. Restart the Apache2 web server (type "service httpd restart"). You should get two "OK"s
  12. Attempt to access phpMyAdmin as you normally would. You should see a white screen with "I AM phpMyAdmin" on it. If you do, delete the two lines you just added, save the file and try to access phpMyAdmin again. If you get a blank screen this time then skip to the next section, since the web server is accessing phpMyAdmin.
  13. Remove phpMyAdmin and reinstall it.

Identifying Fatal PHP Error

These steps identified the real problem and allowed for the quick patch.

  1. Log into your AWS server via a SCP client (like WinSCP)
  2. Open the apache2 configuration file for phpMyAdmin ("/etc/httpd/conf.d/phpMyAdmin.conf") and add the following lines to the "" then save the file.
    • php_admin_flag engine on
    • php_admin_value display_errors on
    • php_admin_value error_reporting 30711
    • php_admin_flag ini_set on
  3. Log in to your AWS server via SSH and restart apache2 ("service httpd restart")
  4. Attempt to access phpMyAdmin as you normally would. Instead of a blank screen, you should get an error message along the lines of "Fatal error: Call to undefined function PMA_sanitize() in /usr/share/phpMyAdmin/libraries/Message.class.php on line 540"
  5. Open the file "/usr/share/phpMyAdmin/libraries/Message.class.php"
  6. At the top of the header comments, add the line "require_once('./libraries/sanitizing.lib.php');"
  7. Save the Message.class.php file.
  8. Attempt to access phpMyAdmin as you normally would. It should work fine now. If you want to, you can go back to the apache2 phpMyAdmin configuration file (/etc/httpd/conf.d/phpMyAdmin.conf) and remove the lines you entered. If you have a public installation of phpMyAdmin, then you should remove them for security reasons.