Atlantic.Net Blog

Set Up Multiple WordPress Sites on Single VPS

WordPress is free, open-source, and the most popular content management system based on PHP and MySQL. It is a customizable CMS supporting plugins that allows you to set up blogs and websites easily. WordPress provides a rich set of features and benefits including publishing tools, flexibility, simplicity, media management, user management, an easy theme system, customizability, and more. If your Linux system has 1 CPU and 4GB RAM, you can run multiple WordPress sites on a single server. Apache virtual host allows you to host multiple WordPress sites on a single server with a single IP address and multiple domain names.

In this tutorial, we will learn how to host multiple WordPress sites on a single VPS.

Prerequisites

  • A fresh Ubuntu 18.04 server VPS on the Atlantic.Net Cloud Platform.
  • Two valid domain names or subdomain names are pointed at your VPS IP address.
  • In this tutorial, we will use site1.example.com and site2.example.com subdomains to host WordPress sites.

Step 1 – Install a LAMP Server

Before starting, you will need to install Apache web server, MariaDB server, PHP and other PHP modules on your server. You can install all of them with the following command:

apt-get install apache2 mariadb-server php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-mcrypt php7.2-ldap php7.2-zip php7.2-curl unzip -y

Once all the packages are installed, open the php.ini file and tweak some settings:

nano /etc/php/7.2/apache2/php.ini

Change the following lines:

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

Save and close the file. Then, start Apache and MariaDB service and enable them to start after system reboot with the following command:

systemctl start apache2
systemctl start mariadb
systemctl enable apache2
systemctl enable mariadb

Step 2 – Configure Database for WordPress

Next, you will need to create a separate database and user for each WordPress site. Here, we will create a wpdb1 database with wpuser1 for site1.example.com and wpdb2 database with wpuser2 for site2.example.com.

To do so, log in to MariaDB shell with the following command:

mysql -u root -p

Provide your root password when prompt then create a wpdb1 and wpdb2 database with the following command:

MariaDB [(none)]> CREATE DATABASE wpdb1;
MariaDB [(none)]> CREATE DATABASE wpdb2;

Next, create a wpuser1 and wpuser2 user, and set the password with the following command:

MariaDB [(none)]> GRANT ALL ON wpdb1.* TO 'wpuser1'@'localhost' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL ON wpdb2.* TO 'wpuser2'@'localhost' IDENTIFIED BY 'password';

Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Step 3 – Download and Install WordPress

Next, you will need to download the latest version of WordPress from their official website. You can download it with the following command:

wget http://wordpress.org/latest.tar.gz

Once downloaded, extract the downloaded file with the following command:

tar -xzvf latest.tar.gz

Next, copy the extracted directory to the Apache root directory for each site:

cp -r wordpress /var/www/html/site1.example.com
cp -r wordpress /var/www/html/site2.example.com

Next, rename the sample configuration file for each site with the following command:

mv /var/www/html/site1.example.com/wp-config-sample.php /var/www/html/site1.example.com/wp-config.php
mv /var/www/html/site2.example.com/wp-config-sample.php /var/www/html/site2.example.com/wp-config.php

Next, open the configuration file for site1 with the following command:

nano /var/www/html/site1.example.com/wp-config.php

Define the database connection info as shown below:

/** The name of the database for WordPress */
define('DB_NAME', 'wpdb1');

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

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

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

Save and close the file. Then, open the configuration file for site2 with the following command:

nano /var/www/html/site2.example.com/wp-config.php

Define the database connection info as shown below:

/** The name of the database for WordPress */
define('DB_NAME', 'wpdb2');

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

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

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

Save and close the file when you have finished.

Note: Make sure database, user and password value matches with that which you have created earlier.

Next, set up proper permissions for each site with the following command:

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

Step 4 – Configure Apache for WordPress

Next, you will need to create an Apache virtual host file for each site.

First, create an Apache virtual host file for site1 with the following command:

nano /etc/apache2/sites-available/site1.example.com.conf

Add the following lines:

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/site1.example.com/
     ServerName site1.example.com

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

     ErrorLog ${APACHE_LOG_DIR}/site1.example.com_error.log
     CustomLog ${APACHE_LOG_DIR}/site1.example.com_access.log combined
</VirtualHost>

Save and close the file. Then, create an Apache virtual host file for site2 with the following command:

nano /etc/apache2/sites-available/site2.example.com.conf

Add the following lines:

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/site2.example.com/
     ServerName site2.example.com

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

     </Directory>
     ErrorLog ${APACHE_LOG_DIR}/site2.example.com_error.log
     CustomLog ${APACHE_LOG_DIR}/site2.example.com_access.log combined
</VirtualHost>

Save and close the file. Then, enable the virtual host configuration file for both sites with the following command:

a2ensite site1.example.com
a2ensite site2.example.com

Next, enable the Apache rewrite module and restart the Apache service with the following command:

a2enmod rewrite
systemctl restart apache2

Step 5 – Access WordPress Web Installation Wizard

WordPress is now installed and configured for two sites. Now, open your web browser and type the URL http://site1.example.com  and http://site2.example.com. You will be redirected to the WordPress installation wizard. Now, follow the WordPress installation wizard and complete the setup for each site.

Conclusion

Congratulations! You have successfully installed and configured two WordPress sites on a single Ubuntu 18.04 VPS. You can also deploy more WordPress sites on a single VPS. If you’re ready to set up your VPS with Atlantic.Net, learn more about our VPS Hosting Solutions here.

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year