Check this Out!Visit our social network pages for recent updates!

Students question – How to Run Multiple WordPress Blogs on a Single Ubuntu Host?

How does one run multiple wordpress sites on a single Ubuntu 16.10 (Yakkety Yak) server? Multiple unique domains with their own WordPress content? Is that possible?

Yes one can run multiple WordPress blogs from a single Ubuntu server.  When you want to run multiple websites running WordPress from a single host, this guide is going to show you how you can accomplish that with WordPress and Apache2 web server.

As you may well know by now, WordPress depends on the LAMP stack to function. Without that stack, you won’t be able run WordPress. When we’re done, you’ll be able to host two or more unique domains running WordPress blogs on one Ubuntu server. When you’re ready, continue below:

Step 1: Install the LAMP Stack on Ubuntu

Again, install the LAMP stack on Ubuntu for this to work. We’ve already written a tutorial on install it. To view that tutorial check the link below. Follow the link to install LAMP and return to this post and continue.

https://websiteforstudents.com/question/install-lamp-stack-ubuntu-server/

Step 2: Creating WordPress databases and Users

After installing the LAMP stack, go and create as many WordPress sites databases as you wish. For this tutorial, we’re going to create two unique WordPress sites. These two sites will two unique databases.


WordPress Site 1 Database = wpsite1db

WordPress Site 2 Database = wpsite2db


To create the databases, logon to MySQL server by running the commands below:

sudo mysql -u root -p

Then run the statements below to create both sites databases

CREATE DATABASE wpsite1db;
CREATE DATABASE wpsite2db;

After creating the databases, go and create two accounts to manage these databases.


WordPress Site 1 Database User = wpusersite1

WordPress Site 2 Database User = wpusersite2


Now run the SQL statements below to create the database user accounts for both sites

CREATE USER 'wpusersite1'@'localhost';
CREATE USER 'wpusersite2'@'localhost';

Next, run the statements below to set the password for each account

SET PASSWORD FOR 'wpusersite1'@'localhost' = PASSWORD('type_password_here');
SET PASSWORD FOR 'wpusersite2'@localhost' = PASSWORD('type_password_here');

Next, run the statements below to grant the user accounts full access to the databases above.

GRANT ALL ON wpsite1db.* TO 'wpusersite1'@localhost';
GRANT ALL ON wpsite2db.* TO 'wpusersite2'@'localhost';

Run the command below to save the above changes

FLUSH PRIVILEGES;

Then exit the database server by running the command below

exit

Step 3: Downloading WordPress and Configuring the Sites

After creating the databases and user accounts for both websites, go and download WordPress content. To download WordPress, run the commands below.

cd /tmp/ && wget http://wordpress.org/latest.tar.gz

Then run the commands below to extract the downloaded content.

tar -xvzf latest.tar.gz

Next, create two root directories for both websites in the /var/www/html default folder. This location is the default location for Apache2 web server. Since we’re creating two custom websites, let’s create those inside the /var/www/html directory.


WordPress Site 1 Directory = /var/www/html/wpsite1

WordPress Site 2 Directory = /var/www/html/wpsite2


Run the commands below to create both directories

sudo mkdir /var/www/html/wpsite1
sudo mkdir /var/www/html/wpsite2

After creating those directory, copy the downloaded WordPress content into both sites’ root directories. You can do that by running the commands below.

sudo cp -r /tmp/wordpress/* /var/www/html/wpsite1
sudo cp -r /tmp/wordpress/* /var/www/html/wpsite2

When you’re done, create WordPress’ wp-config.php configuration files into both site directories. You can accomplish that by running the commands below.

sudo cp /var/www/html/wpsite1/wp-config-sample.php /var/www/html/wpsite1/wp-config.php
sudo cp /var/www/html/wpsite2/wp-config-sample.php /var/www/html/wpsite2/wp-config.php

Next, open each of the site configuration file and configure the database connection settings for each site.

WordPress Site 1 Configuration:

sudo nano /var/www/html/wpsite1/wp-config.php

Then edit the file and make the highlighted changes below:

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wpsite1db‘);

/** MySQL database username */
define(‘DB_USER’, ‘wpusersite1‘);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘wpusersite1_password_here‘);

Save your changes when done.

WordPress Site2 Configuration:

sudo nano /var/www/html/wpsite2/wp-config.php

Then edit the file and make the highlighted changes below:

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wpsite2db‘);

/** MySQL database username */
define(‘DB_USER’, ‘wpusersite2‘);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘wpusersite2_password_here‘);

Save your changes when done.

After configuring the changes above, continue below to configure the directory permissions. We want WordPress to function correctly. To do that, run the commands below.. this will apply to both sites’ directories

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

Step 4: Configuring Sites Apache2 VirtualHosts

Now that both sites have their databases and directories created and configured, let’s go and create two VirtualHost for our sites.


WordPress Site 1 VirtualHost File = /etc/apache2/sites-available/wpsite1.conf

WordPress Site 2 VirtualHost File = /etc/apache2/sites-available/wpsite2.conf


First, we’ll copy Apache2 default site configuration file to make our two VirtualHost files.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wpsite1.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wpsite2.conf

Then open each VirtualHost file and make the highlighted changes:

Site 1 VirtualHost Confiugration:

sudo nano /etc/apache2/sites-available/wpsite1.conf

<VirtualHost *:80>
        # However, you must set it for any further virtual host explicitly.
        ServerName website1.com
        ServerAlias www.website1.com
        ServerAdmin webmaster@website1.com
        DocumentRoot /var/www/html/website1.com
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Site 2 VirtualHost Configuration:

sudo nano /etc/apache2/sites-available/wpsite2.conf

<VirtualHost *:80>
        # However, you must set it for any further virtual host explicitly.
        ServerName website2.com
        ServerAlias www.website2.com
        ServerAdmin webmaster@website2.com
        DocumentRoot /var/www/html/website2.com
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Save your changes and continue below.

After all the changes above, this is the time to enable both sites.. To do that, run the commands below.

sudo a2ensite wpsite1.conf
sudo a2ensite wpsite2.conf

Restart Apache2 web server.

sudo systemctl restart apache2

Restart Apache2 web server and go to the website URLs and you should see WordPress default setup pages.

WordPress default setup page

That’s it!

This is how you setup multiple WordPress websites on a single host. If you want to add another website, just follow the guide above and do the same you did for site1 and site2 to create site3

Enjoy!