Multiple WordPress Installations on Sub Domains
When it comes to blogging, lot many of us will choose WordPress as a blogging platform because of it’s versatility and ease of use. But when the WordPress platform is self managed (i.e. hosted and installed WordPress manually on server), there can be
many complications related to installations, domain mapping, and managing .htaccess files specially when there are multiple WordPress installations on same server. So, this post will help to setup sub-domain mapping to multiple WordPress installations
on single server.
There are many ways for achieving this functionality like using .htacess file or using apache2 hosts configurations. In this post we will see the best option where we will Run Multiple WordPress Sites on Sub Domains using apache2 host configuration.
Whenever request comes to server, it will first go to Apache2 and then to .htaccess, if you use .htaccess, it will consume some microseconds and might delay server response. So it’s better to map subdomain requests in apache2 configuration itself.
Note: This is not equivalent to redirecting http://www.example.com/post1 to http://www.example.com/post1-actual. You can use redirection plugin for that purpose.
Resources used:
Instructions file | View |
Image file | View |
GoDaddy configurations file | View |
Prerequisite
1. You must be using Apache2 as server.
2. You need to have root access to your server so that we can make changes to apache2 configuration files.
3. You must have setup subdomain to point to server IP address.
Please check video for more details.
1. Login to Server using SSH and Enable rewrite module:
You can login into the server using SSH, with user having root access so that user can run sudo commands. Execute below command:
1 |
sudo a2enmod rewrite |
2.find apache2 virtual host configuration file:
Next step is to find the Apache2 virtual host configuration file. Note down the location for further steps. For Ubuntu 16.04 with Apache2 below will be default location:
1 |
/etc/apache2/sites-available/ |
3. Edit default virtual host file : 000-default.conf:
This file is present at location we have found for apache2 virtual host configuration. Execute below command to open file using nano editor:
1 |
sudo nano /etc/apache2/sites-available/000-default.conf |
3. Modify 000-default.conf
Modify the content for tag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<VirtualHost *:80> <Directory /var/www/html/test1> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ServerAdmin webmaster@mytechblog.in ServerName test1.mytechblog.in ServerAlias test1-site.mytechblog.in DocumentRoot /var/www/html/test1 ErrorLog ${APACHE_LOG_DIR}/test1_error.log CustomLog ${APACHE_LOG_DIR}/test1_access.log combined </VirtualHost> |
4.Restart apache2 server and Done!!
Execute below command to restart apache2 server.
1 |
sudo service apache2 restart |
You have mapped test1 sub-domain to test1 sub-directory
5. Now map test2 sub-domain to test2 folder:
1 |
cd /etc/apache2/sites-available/ |
1 |
sudo cp -rf 000-default.conf test2.conf |
1 |
sudo nano test2.conf |
Then add the following code to virtual host definition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<VirtualHost *:80> <Directory /var/www/html/test2> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ServerAdmin webmaster@mytechblog.in ServerName test2.mytechblog.in ServerAlias test2-site.mytechblog.in DocumentRoot /var/www/html/test2 ErrorLog ${APACHE_LOG_DIR}/test2_error.log CustomLog ${APACHE_LOG_DIR}/test2_access.log combined </VirtualHost> |
6. Run below command :
Execute below command:
1 |
sudo a2ensite test2.conf |
7. Restart server, Done!!
Execute below command:
1 |
sudo service apache2 restart |
You have mapped test2 sub-domain to test2 sub-directory
So, this is how you can map two separate WordPress installations to different domains.