Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Hi I'm currently working on setting up a VirtualHost on Amazon EC2 for accessing phpmyadmin so i can access it with test.example.com as oppose to it being widely available as it's default example.com/phpmyadmin.

So far I've created a file "testfile" in /etc/apache2/sites-available/ with the code below and enabled it "a2ensite testfile" However I'm not getting the vhost to work

<VirtualHost *:80>
            ServerAdmin webmaster@example.com

            ServerName test.example.com
            ServerAlias test.example.com

            #DocumentRoot /usr/share/phpmyadmin
            DocumentRoot /home/user/public_html/folder

            RewriteEngine On
            RewriteCond %{HTTP_HOST} !test.example.com
            RewriteRule (.*) [L]


            <Directory /home/user/public_html/folder>

                    Options FollowSymLinks
                    DirectoryIndex index.php
                    AllowOverride None

                    <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_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/
                    </IfModule>

            </Directory>
     # Authorize for setup
            <Directory /usr/share/phpmyadmin/setup>
                <IfModule mod_authn_file.c>
                AuthType Basic
                AuthName "phpMyAdmin Setup"
                AuthUserFile /etc/phpmyadmin/htpasswd.setup
                </IfModule>
                Require valid-user
            </Directory>

            # Disallow web access to directories that don't need it
            <Directory /usr/share/phpmyadmin/libraries>
                Order Deny,Allow
                Deny from All
            </Directory>
            <Directory /usr/share/phpmyadmin/setup/lib>
                Order Deny,Allow
                Deny from All
            </Directory>

            ErrorLog /home/user/public_html/folder/logs/error.log
            LogLevel warn
            CustomLog /home/user/public_html/folder/logs/access.log combined

    </VirtualHost>

sudo ln -s /usr/share/phpmyadmin /home/user/public_html/folder

The above line creates a link of the phpmyadmin in the public folder.

Any help on this would be greatly appreciated.

Note: example.com will be replaced with my official domain

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

After hours of testing and trouble shooting here is the solution.

First ensure that you created an A record in your DNS manger to point your sub domain "test.example.com" to your server IP (this should take roughly 24-72 hours to propagate).

Then create your host file with the following command (please note I'm using ubuntu which uses individual host files but you can add this to you main host file):

sudo vi /etc/apache2/sites-available/test.example.com

Add the following data below (I've enabled ssl on my system which is port 443 and un-contentmented the ssl section at the end):

<VirtualHost *:80>

    ServerAdmin webmaster@example.com

    DocumentRoot /usr/share/phpmyadmin
    ServerName test.example.com

    RewriteEngine On
        RewriteCond %{HTTP_HOST} !test.example.com
        RewriteRule (.*) [L]

     <Directory /usr/share/phpmyadmin>

        Options Indexes FollowSymLinks
            AllowOverride None
        deny from all
        allow from localhost
        #allow access via your IP
            allow from xxxxxx.xxxxx.xxxxxxx.xxxxxxxxx/xx

        <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_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/
        </IfModule>

    </Directory>

    # Authorize for setup
    <Directory /usr/share/phpmyadmin/setup>
        <IfModule mod_authn_file.c>
        AuthType Basic
        AuthName "phpMyAdmin Setup"
        AuthUserFile /etc/phpmyadmin/htpasswd.setup
        </IfModule>
        Require valid-user
    </Directory>

    # Disallow web access to directories that don't need it
    <Directory /usr/share/phpmyadmin/libraries>
        Order Deny,Allow
        Deny from All
    </Directory>
    <Directory /usr/share/phpmyadmin/setup/lib>
        Order Deny,Allow
        Deny from All
    </Directory>

    #   SSL Engine Switch:
        #   Enable/Disable SSL for this virtual host.
       # SSLEngine on

        #   A self-signed (snakeoil) certificate can be created by installing
        #   the ssl-cert package. See
        #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
        #   If both key and certificate are stored in the same file, only the
        #   SSLCertificateFile directive is needed.
       # SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
       # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

        ErrorLog /home/user/public_html/folder/logs/error.log
        LogLevel warn
        CustomLog /home/user/public_html/folder/logs/access.log combined

</VirtualHost>

Once done save the file and active your vhost

sudo a2ensite test.example.com

It will then prompt you to restart Apache once you have done so you should be up and running and able to accesses phpmyadmin via "test.example.com" as oppose to "www.example.com/phpmyadmin"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.