Loading...

How To Install WordPress Multisite On Ubuntu With Nginx

In this article, we will show you how to install WordPress Multisite on an Ubuntu 16.04 VPS with MariaDB, PHP-FPM 7.0 and Nginx. WordPress Multisite allows you to run and manage multiple WordPress websites from a single WordPress installation. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.

Requirements

For this tutorial, and similar setups in general, you’ll need:

  • An Ubuntu VPS. You can get a Managed Ubuntu VPS from RoseHosting and have them set all of this up for you, for free as part of their managed services.
  • Since this is going to be a multisite WP install, we’ll need more resources to properly run all the sites, so a VPS with at least 1GB of RAM is recommended.
  • Nginx, PHP7, MariaDB/MySQL and WP-CLI. Details on how to install them below.

Log in to your VPS via SSH

ssh my_sudo_user@my_server

Update the system and install necessary packages

sudo apt update && sudo apt -y upgrade
sudo apt -y install curl

Install MariaDB 10.0

Install the latest MariaDB 10.0 server from the official Ubuntu repositories:

sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

mysql_secure_installation

Next, we need to create a database for our WordPress Multisite installation.

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'my_strong_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

Install PHP 7.0 and all required PHP modules

To install the latest stable version of PHP 7.0 and all necessary modules, run:

sudo apt -y install php-fpm php-cli php-gd php-mysql php-mcrypt php-curl php-intl php-xsl php-zip php-mbstring php-xml php-xmlrpc

Change few default PHP settings:

sudo sed -i "s/memory_limit = .*/memory_limit = 256M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.0/fpm/php.ini

Install WordPress

We’ll use the wp-cli tool to install our WordPress Multisite installation. WP-CLI is a command line tool with which we can use to install and manage our WordPress installations. To install it, run the following commands:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

and check if the installation is successful:

wp --info
PHP binary:     /usr/bin/php7.0
PHP version:    7.0.15-0ubuntu0.16.04.4
php.ini used:   /etc/php/7.0/cli/php.ini
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.1.0

Create a directory for our WordPress Multisite installation:

sudo mkdir -p /var/www/html/example.com

Replace example.com with your domain

Change to the WordPress directory and download the WordPress core:

cd /var/www/html/example.com
wp core download

Create a wp-config.php file:

wp core config --dbname=wordpress --dbuser=wordpress --dbpass=my_strong_password

Run the WordPress Multisite installation:

wp core multisite-install --title="My WordPress Multisite" --admin_user="admin_user" --admin_password="admin_strong_password" --admin_email="admin@example.com"

If the installation is successful you will see something like below:

Created single site database tables.
Set up multisite database tables.
Added multisite constants to 'wp-config.php'.
Success: Network installed. Don't forget to set up rewrite rule

Finally, set the correct permissions:

sudo chown -R www-data: /var/www/html/example.com

Install and configure Nginx

Install Nginx from the official Ubuntu repositories:

sudo apt -y install nginx

Once the installation is completed, create a new Nginx server block with the following content:

sudo nano /etc/nginx/sites-available/example.com
server {
    listen      80;
    server_name example.com www.example.com example2.com www.example2.com;

    root /var/www/html/example.com/;

    index index.html index.htm index.php;

    charset utf-8;

    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php) $2 last;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log  /var/log/nginx/example.com.access.log;
    error_log   /var/log/nginx/example.com.error.log;

    sendfile off;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}

Activate the server block by creating a symbolic link:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

Test the Nginx configuration and restart nginx:

sudo nginx -t
sudo service nginx restart

Now you should be able to login to your WordPress back-end by going to http://example.com/wp-admin using the information you set when running the wp core multisite-install command.

Add new site

Once our WordPress Multisite Network is installed and configured we can start adding new sites. In this example, we will add the domain example2.com. To add a new site, go to the Sites page by clicking on My Sites > Network Admin > Sites in the admin menu, click on the “Add new” button and fill the form as shown in the image below.

example1

Once the site is added we need to change the Site Address (URL) from http://example.com/example2 to example2.com, to do that, go to Sites > All sites, click “Edit” under the site name and change the Site Address (URL) as shown in the image below.

example2

If everything is setup correctly now you should be able to open your new WordPress site by going to https://example2.com.


That’s it. You have successfully installed and configured a WordPress Multisite Network. When adding a new site do not forget to add the domain to the Nginx configuration.

RoseHosting.com is a privately held company founded in 2001 and based in St. Louis, Missouri – RoseHosting.com offers quality managed Linux VPS hosting with free 24/7 technical support.