How to Set up WordPress Multisite on Ubuntu Server using LAMP

This knowledgebase will show you how to set up WordPress Multisite with Apache Web server. It’s assumed that you have already installed WordPress with LAMP stack on a Ubuntu server.

What is WordPress Multisite

It’s a feature that enables you to host multiple websites on a single WordPress installation. The best example is WordPress.com, which hosts tens of millions of websites on a single WordPress installation.

There are two types of WordPress multisite

  • sub-domain multisite, which is the most common type and used by WordPress.com blogs
  • sub-directory multisite

In this tutorial, I will show you how to set up sub-domain type of multisite and how to set up domain mapping, so that you can map a new domain name to a sub-domain. As a matter of fact, WordPress.com uses domain mapping so that customers can choose their own domain names (your-domain.com) instead of sub-domain (your-blog.wordpress.com).

Steps to Set up WordPress Multisite

1. Edit wp-config.php File
Change into your WordPress installation directory like below:

cd /var/www/example.com/

Edit wp-config.php file with your preferred text editor.

sudo nano wp-config.php

Find this line: /* That’s all, stop editing! Happy blogging. */ (usually at the end of the file). Then add the following line to enable the Network feature.

define('WP_ALLOW_MULTISITE', true);

<image>

Save and close the file. Next, go to your WordPress Dashboard in your Web browser. You now see a new item, labeled Network Setup, under the Tools menu. Click the Network Setup link in the Tools menu. If you have any plugins activated, please deactivate them for a moment.

2. Enable Apache mod_rewrite module
The Network Setup page will tell you to enable the Apache mod_rewrite module. You can check if it is enabled by running the command below.

sudo apache2ctl -M | grep rewrite

If it’s already enabled, you will see this line:

rewrite_module (shared)

Otherwise enable it with:

sudo a2enmod rewrite

3. Enable .htaccess File
We also need to enable .htaccess file because later we will need to add some directives in this file to enable WordPress multisite. To enable .htaccess file, edit the Apache vhost configuration file for your WordPress site like below.

sudo nano /etc/apache2/sites-available/example.com.conf

Add the following lines inside <VirtualHost> tag. Replace /var/www/example.com with your own document root directory.

<Directory "/var/www/example.com">
AllowOverride All
</Directory>

Save and close the file. Just so you know, .htaccess file is also needed for WordPress permalink to work. Now restart Apache for the change to take effect.

sudo systemctl restart apache2

4. Enable the Network
Then at the WordPress Dashboard, choose sub-domains and click Install button.

<image>

To use a subdomain configuration, you must have a wildcard entry in your DNS. To create a wildcard DNS record, enter * in the name field and enter your server IP address in the value field in your DNS manager.  The following is an example of a wildcard entry in CloudFlare DNS manager.

<image>

Then next page will tell you to add some configurations in wp-config.php file and the .htaccess file. Note that you need to delete existing rewrite rules in .htaccess file and then add the new rewrite rules.

<image>

Once thats done, click the log in link at the bottom of the page to re-login.

Create a New Site in the Network

With the WordPress Network now fully enabled and configured, you see a new link in the menu at the top right of your WordPress Dashboard called My Sites. To create a new site, go to My Sites -> Network Admin -> Sites.

Click Add New button and enter site URL, site title, admin email.

<image>

You can add many sites as you want.

Install Themes and Plugins

Individual site admin can’t install new themes and plugins. Only the network admin can do that. Go to My Sites -> Network Admin -> Dashboard. From there, the network admin can install themes and plugins and apply changes that affect the whole network. Once a theme or plugin is network-enabled, individual admins can enable it from their dashboard.

How to Set up Domain Mapping

If you want to add a top-level domain in the WordPress multisite network, you need first to create a subsite in the network, like site1.example.com, then use domain mapping to map the top-level domain like example.org to site1.example.com.

Here are the steps.

First, create DNS A record for the top-level domain you want to map. It should point to the IP address of your WordPress site.

Then, create a subsite in the WordPress multisite network.

Next, go to My Sites -> Network Admin -> Sites, click edit button of the newly-created subsite. In the Site Address field, replace the URL with the top-level domain you want to map.

 

Save your changes and you are done. Now when a visitor enter example.org in web browser, it will be redirected to site1.example.com under the hood without being noticed by the visitor.

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How To Install LAMP Stack on CentOS VPS

This Knowledgebase article details steps on how to install LAMP stack on CentOS & RHEL OS...

How to Install LEMP Stack on Ubuntu VPS

This knowledgebase article details how to install LEMP stack (Nginx, MariaDB, and PHP7.4) on...

Install WordPress on Ubuntu with LAMP

This knowledgebase will detail how to install WordPress on Ubuntu flavours with Apache, MariaDB...

How to Install LAMP Stack on Ubuntu VPS

This knowledgebase article is going to show you how to install LAMP stack on Ubuntu 20.04 LTS. A...

How to Run PHP-FPM with Apache in Ubuntu

There are basically two ways to run PHP code with Apache web server: Apache PHP module...