Setup Multiple WordPress Sites on one host a single VPS
Posted on May 28th, 2019
VPS stands for Virtual Private Server, also known as VM(Virtual Machine). We can also call these VPS/VMs a host for our WordPress sites as they hold our WordPress files and data. In this tutorial, I will show you how you can configure multiple WordPress sites on one Host or a single VPS.
You can also use VPS to host all the WordPress websites that you own. It is cost effective as well as your WordPress websites can get all the resources they need to perform as fast as possible.
This is a step-by-step guide that you can follow with few prerequisites. Here is what you need to follow this guide.
- A VPS/VM with Apache, MySQL and PHP (LAMP server) installed.
- Root access to the server.
Note: Follow this guide to Install LAMP server on Ubuntu.
We need root access to perform this task as we have to create a few files called virtual hosts. Once you are ready with a server having Apache, MySQL and PHP with root access, we can get started.
Create DocumentRoot for WordPress websites
Document root is a directory in which we can store our website files. In case of WordPress, we will store WordPress files inside the document root of a specific website. I will use example.com and example2.com as domain names in this tutorial. Do not forget to replace these domain names with yours.
In this tutorial, I will create Document roots inside /var/www
directory. But you can also create document root in a user’s home directory in case you want to isolate the WordPress installations. Execute the following command to create document roots as well as directory to store error and access logs of two websites.
mkdir -p /var/www/{example.com,example2.com}/{logs,public_html}
The -p
flag in the command allows us to create nested directories. In this case, It is allowing us to create logs and public_html directories inside both example.com and example2.com directories.
Here, the public_html directory inside both the parent directory is known as document root. As our document roots are ready, we can create a sample index file for both the websites. Execute the following commands to perform the task.
echo “Hello world from example.com” >> /var/www/example.com/public_html/index.html
echo “Hello world from example2.com” >> /var/www/example2.com/public_html/index.html
Once created, we can move on to create virtual hosts for both the websites.
Create Virtual Hosts for WordPress websites
Virtual hosts are the configuration files that tells our web server to route requests based on the domain name to their respected directory. It also tells the web server what file to look for, what rules to apply and where to store error and access logs for the specific website or virtual host.
As we have two websites to host right now, We have to create two files for two different domain names at the below given location and content.
- Location: /etc/apache2/sites-available/example.conf
- Content:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_htmlErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined<Directory />
Options FollowSymLinks
AllowOverride None</Directory>
<Directory /var/www/example.com/public_html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
Allow from all</Directory>
</VirtualHost>
Do not forget to replace example.com with your domain name in the file contents as well as the filename. You can directly create a file and copy-paste the edited content by executing the following command.
sudo nano /etc/apache2/sites-available/example.conf
After writing the updated content, press CTRL+X followed by Y to save the file. You have to create this virtual host file for all the domain names you want to host on the VPS. In this case, we have to create virtual host files for example.com and example2.com.
Now, It’s time to create databases for our WordPress websites.
Create Databases for WordPress websites
It is very easy to create databases for our WordPress sites as we do not have to edit or create any file in this part. Log in to the MySQL command line interface using the following command.
mysql -uroot -p;
It will ask you for root password which you should know. Once you have access to MySQL command line interface, execute the following commands to create user and database for our first WordPress website.
> CREATE DATABASE example;
> CREATE USER ‘example‘@’localhost’ IDENTIFIED BY ‘RANDOM_PASSWORD‘;
> GRANT ALL PRIVILEGES ON example.* TO ‘example‘@’localhost’;
> FLUSH PRIVILEGES;
Similarly, repeat these commands to create a database and user for your second WordPress website. Do not forget to replace example and RANDOM_PASSWORD with your desired database, database username and password.
> CREATE DATABASE example2;
> CREATE USER ‘example2‘@’localhost’ IDENTIFIED BY ‘RANDOM_PASSWORD‘;
> GRANT ALL PRIVILEGES ON example2.* to ‘example2‘@’localhost’;
> FLUSH PRIVILEGES;
Once done, you can close the MySQL command line interface using the exit
command. Our database and MySQL users are ready. Now, We have to download and extract WordPress files in our document root.
Also, Note down the username, database name and the password as we will need it in future to create the WordPress configuration file.
Download and Extract WordPress files
The next thing we have to do is to remove the basic index files we have created in the public_html directory of both of our websites. We also have to download and extract WordPress files so that we can install WordPress by directly accessing the URL in the browser.
Execute the following commands to remove the basic index file, Download the Latest WordPress and extract WordPress files in the document root.
cd /var/www/example.com/public_html
rm -rf index.html
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress/* ./
rm -rf wordpress latest.tar.gz
Similarly, we have to execute these commands to perform the same task for another domain too.
cd /var/www/example2.com/public_html
rm -rf index.html
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress/* ./
rm -rf wordpress latest.tar.gz
Once you have performed this task for both the websites/domains, Execute the following commands to set the ownership of the files. We need to give ownership of the files to the web server so that we can allow WordPress to create, manage and delete files and directories in our WordPress installation directory.
chown -R www-data:www-data /var/www/example.com
chown -R www-data:www-data /var/www/example2.com
The last thing we have to do in this step of the setup is to enable both the virtual hosts so that our web server can start routing traffic based on the domain name. Execute the following commands to enable the virtual hosts in Apache.
a2ensite example.conf
a2ensite example2.conf
Note that we have to use the exact same virtual host file names here. You can also remove .conf
from the end of the filename and it will still work. After executing both the commands, execute the following command to reload the Apache configuration to apply the changes.
service apache2 reload
Finally, all the configuration part is done. Now, we just have to install WordPress from the browser.
Install WordPress from Browser
Now, all we have to do is to access our domain names in the browser one-by-one and enter the database information to create a WordPress configuration file.
So, open up a new tab in your browser and access any one of the domain name you are trying to configure on the server. You should see a screen just like the following image.
In this step, select the language you are comfortable with and hit the Continue button given on the bottom of the card. In the next step, click on the Let’s Go! button and then you should see a screen just like the following image.
In this form, Enter the information of database and database user we just created. In this case, I have entered the information I have used to create the database for example.com. If the database information you are entering is correct, you will see a screen just like the following image after clicking the Submit button.
Click on the Run the installation to set your WordPress Title, WordPress username, WordPress password and some other settings like these.
Finally, Click on the Install WordPress button given after the form to install WordPress on the first domain name.
Now, access the another domain name in the new tab of your browser and repeat the same WordPress installation steps to install WordPress on another website too.
Conclusion
Congratulations, You have successfully configured two WordPress sites on one host or a single VPS. And the good news is, you can add as many websites as you want on a single VPS. If you want to add 3rd website on a same VPS, Follow these steps:
- Create document root in
/var/www
directory with two sub-directories namedlogs
andpublic_html
. - Create a virtual host file inside
/etc/apache2/sites-available
just like we created for these two websites. - A database to store data of your 3rd WordPress installation.
- Download and extract WordPress files in a document root of your 3rd website.
- Install WordPress from your browser by accessing the URL of your 3rd website.
That’s all it takes to configure multiple WordPress sites on one host or a single VPS. It might go wrong a first few times and you might face some issues but once you understand the process, it will become very easy to configure multiple WordPress sites on one host.
If you are facing any issue with setup, Please contact our support for help.
Hi,
I had 8 – 10 WordPress sites on shared hosting with hostinger. Now my hostinger a/c expired. I already download all backup files. Now I purchased a contabo VPS server. How and where can I upload these files in VPS so all my sites run smoothly?
Better choose a control panel like cPanel or Directadmin for the VPS. They have inbuilt tools to restore the backup or use FTP (via Filezilla) to upload the backup to the server.
‘Interserver’ is providing free migration and Directadmin license (up to 10 domains) along with Slice 4 and above VPS.
I was faced with the task of setting up three independent WP sites on a dedicated server. This article told me exactly how to do it. I followed through the instructions and now have the three sites working perfectly. Many thanks.