Easy installation of Ghost Blog

“Ghost Blog” is a blogging platform. Just blog. If you are into blogging and sharing your thoughts and nothing else, then you will definitely looking for this one. Very lightweight and super stylish with simplicity look. It is a platform where you will be motivated to write. But it is tricky to install. I will make it simple here.Ubuntu 12.04.4 LTS is my VPS which i am using to show you how to install easily. We will do install nodejs , nginx , mysql etc.

ghost

Step:1 NodeJS

Add nodejs repository and install it.

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

Now check if it is really installed or not.

node -v
npm -v

Step:02 Installation of Ghost

Check or install Curl

apt-get install curl

Now use below code to download the ghost archive file to install.

curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

We need to extract to a folder which is familiar to you. I will use /var/www/

unzip -uo ghost.zip -d /var/www/ghost

Then go into the ghost folder

cd /var/www/ghost/

To install Ghost type: (Note 2 Dashes before production)

npm install --production

Above command is very very important when you transfer ghost blog to another vps.

Now we need to check if it starts or not.

npm start

If starts , you can now just ctrl+c to terminate. Terminate it.

You can start ghost as production too.

npm start --production

Now we need to edit config file. That file should be in /var/www/ghost/

nano /var/www/ghost/config.js

Now find  // ### Production. This is the start of Production based configuration. Also find // Developers only need to edit below here and above this line end of Production based configuration. I am helping you what to keep there and add too.

// ### Production
    // When running Ghost in the wild, use the production environment
    // Configure your URL and mail settings here
    production: {
        url: 'http://domain.com',
        mail: {
                transport: 'SMTP',
                options: {
                service: 'Sendmail',
                        }
                },
        database: {
            client: 'mysql',
            connection: {
                    host: 'localhost',
                    user: 'root',
                    password: 'password',
                    database: 'database',
                    charset: 'utf8'
            }
    },

        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        }
    },

Above is a good configuration. First red marked domain is the domain by which you want to use your ghost blog. Change it to yours. Second red marked text is for mysql database. You have to create it by terminal or phpmyadmin. Use localhost if you are in same machine where your ghost is. change mysql database user , password , database according to yours. Then the red marked IP , you have to edit it to your VPS/server IP address. and change the red marked port as your wish.

Save it.

Step:03 Init Script (One Way)

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.
Create the file /etc/init.d/ghost with the following command:

sudo curl https://raw.github.com/TryGhost/Ghost-Config/master/init.d/ghost 
  -o /etc/init.d/ghost

Open the file with nano /etc/init.d/ghost and check the following:
Change the GHOST_ROOT variable to the path where you installed Ghost
Check if the DAEMON variable is the same as the output of which node
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 /var/www/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.

Step:03 Init Script (Another Way)

Create a blank file as ghost.conf in /etc/init/ folder.

touch /etc/init/ghost.conf

Now edit that file by nano and put below code.

# ghost

start on startup

script
cd /var/www/ghost
npm start --production
end script

And save that file. Now you can start and stop the service by simply running below command.

service ghost start
service ghost status
service ghost restart
service ghost stop

This will also act as an auto start configuration file when reboot the server.

Step:04 Run With Apache Virtual Host

Let you want to use Ghost blog by http://domain.com , you need to create a vhost file in /etc/apache2/sites-available/

nano /etc/apache2/sites-available/domain.com.vhost

Paste below codes.

<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/
ProxyPreserveHost On
</VirtualHost>

Change your server/vps ip and port according to your ghost config. Also change the domain name. This is a reverse proxy config. We need to ensure if it is enabled or not.

sudo a2enmod proxy proxy_http

Now enable the vhost file.

ln -s /etc/apache2/sites-available/domain.com.vhost /etc/apache2/sites-enable/domain.com.vhost

Restart apache.

sudo service apache2 restart

Start Ghost

service ghost restart

and you are good to go.

External Post:

I have showed you how to install ghost with Apache server. But Apache is heavy and you can’t just rely on it for huge traffic and if you rely it will be very costly. You can run a ghost blog and handle almost huge traffic by a 128mb vps.

Install Ghost Blog With Lighttpd and Mariadb

lighttpd and Mariadb is perfect. You can rely on those. Happy blogging.

One thought on “Easy installation of Ghost Blog”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.