Best Way To Host Multiple WordPress Sites On A Single Server


🖊 Written by Updated on

WordPress is a very popular CMS, you can build very attractive websites and even awesome blogs. If you have a VPS (Virtual Private Server) or a Cloud hosting instance then you can create multiple sites on a single server.

No, we are not talking about WordPress multisite that is a different thing, suppose you have a cloud hosting with limited resources and also have a budget limitation and you have deployed a Linux compute engine either an Ubuntu system or Debian system.

If you have these resources then, host multiple WordPress sites on a single server or either a Debian server or Ubuntu server, it is very easy.

Just follow the steps.

Prerequisites

For hosting WordPress or even multiple WordPress sites in a single VPS there are some prerequisites:

  1. Setup Domain name with Server
  2. Initial Server Configuration
  3. Install LAMP stack on a server

If you have configured all these three procedures, you can check your installation with immediate impact, if not then you should proceed this three-step before installing multiple WordPress sites.

Creating Databases To Host Multiple WordPress

We are going to install multiple WordPress sites in a single server so we need multiple databases for multiple sites.

WordPress Sites Name

wordpress1.com

wordpress2.com

Database Name

wordpress1

wordpress2

Database Username

wordpress_user1

wordpress_user2

Database Password

wordpress_password1

wordpress_password1

In this tutorial, we have created two databases for two WordPress sites. In case if you have more resources in your Cloud instances then you can create more than two.

For creating databases for hosting multiple WordPress sites, you should follow these commands:

#Create Databases:

$ sudo mysql -u root -p
> CREATE DATABASE wordpress1;

> CREATE DATABASE wordpress2;
creating multiple databases for multiple WordPress

#Create Databases users:

> CREATE USER [email protected];

> CREATE USER [email protected];

#Set Databases Password:

> SET PASSWORD FOR [email protected]= PASSWORD("wordpress_password1");

> SET PASSWORD FOR [email protected]= PASSWORD("wordpress_password2");

#Grant All Privileges:

> GRANT ALL PRIVILEGES ON wordpress1.* TO [email protected] IDENTIFIED BY 'wordpress_password1';

> GRANT ALL PRIVILEGES ON wordpress2.* TO [email protected] IDENTIFIED BY 'wordpress_password2';

#Flush Privileges and exit:

> FLUSH PRIVILEGES;

> exit
setting up databases users and passwords

Now, our database creation has been completed.

Creating Site Root Directories

Sites root directories, there will be stored our WordPress sites, and further when we will upload any media. So, for creating root directories follow the given commands below.

#Change to directory:

$ cd /var/www/html

We need to create our root directories in the html directory, you can create wherever you want but it is the common directory.

#Create a directory for each site:

$ sudo mkdir wordpress1

$ sudo mkdir wordpress2
creating directories for WordPress sites

After changing the directory in html directory, we need to create our site directories. Use the commands, you can create more than two for hosting multiple WordPress websites.

Download WordPress

WordPress is a very popular and user-friendly CMS (Content Management System). We are going to hosting multiple WordPress sites on the Ubuntu server or the Debian server.

For the process of WordPress installation, follow the steps of commands:

#Change directory to root:

$ cd

#Install WordPress:

$ wget -c https://wordpress.org/latest.tar.gz
Downloading WordPress files to root directories

#Extract compressed files:

$ tar -xvzf latest.tar.gz

#Before copying the WordPress files we need copy sample wp-config to the wp-config file:

$ cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
copying wp-config file

#Copy the extracted WordPress file to both sites directory:

Now copy the extracted WordPress files to the sites directory, which was we have created earlier. So, for this process use the following commands:

$ sudo rsync -avP ~/wordpress/ /var/www/html/wordpress1

$ sudo rsync -avP ~/wordpress/ /var/www/html/wordpress2

#Give ownership of directories to Apache:

Now we need to give permission to Apache server for accessing the sites directories, for this process use the following commands:

$ sudo chown -R www-data:www-data /var/www/html/wordpress1/ 

$ sudo chmod 755 -R /var/www/html/wordpress1/ 

$ sudo chown -R www-data:www-data /var/www/html/wordpress2/ 

$ sudo chmod 755 -R /var/www/html/wordpress2/ 
giving directories permissions

Configure WordPress with Databases

Now, after the installation of WordPress, we need to configure the database credential to WordPress’s wp-config file. You can skip this process for now but when you are going to browse your site, it will prompt you to configure your databases with WordPress.

#Configure First WordPress site:

$ sudo nano /var/www/html/wordpress1/wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress1' );

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

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

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

#Configure Second Site:

$ sudo nano /var/www/html/wordpress2/wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress2' );

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

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

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

Configure Apache Virtual Host

Apache virtual host can handle http request, according to apache.org the virtual host refers to the practice of running more than one web site in a single server.

So, we are going to create an Apache virtual host for our websites, you can create many as you want. We are going to create two host file, for this process you should use the following commands:

#Create Virtual Host for the first WordPress site:

$ sudo nano /etc/apache2/sites-available/wordpress1.conf

#Insert Virtual Host Code from here

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

     <Directory /var/www/html/wordpress1>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/wordpress1.com_error.log
     CustomLog ${APACHE_LOG_DIR}/wordpress1.com_access.log combined

</VirtualHost>

#Create Virtual Host for Second WordPress site:

$ sudo nano /etc/apache2/sites-available/wordpress2.conf

#Insert Virtual Host Code from here:

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

     <Directory /var/www/html/wordpress2>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/wordpress2.com_error.log
     CustomLog ${APACHE_LOG_DIR}/wordpress2.com_access.log combined

</VirtualHost>

#Rewrite Apache modules for Virtual host of Frist Site:

$ sudo ln -s /etc/apache2/sites-available/wordpress1.conf /etc/apache2/sites-enabled/wordpress1.conf

$ sudo a2enmod rewrite

$ sudo systemctl restart apache2

#Rewrite Apache modules for Virtual host of Second Site:

$ sudo ln -s /etc/apache2/sites-available/wordpress2.conf /etc/apache2/sites-enabled/wordpress2.conf

$ sudo a2enmod rewrite

$ sudo systemctl restart apache2

Checking the Results

After all the process, now you need to configure your WordPress websites. So, first of all, open your domain name in the browser tab and if you got the same visuals as in the image below then your WordPress site installation is successful.

Host multiple WordPress sites installation of WordPress

Summary

Hosting multiple WordPress sites on Ubuntu server or the Debian server is very easy now and also affordable for you. Most of the cases, what happens with newbie bloggers, they choose cloud hosting and just install a pre-contained WordPress site in a server. So, there is an issue you can’t install another WordPress in the same machine.

But we have explained how to install or host multiple WordPress sites in a single server, and do not need to pay for any other server for another site. You can host multiple sites in a single server with your pocket-friendly cost.

cPanel or Plesk also have capabilities to install multiple sites in a single server, but there is a big issue, you need to pay for the license of cPanel or Plesk if you take their software also there is another big issue, these software use unnecessary resources of your machine.

So, the best way to hosting multiple websites in a single VPS is to manually install everything and it is very pocket-friendly for you and resource-friendly for your machine. So, check out the blazing-fast managed cloud hosting for WordPress.

Pronay

Hi!
I am a blogger and a digital marketer based in Delhi, India. I have a passion for blogging and influencing people from my work. I am a student pursuing a Bachelor's Degree in Science from Delhi University.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap