/ ghost

Setting up Ghost on Uberspace (< v1.0)

To set up Ghost on Uberspace, you can either use one of the already available Node.js versions (see this helpful guide, thanks to Uberspace for pointing me to it) or install your own local version by choosing one of these ways.

Update 2017-08-26: This how-to is only for Ghost < v1.0, I have edited this post accordingly - See the helpful post by Kevin for installing Ghost v1.0 without ghost-cli on Uberspace.

Update 2013-10-15:

I chose to install my own local version and followed the first way:

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh

The directory ~/node-latest-install might be removed afterwards.

Setting up Ghost (<1.0)

mkdir -p ~/node-prjs/ghost
cd ~/node-prjs/ghost

Download Ghost from https://en.ghost.org/ and extract the archive into the created directory.

npm install --production    # This will take a while

Copy config.example.js to config.js and edit the section labeled production accordingly:

    production: {
        url: 'http://ghost.example.org/', 
        mail: {
            transport: 'SMTP',
            host: 'subdomain.uberspace.de',
            options: {
                service: 'Mail',
                auth: {
                    user: 'username',
                    pass: 'secret'
                }
        }
        },
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },
        server: {
            host: '127.0.0.1',
            port: '63123'
        }
    },

It is important to choose a port number between 61000 and 65535 - you might want to choose a random one like 64391 to avoid conflicts with existing open ports.

Afterwards you should be able to start the server with npm start --production

Setting up a subdomain and Apache for Ghost

Right now Ghost is served by its own webserver. Unfortunately you would have to open a SSH tunnel to access the Ghost server, due to the local bound ip and the port which would have to be opened by the Uberspace admins. This is not convenient for your visitors. Let's setup some forwarding in Apache instead.

Let's assume we want to access our blog using the subdomain ghost.example.org. At first we have to create a directory that we can map to the subdomain:

cd /var/www/virtual/<username>
mkdir html/ghost
ln -s html/ghost ghost.example.org

Next, we need to create a .htaccess that forwards all requests to ghost.example.org (over HTTP) to our internal Node webserver:

cd html/ghost
cat <<EOF > .htaccess
RewriteEngine On
RewriteRule ^(.*) http://127.0.0.1:63123/$1 [P]
EOF

When opening the URL ghost.example.org in a browser, the Ghost landing page should be visible.

If the subdomain cannot be resolved you should check the DNS entries.

Creating a service

If you are quitting the SSH session and don't run a terminal multiplexer like screen or tmux, then you need to set up a service. Running a service ensures that the Ghost server is also automatically started in case of a server reboot.

Setup the service environment and create the inital service:

test -d ~/service || uberspace-setup-svscan
uberspace-setup-service ghost env NODE_ENV=production node ~/node-prjs/ghost/index.js 2>&1

Edit the file ~/service/ghost/run and add a cd to the Ghost directory right before starting the server with exec:

cd $HOME/node-prjs/ghost/
exec /bin/env NODE_ENV=production node /home/<user>/node-prjs/ghost/index.js 2>&1

Start the service with:

svc -u ~/service/ghost

That's it. Enjoy Ghost on Uberspace!

In case the setup doesn't work for you, please send me a tweet or try some other contact option.