[Ghost] Install along with Apache

How to run a Ghost blog on a server running an Apache server.
This guide has been tested with Ubuntu server 14.04.1.

Since all commands needs admin rights, you should first type

sudo -s    

Install Apache

apt-get update
apt-get install apache2

Install node.js

The nodejs package included in Ubuntu is obsolete, so we're gonna use the one from Chris Lea's repository.

apt-get install -y python-software-properties python g++ make
add-apt-repository -y ppa:chris-lea/node.js
apt-get update
apt-get install nodejs

Install Ghost

Create download and install ghost

mkdir /var/www/ghost
cd /var/www/ghost

wget https://ghost.org/zip/ghost-latest.zip
unzip -uo ghost-latest.zip
rm ghost-latest.zip    

npm install --production

Configure Ghost

cp config.example.js
nano config.js

Here you only need to change the url in the production configuration.

 production: {
    url: 'http://example.com',
    mail: {},

Run Ghost as a service

nano /etc/init/ghost.conf

And paste the following content:


description "Ghost Blog"
author "Your name"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

respawn limit 99 5

    export NODE_ENV=production
    exec /usr/bin/npm start /var/www/ghost 2>&1 >> /var/log/ghost.log    
end script

Exit nano and save the file. Then run:

chmod 644 /etc/init/ghost.conf

From now on, starting Ghost as a service is as simple as:

service ghost start

Configure Apache

Here we're gonna create a new ghost site which is just a proxy to localhost:2368. But first, we need to enable the module proxy_http in apache.

a2enmod proxy_http

And now create the site:

nano /etc/apache2/sites-available/ghost.conf

And paste:

<Virtualhost *:80>
  ServerName example.com
  ServerAdmin support@example.com
  ProxyPass        /  http://localhost:2368/
  ProxyPassReverse /  http://localhost:2368/

Exit nano, save the file. Then:

chmod 644 /etc/apache2/sites-available/ghost.conf

# disable the default site installed with Apache
a2dissite default

# enable our "ghost" site
a2ensite ghost


service apache reload

And your blog should be online

Configure logrotate (optional)

As Ghost creates a lot of log, you should consider configuring logrotate(8) to rotate and compress the logs.

Create /etc/logrotate.d/ghost with the following content:

/var/log/ghost.log {
    rotate 12
      service ghost stop
      service ghost start

Enable SSL (optional)

I wrote another article to explain how to enable HTTPS: Enable SSL in Apache