In my previous post, I told you guys about installing multiple WordPress instances in a single VM. You can have you own reasons doing that, but lets say you don’t wanted to create another VM in cloud or configure whole new server for your blog or website and wanted to use existing server, VM or OS so is why you needed two WordPress instances. In this scenario, you’ll be needing multiple domains and your other WordPress instances will be installed in sub directory.
In this case, your domain should be pointing at sub directory, but DNS doesn’t work like that – either it’s CNAME or A record – you cannot point your domain to sub directory in DNS setting.
Here DNS is failed to serve you, but Virtual Host will help you.
Virtual host is a method in which you can host more than one website in a single machine.
In this tutorial I’ll be using real example. My main website which resides at main public http folder is “www.forgeknives.com” and other website is sitting in sub directory is “www.samknives.com” (main_website/samknives), public URL is “knives.southeastasia.cloudapp.azure.com” VM is installed in Microsoft Azure and I’m using Bitnami LAMP stack.
Head to your domain provider, namecheap in my case, and point both of domains to a Public URL or Public IP of your server, meaning, add CNAME or A Record respectively. In my case, I’m using Public URL which is “knives.southeastasia.cloudapp.azure.com”.
Don’t worry, let server do the work.
Add Virtual Host Information in httpd.conf Files
If you have searched about adding vHosts you’ll come across the information where people has said to edit file like
/etc/apache2/apache2.conf like the solution in this SuperUser thread. Well, they are right, but the problem is – it doesn’t work like this in Bitnami LAMP stack.
Connect to your VM because your about to edit some files on the server.
If you are using Bitnami stack, your “httpd.conf” will be
Edit files of both of your instances i.e
Insert the following information in the files
ServerAlias domain.tld *.domain.tld
In my case, both of my files will be like as followed
ctrl+x > y > enter
Create Virtual Host
Follow these steps to create virtual hosts
- Comment the line
Include "/opt/bitnami/apps/wordpress/conf/httpd-prefix.conf" in the file
- Now, include the vHost configration files of both websites in
- Update the URL.
- Restart Apache Server
$ sudo /opt/bitnami/ctlscript.sh restart apache
At this point, if you access your website using second domain, it’ll be pointing towards it’s sub directory
but when you try to make use of .htaccess of WordPress it won’t work, permalinks will be broken, meaning you cannot be able to access any post etc, you’ll probably get 404 or 500.
Two steps are needed to solve this problem, 1st is, don’t forget to update URL, second is Allowing Override.
When you’ll search about the problem mentioned above, people on forums will be throwing all kind of broken-.htaccess-file-maybe-solution. But here, it’s not the solution. Don’t waste your time deleting and let-the-WordPress-create .htaccess file automatically. For security purpose, Bitnami has move .htaccess file and merged with
This is file, “AllowOverride” is set to “none”, go ahead and change it to “All”.
(We are talking about the instances which are only within sub directory)
Now go ahead and test your website.
This is it, if you have any question don’t forget to ask them bellow.