HowTo setup vhosts for multiple Instances of WordPress

Disclaimer (again):

I am just writing what I did, you should decide for yourself if it is a good idea to copy it. I am not responsible for any damages or wasted time from following these instructions.

I am still motivated to write something here, so i write the second part of the HowTo, before i get too lazy again.

If you read the last entry, you will have a second wordpress-instance that is done setting up – at least from the server point of view…

To make it work, you probably need to configure virtualhosts in apache.

Therefore you need to edit some conf-files. Enter the directory with

cd /etc/apache2/sites-available/

At least there should be a file called 000-default.conf. In it is defined what a “user with a webbrowser” will be shown when $yourdomain.$yourtld is entered.

To be honest: I really dont care whats in it…. The following conf is copied from diemo.best and changed for you:

<VirtualHost *:80>
        ServerAdmin diemo@luisental.org
        ServerName diemo.best
        ServerAlias diemo.best
        DocumentRoot /var/www/diemo_best/wordpress
        <Directory /var/www/diemo_best/wordpress>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Relevant lines: ServerName, ServerAlias, DocumentRoot and <Directory.

You need to change these to your needs. For example if the domain you own is “paul.com” and you want to show the wordpress-site on “wordpress.paul.com”, your servername and serveralias should be “wordpress.paul.com”.

The DocumentRoot and Directory should point to your wordpress-directory (see last post).

If you have another instance of wp running on your server, then this would probably have the following effect:

People who enter “paul.com” would see the other instance. Only people who enter “wordpress.paul.com” – and people that are directed there by a search-engine, obviously – will see the new wordpress-instance. Every other subdomain will get redirected to “paul.com” and to your other instance.

If you want to change the default behaviour… well… you have to change the 000-default.conf.

It is most likely longer than my example above, but you will be able to identify the relevant parts to change it to your liking.

Now all you have to do is to restart apache and go to your new site in your browser.

Have fun!

A relevant addition:

Dont forget to create a DNS-Record for your sub- or second domain that points to your server. Doing that will make it possible to work – keep in mind that it needs to propagate through the dns-system. That will take a while. If you are like me youll have a nice break now, because everything is done except the DNS-Record, which takes about 30 minutes up to several hours. Take that break, you have earned it. 😉