Follow the following three simple steps and you will be able to set up the subdomains multisite in localhost WordPress setup.
Step 1: Setting up virtual host for main network localhost domain
WordPress doesn’t allow to install the sub-domain multisite for local WordPress installation. So, first thing we need to is to set up the virtual host for main network site.
For the demonstration purpose, i am assuming “http://localhost/your-site” as the main local WordPress installation where you want to install subdomains multisite and i will map this local site to virtual domain “http://your-site.com”.
To set up the virtual hosts, use following two commands.
#1
sudo gedit /etc/hosts
and then add following line of code
127.0.0.1 your-site.com
#2
sudo gedit /etc/apache2/sites-enabled/000-default.conf
and then add following lines of code
#For sub-domain your-site.com
<VirtualHost *:80>
DocumentRoot /var/www/html/your-site/
ServerName your-site.com
<Directory /var/www/html/your-site>
Options +Indexes +FollowSymlinks +MultiViews +Includes
AllowOverride FIleInfo Options
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Now, we are done with setting up virtual host for main domain.
Step 2: Setting up virtual hosts for other subdomains
Setting up virtual host for other subdomains is the same process of Step 1.
For example, if you decide to use one sub-domain as site1.your-site.com,
Like in Step 1 example,
sudo gedit /etc/hosts
and then add following lines of code
127.0.0.1 site1.your-site.com
sudo gedit /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/your-site/
ServerName site1.your-site.com
<Directory /var/www/html/your-site>
Options +Indexes +FollowSymlinks +MultiViews +Includes
AllowOverride FIleInfo Options
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Note: The document root and directory should point to the local folder of main domain.
Now, you can add as many as subdomains by following the above procedures. If you are comfortable, you can set up multiple virtual hosts at the same time.
You will need to restart the apache2 server.
sudo systemctl restart apache2
Step 3: Installing WP Multisite
Open wp-config.php file and add following code:
define('WP_ALLOW_MULTISITE', TRUE);
Then, reload the WP backend and you will see the “Network setup” submenu under “Tools”.
The next step is to click the “Network Setup” and you will be redirected to network set up page as shown in following image.

Choose the “Sub-domains” and click “install”.
As a final step, you will be instructed to put some codes in “wp-config.php” file and “.htaccess” file.

Note: Make sure to keep backups of both files in case needed to revert back.
All Done. !!!!!!!!
P.S. if you are on windows or mac, please find a way to set up virtual hosts. Rest of the processes are same.
Comments
Pingback:Installation of multisite with sub-domains on localhost in Wodrpress – Engineering Sarokar