Set Up Apache to Run Multiple WordPress Sites on a Single Linode

Updated by Linode Contributed by Jonathan Tsai

Contribute on GitHub

Report an Issue | View File | Edit File

WordPress on Apache

What is WordPress?

WordPress is a popular, dynamic, content management system that makes it easy to build anything from blogs to complete websites and online stores. This guide shows you how to configure your system to run multiple WordPress sites on a single Linode, using Apache Virtual Hosts.

Before You Begin

  • Configure a LAMP web stack.

  • This guide assumes you have followed the Install WordPress on Ubuntu 16.04 guide, and are familiar with the procedures described there.

  • Make sure MySQL has a database set up for each separate instance of WordPress that you wish to run. If you do not have a WordPress database, create one:

    1. Log in to the MySQL command line as the root user:

      mysql -u root -p
    2. Create the WordPress databases with a separate namespace:

      CREATE DATABASE example1_wordpress;
    3. Create a user and grant them privileges for the newly created example1_wordpress database, replacing example1_wpuser and password with the username and password you wish to use:

      CREATE USER 'example1_wpuser' IDENTIFIED BY 'password1';
      GRANT ALL PRIVILEGES ON example1_wordpress.* TO 'example1_wpuser';
    4. Repeat Steps 2 and 3 for each instance of WordPress that you want to run, replacing the example namespace with a keyword of your choice representing the additional sites:

      CREATE USER 'example2_wpuser' IDENTIFIED BY 'password2';
      GRANT ALL PRIVILEGES ON example1_wordpress.* TO 'example2_wpuser';
    5. Exit MySQL:

  • This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, you can check our Users and Groups guide.

    • All configuration files should be edited with elevated privileges. Remember to include sudo before running your text editor.

An example of a two WordPress setup is:

Hostname Database Username Password example1_wordpress example1_wpuser password1 example2_wordpress example2_wpuser password2

Replace each instance of, example, example1, example2, and the other example variables in this guide with your respective site’s domain name and namespace keyword.

Install Multiple WordPress Instances

The following steps are adapted from the Install WordPress section of the Install WordPress on Ubuntu 16.04 guide.

  1. Create the directory that will host your website and WordPress source files. In this guide, the home directory /var/www/html/ is used as an example. Navigate to that new directory:

    sudo mkdir /var/www/html/
    sudo mkdir /var/www/html/
    cd /var/www/html/
  2. Create a directory called src under /var/www/html/ Download and extract the latest version of WordPress:

    sudo mkdir /var/www/html/
    cd /var/www/html/
    sudo wget
    tar -zxvf latest.tar.gz
  3. Repeat the procedure for

    sudo mkdir /var/www/html/
    cd /var/www/html/
    sudo wget
    sudo tar -zxvf latest.tar.gz
  4. Rename latest.tar.gz as wordpress followed by the date to store a backup of the original source files. This will be useful if you install new versions in the future and need to revert back to a previous release:

    sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz

    Repeat this step in /var/www/html/

  5. Set your web server’s user, www-data, as the owner of your site’s home directory:

    sudo chown -R www-data:www-data /var/www/html/
    sudo chown -R www-data:www-data /var/www/html/
  6. Copy the WordPress files to your public_html folder:

    sudo cp -R /var/www/html/* ../public_html/
    sudo cp -R /var/www/html/* ../public_html/
  7. Give your web server ownership of the public_html folder:

    sudo chown -R www-data:www-data /var/www/html/
    sudo chown -R www-data:www-data /var/www/html/
  8. Repeat for each additional instance of WordPress that you want to run.

Configure Apache Virtual Hosts

Up until this point, the steps have been fairly straightforward and similar to setting up a single instance of WordPress. In this section, configure Apache Virtual Hosts so that a visitor to will be served the content in /var/www/html/ and backed by the MySQL database example1_wordpress.

  1. Go to the Apache sites-available directory:

    cd /etc/apache2/sites-available
  2. Copy 000-default.conf as needed:

    cp 000-default.conf example1.conf
    cp 000-default.conf example2.conf
  3. Put the following contents in

    <VirtualHost *:80>
    # The primary domain for this host
    # Optionally have other subdomains also managed by this Virtual Host
    ServerAlias *
    DocumentRoot /var/www/html/
    <Directory /var/www/html/>
    Require all granted
    # Allow local .htaccess to override Apache configuration settings
    AllowOverride all
    # Enable RewriteEngine
    RewriteEngine on
    RewriteOptions inherit
    # Block .svn, .git
    RewriteRule \.(svn|git)(/)?$ - [F]
    # Catchall redirect to
    RewriteCond %{HTTP_HOST}   !^www.example1\.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteRule ^/(.*)$1 [L,R]
    # Recommended: XSS protection
    <IfModule mod_headers.c>
    Header set X-XSS-Protection "1; mode=block"
    Header always append X-Frame-Options SAMEORIGIN
  4. Enable the site. This will create a symlink to the Apache conf file in /etc/apache2/sites-enabled/:

    sudo a2ensite example1.conf
  5. Restart Apache to enable the changes:

    sudo systemctl restart apache2
  6. Repeat Steps 2 through 5 for each WordPress site that you want to run.

Configure WordPress

Follow the steps from the Configure WordPress section of the Install WordPress on Ubuntu 16.04 guide.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

comments powered by Disqus

This guide is published under a CC BY-ND 4.0 license.