WordPress is probably the most popular blogging platform where we can easily use themes and write blog posts. In addition to it, there are thousands of plugins which makes the work so much better.

But if you are one who has to maintain multiple blogs and end up paying lots of money on various servers to host your blogs, there is a way to work around and have multiple WordPress blogs on a single server.

I’ve done it for 4 of my blogs which are currently running on a single Digital Ocean server. I’ll explain how I achieved it –

Note – This article will have terminologies related to the Digital Ocean server but the same method can be applied on servers hosted on any platform.

I’ve used Nginx to serve as my reverse proxy server. With a little change of commands, Apache2 users can also adapt to the below steps.

Step 1 –

Purchase a domain. I find GoDaddy, NameCheap quite nice and they offer the domain at a very reasonable price. Once you purchase the domain, navigate to the DNS settings of your domain and create a new ‘A’ type record. In the Name, add ‘@’ and value would be the IP address of your droplet. Leave the TTL to the default value.

Step 2 –

It is always good to have our website run on HTTPS. For this, we will make use of LetsEncrypt to generate an SSL certificate for our newly mapped domain. We will run the command –

sudo certbot --nginx -d example.com -d www.example.com

replace example.com and www.example.com with your domain name.

After running the command, we will be asked for a choice, i.e. to redirect HTTP calls to HTTPS or not. You can go ahead with the redirect option (#2) and press Enter. That would forward the HTTP request to HTTPS automatically. So we can be assured that the user always loads the secured version of our website.

Step 3 –

Now, let’s begin with the WordPress implementation.

Run the following command –

wget wordpress.org/latest.zip

This will download the WordPress files. Unzip it using the command –

unzip latest.zip

Move the files to /var/www folder –

mv wordpress /var/www/your_site.com

Also, set the ownership of the directory to Nginx. This will help WordPress get access to it. If we skip this step, any file we upload or themes we download through the admin panel in WordPress will not work. Basically, it will allow FTP access from our blog.

chown -R www-data:www-data /var/www/your_site.com

Step 4 –

Since WordPress works with a MySQL DB, we will create a Database for our website.

We will now login into our SQL using the below command –

mysql

It will prompt for username and password. Once successfully authenticated, run the following queries –

CREATE DATABASE database_name;
CREATE USER 'user_name'@'%' IDENTIFIED BY 'use_secure_password_here';
GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'%' WITH GRANT OPTION;

This will create a new MySQL database and a user which is allowed to access it. We will provide these credentials to WordPress for it to store and retrieve the data.

Step 5 –

In our WordPress directory, we can find a wp-config.php file.

In the file, replace the DB_NAME, DB_USER, and DB_PASSWORD with the configurations we just set up in MySQL and save the file.

Step 6 –

Now we will configure Nginx to accept requests for our new domain linked to WordPress. We will also define other configurations needed for WordPress.

Open the Nginx configuration file ‘sites_available’, which is in the ‘/etc/nginx’ directory. And the following block –

server {
listen 443 http2 ssl; 
 server_name website_name.com ;

root /var/www/wordpress_website_name/;
index index.php;

# log files
access_log /var/log/nginx/sample.com.access.log;
error_log /var/log/nginx/sample.com.error.log;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}   
    ssl_certificate /etc/letsencrypt/live/website_name.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/website_name.com/privkey.pem; # managed by Certbot
}

Step 7 –

Check if the Nginx configuration is proper by running the command –

sudo nginx -t

Now we will restart our Nginx server –

sudo systemctl nginx restart

That’s it!

Now when we open your website in the browser, we will see the WordPress admin page which will ask us to create a new user for the website WordPress panel. Go ahead and create one. This will enable access to our WordPress blog.


Once you are set up with your WordPress blog, you would want to make it look and feel better for your readers. Check out this blog here where I talk about my top 10 plugins which are FREE!

Leave a Reply

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