web analytics

How To Host Multiple Ghost Blogs on Ubuntu 12.04 Using Apache

Introduction

Ghost is a new blogging engine that was built using node.js, so it can’t be run like a PHP-based blogging engine, such as WordPress. Ghost was born to return the essence of blogging, blogging that focused on content. Therefore, Ghost has a very simple design both on the public page and admin page. Ghost doesn’t use MySQL database, it uses SQLite – a database system that stores data in a file.

Running multiple Ghost blogs is not easy as running other blogging engines, because Ghost runs as a service and can’t be accessed directly through a web browser by starting the webserver such as PHP scripts. In this tutorial, you will learn how to host multiple Ghost blogs on Ubuntu 12.04 using Apache.

Prerequisites

We assume that you have a droplet with Ubuntu 12.04 and you have installed the Apache web server, too. So, we will focus on setting up the Apache and Ghost blogs.

We will learn to run two Ghost blogs, it’s just an example, you can use this tutorial to run more blogs.

Installing Ghost

The default document root of Apache is /var/www, you can use this directory to place the Ghost engine. Download and extract Ghost in the document root


cd /var/www/
sudo curl -L -o ghost.zip
unzip -uo ghost.zip -d ghost1
unzip -uo ghost.zip -d ghost2
sudo rm ghost.zip

Then, install Ghost


cd /var/www/ghost1
npm install --production

Do the same on the second Ghost

cd /var/www/ghost2
npm install --production

Configuring Ghost

Open config.js in the first Ghost directory /var/www/ghost1, go to the production section, change the URL, and don’t change any other settings.

sudo nano /var/www/ghost1/config.js


production: {
url: 'http://firstdomain.com',
mail: {},
database: { client: 'sqlite3', connection: { filename: path.join(__dirname, '/content/data/ghost.db') },
debug: false },
server: { host: '127.0.0.1', port: '2368' }
},

Open config.js in the second Ghost directory /var/www/ghost2, this time you have to change the URL and port, you can change the port to 2369, it’s free to use.

sudo nano /var/www/ghost2/config.js


production: {
url: 'http://seconddomain.com',
mail: {}, database: { client: 'sqlite3', connection: { filename: path.join(__dirname, '/content/data/ghost.db') }, debug: false },
server: { host: '127.0.0.1', port: '2369' } },

Configuring Apache

In this case, Apache is running as a proxy, and you use Apache to redirect requests to the Ghost engine which is running as a service.

Create a configuration file /etc/apache2/sites-avaiable/firstdomain.com.

sudo nano /etc/apache2/sites-avaiable/firstdomain.com

Use this config:


<VirtualHost *:80>
ServerName firstdomain.com
ProxyPass /
ProxyPassReverse /
ProxyPreserveHost On
RewriteEngine On
RewriteOptions inherit
</VirtualHost>

Then, create for the second domain /etc/apache2/sites-available/seconddomain.com.

sudo nano /etc/apache2/sites-avaiable/seconddomain.com

Use this config:


<VirtualHost *:80>
ServerName seconddomain.com
ProxyPass /
ProxyPassReverse /
ProxyPreserveHost On
RewriteEngine On
RewriteOptions inherit
</VirtualHost>

The last one, enable mod_rewrite on Apache, this is for enabling clean URL.

sudo a2enmod rewrite

Start All Services

Apache

sudo service apache2 start

Ghost

It’s recommended to run Ghost as a background task, you can use forever to handle it.

Install forever with this command

sudo npm install forever -g

Run the first Ghost
cd /var/www/ghost1

sudo NODE_ENV=production forever start index.js

Run the second Ghost

cd /var/www/ghost1

sudo NODE_ENV=production forever start index.js

You should now have two Ghost blogs running on a single droplet using Apache webserver.