Getting Ghost Live
So you’re ready to get Ghost live? Excellent!
The first decision you need to make, is whether you want to install and setup Ghost yourself, or whether you prefer to use an installer.
There are a couple of options for simple installers at the moment:
- Deploy to the cloud with Bitnami.
- Launch Ghost with Rackspace deployments.
- Get up and running with a DigitalOcean Droplet.
You’re going to need a hosting package that already has, or will allow you to install Node.js. This means something like a cloud (Amazon EC2, DigitalOcean, Rackspace Cloud), VPS (Webfaction, Dreamhost) or other package that has SSH (terminal) access & will allow you to install Node.js. There are plenty around and they can be very cheap.
What won’t work at the moment, is cPanel-style shared hosting as this is usually aimed specifically at hosting PHP. Although some offer Ruby, and so may offer Node.js in the future as they are somewhat similar.
Unfortunately, many of the Node-specific cloud hosting solutions such as Nodejitsu & Heroku are NOT compatible with Ghost. They will work at first, but they will delete your files and therefore all image uploads and your database will disappear. Heroku supports MySQL so you could use this, but you will still lose any uploaded images.
The following links contain instructions on how to get up and running with:
- A2 Hosting – (autoinstaller)
- DigitalOcean – from Corbett Barr
- Dreamhost – from howtoinstallghost.com
- Webfaction – from howtoinstallghost.com
- Rackspace (Ubuntu 13.04 + linux service) – from Gilbert Pellegrom
- Ubuntu + nginx + forever – from Gregg Housh
- …check outhowtoinstallghost.com for more guides …
Making Ghost run forever
The previously described method to start Ghost is npm start. This is a good way to do local development and tests, but if you start Ghost using the command line it will stop whenever you are closing the terminal window or log out from SSH. To prevent Ghost from stopping you have to run Ghost as a service. There are two ways to accomplish this.
You can use
forever to run Ghost as a background task.
forever will also take care of your Ghost installation and it will restart the node process if it crashes.
- To install
npm install forever -g
- To start Ghost using
foreverfrom the Ghost installation directory type
NODE_ENV=production forever start index.js
- To stop Ghost type
forever stop index.js
- To check if Ghost is currently running type
PM2 is a more advanced solution than node-forever for NodeJS applications. In addition to automatically restart on crash, it also allows you to deploy your code easily, to generate init script to restart your apps on server reboot and finally to reload Ghost without any downtime.
- To install
npm install pm2 -g
- To launch Ghost on your server do
NODE_ENV=production pm2 start index.js --name "Ghost"
- To stop Ghost
pm2 stop Ghost
- To restart
pm2 restart Ghost
- And to reload Ghost without downtime
pm2 reload Ghost
Regarding Ghost deployment (from local to remote) : https://github.com/Unitech/pm2#deployment
- Regarding init script generation : https://github.com/Unitech/pm2#startup-script
Popular Linux distributions—such as Fedora, Debian, and Ubuntu—maintain a package for Supervisor: A process control system which allows you to run Ghost at startup without using init scripts. Unlike an init script, Supervisor is portable between Linux distributions and versions.
- Install Supervisor as required for your Linux distribution. Typically, this will be:
apt-get install supervisor
yum install supervisor
— Most other distributions:
- Ensure that Supervisor is running, by running
service supervisor start
- Create the startup script for your Ghost installation. Typically this will go in
[program:ghost] command = node /path/to/ghost/index.js directory = /path/to/ghost user = ghost autostart = true autorestart = true stdout_logfile = /var/log/supervisor/ghost.log stderr_logfile = /var/log/supervisor/ghost_err.log environment = NODE_ENV="production"
- Start Ghost using Supervisor:
supervisorctl start ghost
- To stop Ghost:
supervisorctl stop ghost
You can see the documentation for Supervisor for more information.
Linux systems use init scripts to run on system boot. These scripts exist in /etc/init.d. To make Ghost run forever and even survive a reboot you could set up an init script to accomplish that task. The following example will work on Ubuntu and was tested on Ubuntu 12.04.
We have a working init script which you can use to configure your server. The file exists in the Ghost Config repository on GitHub. To install this, follow the steps below:
- Create the file /etc/init.d/ghost with the following command:
$ sudo curl https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost \ -o /etc/init.d/ghost
- Open the file with
nano /etc/init.d/ghostand check the following:
GHOST_ROOTvariable to the path where you installed Ghost
Check if the
DAEMONvariable is the same as the output of
The Init script runs with it’s own Ghost user and group on your system, let’s create them with the following:
$ sudo useradd -r ghost -U
- Let’s also make sure the Ghost user can access the installation:
$ sudo chown -R ghost:ghost /path/to/ghost
- Change the execution permission for the init script by typing
$ sudo chmod 755 /etc/init.d/ghost
- Now you can control Ghost with the following commands:
$ sudo service ghost start $ sudo service ghost stop $ sudo service ghost restart $ sudo service ghost status
- To start Ghost on system start the newly created init script has to be registered for start up. Type the following two commands in command line:
$ sudo update-rc.d ghost defaults $ sudo update-rc.d ghost enable
- Let’s make sure your user can change files, config.js for example in the Ghost directory, by assigning you to the ghost group:
$ sudo adduser USERNAME ghost
If you now restart your server Ghost should already be running for you.