Point Domain to Sub-Directory in Apache Bitnami: Virtual Hosts

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.

1

2

 

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.

DNS Setting

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”.

3

4

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/httpd/httpd.conf or/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 /opt/bitnami/apps/wordpress_instance/conf/httpd-vhosts.conf.

Edit files of both of your instances i.e
/opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf
/opt/bitnami/apps/samknives/conf/httpd-vhosts.conf

Insert the following information in the files

NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/public_http
</VirtualHost>

In my case, both of my files will be like as followed

5

6

ctrl+x > y > enter

Create Virtual Host

Follow these steps to create virtual hosts

  1. Comment the line Include "/opt/bitnami/apps/wordpress/conf/httpd-prefix.conf" in the file /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf7
  2. Now, include the vHost configration files of both websites in /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf8
  3. Update the URL.
  4. 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

9

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.

10

Two steps are needed to solve this problem, 1st is, don’t forget to update URL, second is Allowing Override.

Allow Overriding

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 /opt/bitnami/apps/samknives/conf/httpd-app.conf.

This is file, “AllowOverride” is set to “none”, go ahead and change it to “All”.

11

(We are talking about the instances which are only within sub directory)

Now go ahead and test your website.

12

This is it, if you have any question don’t forget to ask them bellow.

Ahmed Khateeb

Computer Scientist, Former intern at Microsoft, Developer and Blogger. "Tech Enthusiast".

One thought on “Point Domain to Sub-Directory in Apache Bitnami: Virtual Hosts

  1. Ok we have *much* simpler situation: s:\xampp
    With Bitnami added as per usual : s:\xampp\app
    We simply want to run standard (non bitnami) WPress alongside Bitnami WP …
    We have followed Appache “how to doc” on virtual servers. And all is fine as far as Bitnami is concerned. But can not figure WHERE is it allowed/required to place parallel “plain” wordpress instance?

    As per document we have created:
    s:/xampp/apache/conf/extra/httpd-vhosts.conf

    DocumentRoot “S:/xampp/htdocs”
    ServerName localhost

    DocumentRoot “S:/xampp/apps/wordpress/htdocs”
    ServerName wordpress.localhost

    DocumentRoot “S:/websites/client1.local”
    ServerName client1.local

    The result is 403 …

    ps: yes c:\windows\system32\drivers\etc\hosts is

    127.0.0.1 localhost
    127.0.0.1 wordpress.localhost
    127.0.0.1 client1.local
    client1.localhost

    Please advise …

Leave a Reply

Your email address will not be published. Required fields are marked *