Question

Problem with multiple subdomains-DocumenRoots on Ubuntu 18.04 and Apache2

Posted May 6, 2020 329 views
ApacheUbuntu 18.04

Hi guys,

I apologize if this is a duplicated question, I have been trying to find an answer through the related posts I have managed to find with no luck so far…

I have an apache2 server running on Ubuntu 18.04 (DNS for DigitalOcean set) with two subdomains: php.example.com and blog.example.com (DNS A Records set for the droplet IP). I installed phpMyAdmin (/usr/share/phpmyadmin) and a wordpress blog (/var/www/wordpress).

I wanted to access phpMyAdmin through php.example.com and the blog through blog.example.com / www.example.com but I cannot get to it; all the subdomains go to one of the DocumentRoots.

I have followed some tutorials (https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04) and tips I have seen here and on different sites, and so far I have completed these steps:

1) Configured Virtual Hosts:

wordpress.conf:
<VirtualHost *:80>

    ServerAdmin example@mail.com
    ServerName www.example.com
    ServerAlias blog.example.com
    DocumentRoot /var/www/wordpress

    <Directory /var/www/wordpress/>
            AllowOverride All
    </Directory>

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

</VirtualHost>

<VirtualHost *:443>
ServerAdmin example@mail.com
ServerName www.example.com
ServerAlias blog.example.com
DocumentRoot /var/www/wordpress

    SSLEngine on
    SSLCertificateFile /certroute
    SSLCertificateKeyFile /keyroute
    SSLCertificateChainFile /chainroute

    <Directory /var/www/wordpress/>
            AllowOverride All
    </Directory>

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

</VirtualHost>

phpmyadmin.conf:
<VirtualHost *:80>

    ServerAdmin example@mail.com
    ServerName php.example.com
    DocumentRoot /var/www/phpmyadmin

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

</VirtualHost>

<VirtualHost *:443>
ServerAdmin example@mail.com
ServerName php.example.com
DocumentRoot /var/www/phpmyadmin

    SSLEngine on
    SSLCertificateFile /certroute
    SSLCertificateKeyFile /keyroute
    SSLCertificateChainFile /chainroute

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

</VirtualHost>

2) Enabled both .conf files and disabled 000-default.conf / default-ssl.conf

3) Set up a symlink from /var/www/phpmyadmin to /usr/share/phpmyadmin

4) Reloaded Apache2

Still going to wordpress when I try to load https://php.example.com and at this point I really don’t know what to try next.

Any help would be much appreciated.

Thanks!

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.

×
2 answers

Hi @fgazpiazu,

You want to access PHPMyAdmin like this php.domain.com instead of domain.com/phpmyadmin.

If you’re running an apache server and you have installed PHPMyAdmin, So the one thing is extra you have to do.

Just create a symbolic link in apache2 directory to access the PHPMyAdmin:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf

sudo a2enconf phpmyadmin.conf

Now, create a new configuration file in apache directory for you subdomain php.domain.com.conf, and add following lines

<^><VirtualHost *:80>
ServerName php.website.com
RedirectPermanent / http://php.website.com:/
</VirtualHost><^>

Now when you open php.domain.com, it will redirect you to domain.com/phpmyadmin

If you have install PHPMyAdmin in /etc directory, then this will work, otherwise, you have to make some changes.

Sorry, @fgazpiazu,

This is the right configuration, I made a mistake above.

server {
# Permanent redirect to new URL
server_name php.yourdomain.com;
rewrite ^/(.*)$ http://yourdomain.com/phpmyadmin permanent;
} 

reload configuration:

$ sudo systemctl reload nginx

Add the following record in your DNS manager.

CNAME php yourdoamin.com
Submit an Answer