Install Multiple WordPress Sites on a Single Host

Vince IarusciDevOps, LearningLeave a Comment

Overview

WordPress (WordPress.org) is a free and open-source content management system (CMS) based on PHP and MySQL.  This article will walk you through the steps to host two or more separate WordPress instances on one VPS.  Note that this is different from setting up multisite.

In our company, we’ve successfully installed 3 sites on one VPS host.  We’re using an OVH VPS server at a cost of about $5 bucks CAD a month.  That works out to about $1.70 per site.  Based on the size and traffic to your sites, you may need to upgrade the size and storage of the VPS.

In our examples below, websites The Force (www.theforce.com domain) and The Dark Side (www.thedarkside.com domain) are installed. If you need to add more sites on the same server, just repeat all these steps for the additional server.  The steps for the installation are done from the command line but many of the steps can be done using an ftp client like Filezilla. Feel free to use an ftp client if it simplifies your install.

*Note that these websites are for demo purposes only and any reference to any existing websites or users is co-incidental. 

Our Server Environment

These instructions will work for most Linux type operating systems.

Operating System: Debian GNU/Linux 
Version: 8 (jessie) 
Hostname: server.example.com 
IP: 158.99.999.99 
VPS: vps12345.vps.ovh.ca 
Web Server: Apache2 
Database Server: MySql 5.5

Installation Steps

Download Wordpress and Extract the Package

Our first step will be to download the latest version of WordPress and unzip the package after download.

root@server:~# wget http://wordpress.org/latest.tar.gz
root@server:~# tar xzvf latest.tar.gz
Create Site Database and User

We’ll need to create a database with an assigned user for each of our sites using mysql commands.  Replace “password” with a unique secure password for each user.

mysql –u root -p 

CREATE DATABASE theforce;
CREATE USER luke@localhost; 
SET PASSWORD FOR luke@localhost= PASSWORD("password"); 
GRANT ALL PRIVILEGES ON theforce.* TO luke@localhost IDENTIFIED BY 'lukepassword';
FLUSH PRIVILEGES;
exit
CREATE DATABASE thedarkside;
CREATE USER vader@localhost;
SET PASSWORD FOR vader@localhost= PASSWORD("password");
GRANT ALL PRIVILEGES ON thedarkside.* TO vader@localhost IDENTIFIED BY 'vaderpassword';
FLUSH PRIVILEGES;
exit
Set-up Site Locations on server

The next steps create the server location in the www folder and copy the wordpress package to each of the server locations.

root@server:~# cd /var/www
root@server:~# mkdir theforce
root@server:~# mkdir thedarkside
root@server:~# cp ~/wordpress/wp-config-sample.php ~ /wordpress/wp-config.php
root@server:~# Rsync –avP ~/wordpress/ /var/www/theforce/
root@server:~# Rsync –avP ~/wordpress/ /var/www/thedarkside/
Set Ownership and Permissions

Set permissions to allow the www-data user to write to the website directory.

root@server:~# chown www-data:www-data * -R 

Configure wp-config.php

Each of the websites installs will need to connect to their respective databases. This is done by changing the settings in the wp-config.php config file for each site.

Run these commands to configure The Force website:

root@server:~# cd /var/www/theforce
root@server:~# sudo nano wp-config.php

Change the connection settings for the The Force website:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'theforce');
/** MySQL database username */
define('DB_USER', 'luke');
/** MySQL database password */
define('DB_PASSWORD', '<password here>');

Set the Table Prefix for theforce database.  Using fo_ that represents theforce for the table prefix. (Optional)

/**
* WordPress Database Table prefix. 
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix  = 'fo_';

 

Run these commands to configure The Darkside website …

root@server:~# cd /var/www/thedarkside
root@server:~# sudo nano wp-config.php

Modify the connection settings for the The Darkside website …

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'thedarkside');
/** MySQL database username */
define('DB_USER', 'vader');
/** MySQL database password */
define('DB_PASSWORD', '<password here>');

Set the Table Prefix for thedarkside database.  Using ds_ that represents thedarkside for the table prefix. (Optional)

/**
* WordPress Database Table prefix. 
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix  = 'ds_';
Configure Apache Virtualhost

Copy the conf file for each new site.  The existing sample 000-default.conf template file is used for the copy.  Note that the name for the sample conf file may be different depending on your install.

root@server:~# cd /etc/apache2/sites-available
root@server:~# cp 000-default.conf theforce.conf
root@server:~# cp 000-default.conf thedarkside.conf

Make Changes to the theforce.conf Virtual Host

root@server:~# sudo nano theforce.conf

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/theforce
  ServerName theforce.com
  ServerAlias theforce.com
  Redirect permanent /phpmyadmin https://vps12345.vps.ovh.ca/phpmyadmin
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  <Directory /var/www/theforce>
    Options FollowSymLinks
    AllowOverride All
  </Directory>
  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
 
  ErrorLog ${APACHE_LOG_DIR}/error.log
 
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn
 
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> 

Make Changes to the thedarkside.conf Virtual Host

root@server:~# sudo nano thedarkside.conf

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/thedarkside
  ServerName thedarkside.com
  ServerAlias www.thedarkside.com
  Redirect permanent /phpmyadmin https://vps12345.vps.ovh.ca/phpmyadmin
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  <Directory /var/www/thedarkside>
    Options FollowSymLinks
    AllowOverride All
  </Directory>
  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
 
  ErrorLog ${APACHE_LOG_DIR}/error.log
 
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn
 
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> 
Enable The Virtual Hosts Files
root@server:~# a2ensite theforce
root@server:~# a2ensite thedarkside
Configure the Hosts file

root@server:~# sudo nano /etc/hosts

Add the following lines to the bottom of the file:

158.99.999.99    www.theforce.com 
158.99.999.99    www.thedarkside.com
Reload Apache

root@server:~# service apache2 reload

Log into each new WordPress site to complete the website set-up

Open the url for each site in a browser.

www.theforce.com
www.thedarkside.com

You will be forwarded to the WordPress admin site for each domain and prompted to complete the WordPress set-up

Set-Up HTTPS on Your Websites

Setting Up an SSL Certificate with Certbot

Please follow and like us:

Leave a Reply

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