Speeding up phpMyAdmin

Posted

Here's a quick tip for speeding up phpMyAdmin when using it on a remote server. A big drain on rendering speed for the app seems to be the sheer number of theme related requests (images and stylesheets) the browser makes on every page load. An easy way around this is to use the Apache module mod_expires to send an expires header with these files, which tells the browser not to bother requesting them again for a set period. This cuts down the total requests by about 90%.

Firstly, make sure mod_expires is enabled:

sudo a2enmod expires
sudo apache2ctl restart

then open the phpMyAdmin Apache configuration file (by default in located at /etc/apache2/conf.d/phpmyadmin.conf) in your text editor of choice. You'll see an IfModule block which sets up some php values:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php

        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        php_flag register_globals Off
        php_value include_path .
    </IfModule>
</Directory>

insert the following mod_expires block below the existing </IfModule>:

    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/gif "access plus 7 days"
        ExpiresByType image/jpg "access plus 7 days"
        ExpiresByType image/png "access plus 7 days"
        ExpiresByType text/css "access plus 7 days"
        ExpiresByType application/javascript "access plus 7 days"
    </IfModule>

which should leave you with this:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php

        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        php_flag register_globals Off
        php_value include_path .
    </IfModule>

    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/gif "access plus 7 days"
        ExpiresByType image/jpg "access plus 7 days"
        ExpiresByType image/png "access plus 7 days"
        ExpiresByType text/css "access plus 7 days"
        ExpiresByType application/javascript "access plus 7 days"
    </IfModule>
</Directory>

Restart Apache (sudo apache2ctl restart) so the changes take effect.

What this does is tell Apache to send an expires header of 7 days into the future for all image, CSS and javascript files within phpMyAdmin. The initial request after the restart will be as before, but after that the browser knows that the files it got back are good for 7 days, so on subsequent requests it will only request the HTML page. You should see a noticeable speed improvement.

Normally when using mod_expires you would use a much longer expire time than 7 days, but this way if a future phpMyAdmin update does change these theme files you're less likely to get caught out.

Comments (1)

Comments

Matt
26th Jul, 2011

Thanks. Just what I needed. Now to turn on PHP caching of some sort to speed it up even more.

Comments are closed.