Ghost is a free and open source blogging platform written in Node.js, completely customizable, and dedicated to publishing.
We’ll demonstrate the installation by logging into the server as root, so that we will not need to add sudo it before each command. If you are logged in as another user, remember that you will need sudo.
On your Server, run the following to update the package index, upgrade packages, and install Node.js and npm.
apt-get update
apt-get upgrade
apt-get install python software-properties-common gcc g++ make -y # auto install
add-apt-repository ppa:chris-lea/node.js -yThe output from these commands should be similar to:
gpg: keyring /tmp/tmpvpe2ugzj/secring.gpg' created
gpg: keyring /tmp/tmpvpe2ugzj/pubring.gpg' created
gpg: requesting key C7917B12 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpvpe2ugzj/trustdb.gpg: trustdb created
gpg: key C7917B12: public key "Launchpad chrislea" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OKAutomatically, the package signing key will be added to the keyring (so that the packages downloaded can be verified), and the PPA will be added to APT’s sources.list.d.
Now, let’s run:
apt-get update # again
apt-get install nodejs -yRun npm to test the installation. You will see npm‘s usage printed to the screen:
Usage: npm <command>
...
...
npm@1.4.28 /usr/lib/node_modules/npmNow, we can install Ghost.
Since Ghost is now considered stable, it can be installed through npm. Install it with the following command:
npm install -g ghost --productionIgnore any warnings for now.
Next, we will start Ghost and check if it’s working properly.
cd /usr/lib/node_modules/ghost
npm start --productionThe output should look like this:
> ghost@0.5.2 start /usr/lib/node_modules/ghost
> node index
Migrations: Database initialisation required for version 003
...
Migrations: Complete
Ghost is running...
Your blog is now available on http://my-ghost-blog.com
Ctrl+C to shut downIt works! Use Ctrl-C to shut down Ghost and move on to the next step: installing (and configuring) Nginx.
Nginx is very simple to install. Run the following command:
apt-get install nginxNginx will be configured to allow connections from anywhere in the world to port 80 (or 443, if using SSL) your server, which is then forwarded proxied to Ghost. This is how people connect to your blog.
Configuring Nginx is not that hard, either. Follow these steps to configure the Ghost proxy.
First, remove the default configuration file:
cd /etc/nginx/
rm sites-enabled/defaultThen, make a new configuration file:
cd sites-available
touch ghostAdapt the following lines to your needs and use something like nano or vi to paste it in (you’ll need to set server_name to your domain name:
server {
listen 80;
server_name yourdomain.tld;
access_log /var/log/nginx/yourdomain.tld.log; # if you want logging
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_pass http://127.0.0.1:2368;
proxy_redirect off;
}
}Symlink your configuration file:
cd /etc/nginx
ln -s sites-available/ghost sites-enabled/ghostservice nginx restartAt this point, Nginx is installed, configured, and running on your server.
Finally: Start Ghost AutomaticallySupervisor is a process control system that allows you to run Ghost at startup without using init scripts. We will be installing Supervisor to manage Ghost.
To install Supervisor, run:
apt-get install supervisor
service supervisor startThen, create a new script file in /etc/supervisor/conf.d/ghost.conf. Paste in these contents:
[program:ghost]
command = node /usr/lib/node_modules/ghost/index.js
directory = /usr/lib/node_modules/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"Next, we need to create a user for Ghost and permit it to access the Ghost files and database. Run the following commands:
useradd ghost
chown -R ghost /usr/lib/node_modules/ghost/
supervisorctl reread
supervisorctl updateNow you can control Ghost by executing supervisorctl start ghost and supervisorctl stop ghost.