How to direct phpmyadmin to a subdomain on my site?

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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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