Connect More Domain and assign folder
Of course we might want to host another WordPress site in our server, this is how you can do it:
Add domain in DNS setting
It’s the same step with previous step about connecting your domain to your droplet above. We are going to use “secondary-domain.com” as example. So we need to set our domain name server to DO name servers, and add the domain in DO DNS Control Panel.
Visit your domain
After DNS is resolved, when you visit “secondary-domain.com” in your browser, you’ll see your main site which is located in “/var/www” folder path. We need to change this to another location/folder/path.
Assign folder for your domain
Using FileZilla, navigate to “/etc/apache2/sites-enabled” and create a file, for example “secondary-domain.com”, edit this file (right-click > view/edit) and add this content, and upload/save back to your server.
- <VirtualHost *:80>
- ServerName secondary–domain.com
- ServerAlias www.secondary–domain.com
- DocumentRoot /var/web/secondary–domain.com
- VirtualHost *:80 : is to set up Virtual Host for port *:80 (accessible via browser)
- ServerName : is the domain
- ServerAlias : is the domain alias, when we visit “www.secondary-domain.com” we will redirected to “secondary-domain.com”. This is optional if you don’t need server alias.
- DocumentRoot : is the path for this domain/host. as the above we are using “/var/web/secondary-domain.com” for our host path location, so our files for our secondary-domain.com will be located there.
All files in “sites-enabled” folder is loaded as Apache virtual host configuration, In different version of Apache this config file need to use “.conf” ext. To understand more about it you can check the files “/etc/apache2/apache2.conf”.
You can also read this tutorial: How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS.
Note: you can create virtual host config file with any file name and assign any path in your server, the above configuration is an example to make it manageable and easy to understand.
Create folder in the path set previously
- Now we need to create the folder, navigate using FileZilla to “/var” folder, and create a folder “web”.
- Inside this (“web”) folder, create another folder “secondary-domain.com”
- Upload a dummy file, for example: “testing.txt” with a content “WOOHOO!”.
Restart Apache to load configuration we added
We need to go back using PuTTY, and type this command:
- service apache2 restart
After Apache service is restarted successfully, visit “http://secondary-domain.com/testing.txt” using your browser, you should see the text “WOOHOO!” we added.
Installing WordPress in Secondary Domain
Basically the same step as before, the difference is we will use the path “var/web/secondary-domain.com”.