Running Multiple WordPress Sites on Ubuntu 16.04 LTS with Apache2, MariaDB and PHP 7.1 Support

Instead of running one WordPress website per server, which may not be a great way to utilize your system resources, you can run multiple sites on a single server. Nowadays, a Linux host with 1 CPU and 4GB RAM can power multiple WordPress websites and do it efficiently with Apache2.

If you want to learn how to run multiple WordPress websites on Ubuntu 16.04 LTS server, the steps below can get you started. With Apache2 HTTP server, you can run as many WordPress websites as possible as long as the host system has enough resources with a feature called VirtualHost.

Apache2 virtualhost is a feature similar to Nginx server block. These features allow users and webmasters to host multiple independent websites or blogs on a single host computer with single IP address and separate domain names.

Instead or running individual website on individual server with individual IPs, Apache2 virtualhost can be configured to run all your different websites from a single host computer and one IP address.

When you’re ready, follow the steps below to get this working.

Step 1: Prepare Ubuntu 16.04 LTS Server

Ubuntu Servers are easier to use and manage, especially for new users and students. Other Linux server will let you do the same, but I find Ubuntu to be much more user friendly then other Linux distributions.

So, prepare Ubuntu server and run the commands below to update it.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

Step 2: Install Apache2 HTTP Web Server

Next, run the commands below to install Apache2 HTTP server.

sudo apt-get install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always startup when the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Step 3: Install MariaDB Database Server

You’ll need a database server for WordPress… and MariaDB database server is a great place to start. To install it run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

After that, run the commands below to secure MariaDB server.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Restart MariaDB server

sudo systemctl restart mysql.service

Step 4: Install PHP 7.1 and other PHP modules

PHP 7.1 isn’t available on Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.

Run the commands below to add the below third party repository to upgrade to PHP 7.1

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then update and upgrade to PHP 7.1

sudo apt update

Run the commands below to install PHP 7.1 and related modules.

sudo apt install php7.1 libapache2-mod-php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl

After install PHP, run the commands below to open Apache2 default PHP file.

sudo nano /etc/php/7.1/apache2/php.ini

Then edit the below lines to look like this and save the file.

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100
max_execution_time = 360
date.timezone = America/Chicago

Step 5: Create WordPress Databases and Dsers

At this point in our setup, all required servers and packages have been installed. it’s now time to create our individual website database and config files.

We’re going to be creating configurations for three WordPress websites. They are:

We’re going to create three databases for these three websites. These databases will be called:


To create the databases, run the commands below to logon to the server.

sudo mysql -u root -p

Then run the commands below to create all three databases. one line at a time.

CREATE DATABASE examplecomdb;
CREATE DATABASE examplenetdb;
CREATE DATABASE exampleorgdb;

Our next task we’ll create three database users, one for each site. they will be called:


Run the commands below to create the three users and set their passwords

GRANT ALL ON examplecomdb.* TO 'examplecomuser'@'localhost' IDENTIFIED BY 'type_new_password_here';
GRANT ALL ON examplenetdb.* TO 'examplenetuser'@'localhost' IDENTIFIED BY 'type_new_passwored_here';
GRANT ALL ON exampleorgdb.* TO 'exampleorguser'@'localhost' IDENTIFIED BY 'type_new_password_here';

When you’re done, run the commands below to save your changes and exit.


Step 6: Create Apache2 Server Blocks

Now we’re going to create three server blocks for our three websites. run the commands below to create each. for each, add th configure code below, replace the domain name and root to their appropriate folders.

sudo nano /etc/apache2/sites-available/
sudo nano /etc/apache2/sites-available/
sudo nano /etc/apache2/sites-available/

For each file, copy and paste the code below. replacing the domain name reference and root folder highlighted.

<VirtualHost *:80>
     DocumentRoot /var/www/html/

     <Directory /var/www/html/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> server block looks like this:

<VirtualHost *:80>
     DocumentRoot /var/www/html/

     <Directory /var/www/html/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

Do this as many time for each website.

When you’re done, run the commands below to enable the server blocks.

sudo a2ensite
sudo a2ensite
sudo a2ensite

Step 7: Create Document Root Folder for Each Site

In each of the server block or site configuration file, there’s a root location. This is where each website content should be stored. and should be different for all websites. Now that we’ve defined the root locations for all our site, go and create them below.

sudo mkdir -p /var/www/html/
sudo mkdir -p /var/www/html/
sudo mkdir -p /var/www/html/

Step 8: Download WordPress content and copy it to each of the root location

Now download WordPress content and extract into the root directory for each site. To do that run the commands below

cd /tmp/ && wget

Then extract the downloaded file.

tar -xzvf latest.tar.gz

And copy to each root folder for each site.

sudo cp -R wordpress/* /var/www/html/
sudo cp -R wordpress/* /var/www/html/
sudo cp -R wordpress/* /var/www/html/


After that, run the commands below to create WordPress wp-config.php settings for each of the domains.

sudo cp /var/www/html/ /var/www/html/
sudo cp /var/www/html/ /var/www/html/
sudo cp /var/www/html/ /var/www/html/

Then run the commands below to open each of the config file and enter the database connection info. then save the file.

sudo nano /var/www/html/
sudo nano /var/www/html/
sudo nano /var/www/html/

When each file opens type the database name and password for each site you created above. and save the file.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'examplecomdb');

/** MySQL database username */
define('DB_USER', 'examplecomuser');

/** MySQL database password */
define('DB_PASSWORD', 'type_password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Do the above for each of the sites you create, making sure the database connection info is correct for each site.

When you’re done, run the commands below to configure the directories permissions for all the sites.

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

After running the commands above, run the commands below to check Apache2 configurations, enable the rewrite module and restart the web server

sudo apachectl configtest
sudo a2enmod rewrite
sudo systemctl restart apache2.service

After restarting Apache2 with no errors, you should be able to access your sites the domain names. and see WordPress default setup page.


WordPress default setup page

Follow WordPress wizard until setup is complete for each site. That’s it!

This is how to set up multiple WordPress websites on Ubuntu 16.04 LTS


You may also like the post below:


  1. Congratulations this was the first one go true all the way site s up and running
    Please keeping doing this type of work for people like me want to learn Linux.

    Thank you Terry Texas

  2. Nice article. Thanks for writing this up. Step 4 assumes I have PHP installed already. In my case I did not so I had to go find instructions somewhere else on how to install PHP 7.1. I used this link FYI

  3. Hector J Simosa

    Thanks very much! Nice explanation.

  4. I already have a WordPress installation of one site in my Ubuntu server that works. Is it possible to add another site and how?
    Thank you

  5. Hi all, In step 6 while you want to edit w-config file you should use ‘type_new_password_here’ instead of ‘type_password_here’, that is why I had problem database connection. BE AWARE…..

  6. Sorry I made a mistake. It is in step 9.

  7. In step 5 creating new user this one has wrong spelling,,, It took long time to understand where is the problem.please fix that as well

  8. check these guys out

    Thanks for the sensible critique. Me and my neighbor were just preparing to do some research on this. We got a grab a book from our area library but I think I learned more from this post. I’m very glad to see such great info being shared freely out there.

  9. hello
    my friend set up my ubuntu 16.04 and now i have 3 website in my dedi server and i need to add another one too. will i do all this or i need just set database for wordpress.?

    thank you

  10. Worked like a dream setting up on Ubuntu 18.04
    Now for the hard bit creating some content.

  11. I tried this method, and it seems like everything else works but the wordpress itself.
    When I try to run the admin file or the install file, I’m just getting the raw php spat out to the webpage. Any advice on any step I might’ve messed up? Thanks.

  12. Thanks, great article, worked just fine on Linux lite 4 (Ubuntu 18.04 LTS)

  13. Thank you so much. I did a WordPress migration using this tutorial. My site feels brand new.

  14. Can I use this article even if I already have wordpress installed with one website already hosted on my localhost ?

    1. My previous installation used this line of code
      Alias /blog /usr/share/wordpress

      Options FollowSymLinks
      AllowOverride Limit Options FileInfo
      DirectoryIndex index.php
      Order allow,deny
      Allow from all

      Options FollowSymLinks
      Order allow,deny
      Allow from all

      in /etc/apache2/sites-available/wordpress.conf

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.