How to direct phpmyadmin to a subdomain on my site?

January 9, 2015 6.1k views

Hey everyone. Firstly, I've just moved to DigitalOcean from a shared hosting account with another company, so I'm still getting the hang of configuring my server appropriately - so apologies if I'm slow to understand something.

Currently I have phpmyadmin configured and secured on my LAMP stack in Ubuntu, and I can navigate to it in my browser by entering <My IP>/phpmyadmin/

What I'd like to do is emulate how my previous hosting setup managed phpmyadmin. I'd like to access it by heading to the address mysql.<mysitename>.com. I have already set up the A record for my site, but now I need to know how to create a subdomain and have phpmyadmin open on that. How can I accomplish this?

1 Answer

First, disable the phpMyAdmin configuration file that maps /phpmyadmin to /usr/share/phpmyadmin:

sudo a2disconf phpmyadmin

Then, create a new virtual host (/etc/apache2/sites-available/ with the following content:

<VirtualHost *:80>

    DocumentRoot /usr/share/phpmyadmin

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

        <IfModule mod_php5.c>
            <IfModule mod_mime.c>
                AddType application/x-httpd-php .php
            <FilesMatch ".+\.php$">
                SetHandler application/x-httpd-php

            php_flag magic_quotes_gpc Off
            php_flag track_vars On
            php_flag register_globals Off
            php_admin_flag allow_url_fopen Off
            php_value include_path .
            php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
            php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Finally, restart Apache:

sudo service apache2 restart

You should then be able to access phpmyadmin through

Have another answer? Share your knowledge.