CentosInstallPHPMyAdmin

== Install phpmyadmin on Centos 6 ==

If there is one thing that I do not understand, it's the appeal of PHPMyAdmin. Mix PHP, probably the worst scripting language **ever** with Mysql, probably the worst open-source database, and what do you get? A freaking security hole, that's what!

Anyway, some... ahem... "users" at my job only swear by thie piece of crap, so I had to install a Centos 6.4 machine for them. Yeah, they like crap but they don't want to install it -- surprising, I know.

The other problem is that these... ahem... "users" (I am trying very hard to stay polite, here!!) want to use the same phpmyadmin server to connect to different Mysql servers in different LANs. Oh joy.

So: there it is, how to install a phpmyadmin server on a Centos 6.4 machine... And connect from this phpmyadmin to different Mysql servers:

==== 1. Make sure your PHP is up to date ====

Here is the saving grace of Centos: {{{yum}}} is your friend. Enter the following as user {{{root}}} and you should be OK...:

{{{ # yum update }}}

Then, make sure you install the following PHP packages that are required by phpmyadmin:

{{{ $ rpm -qa | grep -i php php-mcrypt-5.3.3-1.el6.x86_64 php-common-5.3.3-22.el6.x86_64 php-cli-5.3.3-22.el6.x86_64 php-gd-5.3.3-22.el6.x86_64 php-xml-5.3.3-22.el6.x86_64 php-devel-5.3.3-22.el6.x86_64 php-pdo-5.3.3-22.el6.x86_64 php-mbstring-5.3.3-22.el6.x86_64 php-pear-1.9.4-4.el6.noarch php-5.3.3-22.el6.x86_64 php-mysql-5.3.3-22.el6.x86_64 }}}

**//PLEASE NOTE//** In order to install {{{php-mcrypt-5.3.3-1.el6.x86_64}}}, you need to enable the EPEL repository on your server. To do this, follow the procedure shown below:

- Download and install the EPEL RPM, with the following commands as {{{root}}}:

{{{ # wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -ivh ./epel-release-6-8.noarch.rpm }}}

- List all repositories configured in {{{yum}}} and make sure EPEL is shown in that list, with:

{{{ # yum repolist }}}

Here is the result of that command on my machine:

{{{ $ yum repolist Loaded plugins: fastestmirror, security Determining fastest mirrors epel/metalink | 19 kB 00:00 * base: centos.mirror.fr.planethoster.net * epel: mirrors.ircam.fr * extras: centos.mirror.fr.planethoster.net * updates: miroir.univ-paris13.fr base | 3.7 kB 00:00 epel | 4.2 kB 00:00 epel/primary_db | 5.0 MB 00:00 extras | 3.5 kB 00:00 updates | 3.5 kB 00:00 updates/primary_db | 1.5 MB 00:00 repo id repo name status base CentOS?-6 - Base 6,381 epel Extra Packages for Enterprise Linux 6 - x86_64 8,614 <--- there it is! extras CentOS?-6 - Extras 12 updates CentOS?-6 - Updates 497 repolist: 15,504 }}}

- Finally, install {{{php-mcrypt}}} with the following command:

{{{ # yum install php-mcrypt }}}

The command above installs {{{php-mcrypt}}} and {{{libmcrypt}}}

You are now in business, as far as the PHP side of things is concerned...

**//PLEASE NOTE//** I do not mention, on this little page, that you also need to install Apache (and friends) in order to run phpmyadmin, but I suppose you already know how to do that. If not, please see the "See Also" section below for more information on how to do that.

==== 2. Assign more memory to PHP ====

I have found out the hard way that phpmyadmin crashes hard if you do not give PHP enough memory to play with.

So, if you find yourself with the following errors in you Apache log:

{{{ [Mon Apr 08 18:04:24 2013] [error] [client 10.196.1.174] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted \ (tried to allocate 32 bytes) in /var/www/html/phpmyadmin/libraries/session.inc.php on line 89 [Mon Apr 08 18:04:34 2013] [error] [client 10.196.1.174] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted \ (tried to allocate 32 bytes) in /var/www/html/phpmyadmin/libraries/session.inc.php on line 89 [Mon Apr 08 18:05:16 2013] [error] [client 10.196.1.174] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted \ (tried to allocate 32 bytes) in /var/www/html/phpmyadmin/libraries/session.inc.php on line 89, referer: http://10.226.6.136/ }}}

You will also find yourself with an unresponsive phpmyadmin... Typically, a completely white and empty web page after only a couple of connections.

First things first: stop the Apache server properly with:

{{{ # /etc/init.d/httpd stop }}}

Then, edit the {{{/etc/php.ini}}} file, and look for the following line:

{{{ memory_limit = 128M }}}

And replace it by:

{{{ memory_limit = 512M }}}

Save the {{{/etc/php.ini}}} file, restart Apache, and you should be OK.

==== 3. Install phpmyadmin itself ====

That's reasonably simple: go here and click on the latest version to download it. Copy the file onto the server and enter, for instance:

{{{ # tar xvjf /path/to/phpMyAdmin-3.5.8-all-languages.tar.bz2 -C /var/www/html }}}

In the example above, remember to replace {{{/path/to/}}} by the path to your phpmyadmin archive and {{{/var/www/html/}}} by the path to your Apache document directory.

Now, create a link if needed:

{{{ # ln -v --symbolic ./phpMyAdmin-3.5.8-all-languages/ ./phpmyadmin }}}

By making Apache point to (for instance) {{{/var/www/html/phpmyadmin}}} (instead of the version number) you can upgrade reasonably quickly your installation of phpmyadmin.

Now, go into the directory and enter the following commands to create the initial configuration directory:

{{{ # cd /var/www/html/phpmyadmin # mkdir -v ./config # chmod -Rfv o+rw ./config }}}

Then, launch the installation procedure, as described here. The GUI of phpmyadmin is confusing, badly organized and even a bit buggy at times, so make sure you repeatedly click on the {{{SAVE}}} button to store your choices!

The biggest task during the installation is to configure a Mysql server to connect to - make sure, again, that you include all information necessary to connect to the server and click on the {{{SAVE}}} button to conserve your parameters.

Once the configuration is done, enter the following to copy the phpmyadmin configuration file and delete the {{{config}}} directory:

{{{ # cp -v ./config/config.inc.php . # rm -Rfv ./config }}}

Then restart the Apache server with:

{{{ # /etc/init.d/httpd restart }}}

You are done! At least one server is now configured under phpmyadmin and - if your configuration is correct - you should be able to connect to it through the web interface.

==== 4. Adding more servers ====

That is simple enough, but it requires a bit of file editing. Open the file named {{{config.inc.php}}} that was created at the previous step with your favourite texte editor.

It should look a little bit like this:

{{{ <?php /* * Generated configuration file * Generated by: phpMyAdmin 3.5.8 setup script * Date: Mon, 15 Apr 2013 17:17:46 +0200 */

/* Servers configuration */ $i = 0;

/* Server: GALACTUS SQL - [1] */ $i++; $cfg['Servers'][$i]['verbose'] = 'GALACTUS SQL -'; $cfg['Servers'][$i]['host'] = '10.226.6.15'; $cfg['Servers'][$i]['port'] = ''; $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['user'] = 'phpmyadmin'; $cfg['Servers'][$i]['password'] = 'here_is_the_password'; $cfg['Servers'][$i]['ssl'] = true;

/* End of servers configuration */

$cfg['blowfish_secret'] = '516c1747b3f6f9.64576859'; $cfg['UploadDir?'] = ''; $cfg['SaveDir?'] = ''; $cfg['DefaultLang?'] = 'en'; $cfg['ServerDefault?'] = 1; $cfg['ForceSSL?'] = true; ?> }}}

To add a server, simply duplicate the lines and replace the values. You should end up with something like this:

{{{ <?php /* * Generated configuration file * Generated by: phpMyAdmin 3.5.8 setup script * Date: Mon, 15 Apr 2013 17:17:46 +0200 */

/* Servers configuration */ $i = 0;

/* Server: GALACTUS SQL - [1] */ $i++; $cfg['Servers'][$i]['verbose'] = 'GALACTUS SQL -'; $cfg['Servers'][$i]['host'] = '10.226.6.15'; $cfg['Servers'][$i]['port'] = ''; $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['user'] = 'phpmyadmin'; $cfg['Servers'][$i]['password'] = 'here_is_the_password'; $cfg['Servers'][$i]['ssl'] = true;

/* Server: SURFER SQL - [2] */ $i++; $cfg['Servers'][$i]['verbose'] = 'SURFER SQL -'; $cfg['Servers'][$i]['host'] = '10.226.6.16'; $cfg['Servers'][$i]['port'] = ''; $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['user'] = 'phpmyadmin'; $cfg['Servers'][$i]['password'] = 'here_is_another_password'; $cfg['Servers'][$i]['ssl'] = true;

/* End of servers configuration */

$cfg['blowfish_secret'] = '516c1747b3f6f9.64576859'; $cfg['UploadDir?'] = ''; $cfg['SaveDir?'] = ''; $cfg['DefaultLang?'] = 'en'; $cfg['ServerDefault?'] = 1; $cfg['ForceSSL?'] = true; ?>

}}}

Modifying the file as show above will add another server to the phpmyadmin configuration and allow you to choose which server to connect to when opening the main page.

**//PLEASE NOTE//** - All your credentials are stored in the clear in the file above... Make sure your "users" (or wily hackers) cannot access this file or you may find yourself in trouble!!

==== 5. Debugging the whole thing ====

If you experience problems, my advice is to try creating a ''phpmyadmin'' administrator on the distant machine (authorizing connections only from the phpmyadmin server). This can be accomplished with the following commands, as and administrator under Mysql:

{{{ mysql> select user, host from mysql.user; +------+--------------+ | user | host | +------+--------------+ | root | 127.0.0.1 | | root | edc2inttst01 | | root | localhost | +------+--------------+ 3 rows in set (0.00 sec) }}}

The above ouput is fairly standard based on the

Now to create the user itself, limited to the IP address of the phpmyadmin server:

{{{ mysql> create user 'phpmyadmin'@'10.226.6.136' identified by 'what-a-long-password' ; Query OK, 0 rows affected (0.00 sec) }}}

Check the user creation:

{{{ mysql> select user, host from mysql.user; +------------+--------------+ | user | host | +------------+--------------+ | phpmyadmin | 10.226.6.136 | | root | 127.0.0.1 | | root | edc2inttst01 | | root | localhost | +------------+--------------+ 4 rows in set (0.00 sec) }}}

Now, make the phpmyadmin user an administrator:

{{{ mysql> grant all privileges on *.* to 'phpmyadmin'@'10.226.6.136' with grant option; Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) }}}

Next, try to login from the phpmyadmin server to the distant machine using the {{{mysql}}} command, as follows: {{{mysql -h distant_mysql_server -u phpmyadmin -p'what-a-long-password'}}}.

If this works, then your phpmyadmin installation should be able to do the same. If not, check the connections and firewalls.

If everything fails, I do recommend skipping phpmyadmin completely, and use instead of the SQL client that connects through SSH. These exist on almost every platform. For instance, here is a short selection of SQL client that I have tested and found to be pretty good:

Hope this helps!

== See Also: ==