I have read about Ghost Blogging software and wanted to know how it worked. So I installed it on CentOS 6 and this is what I had to do to get to work properly.
Server 1 gig ram, single CPU and 20G ssd hard drive. When running this setup seemed to only using 250mb of memory. Also performance seemed good.
Make sure system is up to date.
# yum update
Install and make sure wget, curl are installed.
# yum install wget curl
Need to install Nginx as a reverse proxy as Ghost runs on port 2368.
# wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# rpm -i nginx-release-centos-6-0.el6.ngx.noarch.rpm
# rm -f nginx-release-centos-6-0.el6.ngx.noarch.rpm
# yum -y install nginx
# chkconfig nginx on
Nginx reverse proxy setup. Of course setup ghost.example.com to your domain name.
# nano /etc/nginx/conf.d/ghost.conf
server {
listen 80;
server_name ghost.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://ghost.example.com:2368;
}
}
Now we need to download node.js and NPM.
# curl -sL https://rpm.nodesource.com/setup | bash -
# yum install -y nodejs
Download and setup Ghost Blogging Software.
# mkdir -p /var/www/
# cd /var/www
# wget https://ghost.org/zip/ghost-latest.zip
# unzip ghost-latest.zip
# npm install --production
To start Ghost Server.
# npm start --production
Now you can take a browser and connect to the webserver at http://ghost.example.com:2368 (Of course connect to your domain that you have setup.)
Lets add a new user for ghost
# adduser ghost
To setup Ghost as a service.
# nano /etc/init.d/ghost
#!/bin/sh
#
# ghost - this script starts the ghost blogging package
#
# chkconfig: - 95 20
# description: ghost is a blogging platform built using javascript \
# and running on nodejs
#
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
#exec="/usr/bin/npm start index.js --run-as-user ghost --name ghost"
exec="/usr/bin/node index.js >> /var/log/ghost.log &"
prog="ghost"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
start() {
#[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
export NODE_ENV=production
cd /var/www/
daemon --user=ghost $exec
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
pid=`ps -u $prog -fw | grep $prog | grep -v " grep " | awk '{print $2}'`
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
my_status() {
local base pid lock_file=
base=${1##*/}
# get pid
pid=`ps -u $prog -fw | grep $prog | grep -v " grep " | awk '{print $2}'`
if [ -z "${lock_file}" ]; then
lock_file=${base}
fi
# See if we have no PID and /var/lock/subsys/${lock_file} exists
if [[ -z "$pid" && -f /var/lock/subsys/${lock_file} ]]; then
echo $"${base} dead but subsys locked"
return 2
fi
if [ -z "$pid" ]; then
echo $"${base} is stopped"
return 3
fi
if [ -n "$pid" ]; then
echo $"${base} (pid $pid) is running..."
return 0
fi
}
rh_status() {
# run checks to determine if the service is running or use generic status
my_status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 2
esac
exit $?
Make script executable
# chmod +x ghost
Add this new service.
# chkconfig add ghost
Enable this new service.
# chkconfig ghost on
Create a log file.
# touch /var/log/ghost.log
Change permissions on log file.
# chown ghost:ghost /var/log/ghost.log
Start the Ghost Service.
# service ghost start
Start the Nginx Reverse proxy, so we can connect on port 80.
# service nginx start
You should have a running Ghost Blogging WebServer that you can connect to on port 80.
References:
http://linuxpitstop.com/install-ghost-0-7-0-on-centos-7-and-ubuntu-linux-15-04/
http://georgemastro.com/how-to-start-ghost-on-centos-automatically/
https://www.howtoinstallghost.com/how-to-start-ghost-as-a-service-on-linux/