Hosting Ghost Manually on Digital Ocean

I've just recently migrated this blog from Github Static Pages to Digital Ocean. It takes quite some time to make it work because I have limited knowledge on server handling.

There are issues I encountered during migration such as 503 server error, file permission, duplicated virtual hosts, etc.

Mind you, I'm only handling minimal traffic website which, in my case, isn't necessary to follow any procedure that requires effort on keeping the website alive during the process. This is my fingersteps during migration process:

Ghost Upgrade

Notice: I did my upgrade using Casper theme. Not sure if other themes have significant impact on it or not, but this steps should be the basic one.

  1. Making backups is essentially important in migrating process.
    Tl;dr, go to Ghost Admin > Settings > Labs > Export.
    This process will export everything including blog posts and settings, except post image headers and other images you had statically on previous version. Be sure to backup everything before moving on. Or you can do it later.
    Refer to this post for more info.
  2. SSH or FTP into droplet and download a latest copy of Ghost into /var/www/html.
  3. Extract and install that shit with npm install --production
  4. Edit config.js. Go to development section, change host: to droplet IP address.
  5. npm start it and go to http://DROPLET_IP_ADDRESS:2368/ghost in the browser.
  6. Sign up with any name.
  7. Again, go to Settings > Labs > Import. Import the backup json file created in step 1.
    It will import everything we had before into the new environment.
  8. Next, do the less-necessary part which is putting tracking codes, disqus comments script or any UI changes you had on previous version.

Update 13/3/2017:

After an upgrade from 0.6.x to 0.11.x, I did not notice that all these while I'm running this blog in development mode.

Since 0.11.x has the Public API support which I'm consuming on my personal website, things got a little messy since running in dev mode doesn't do all the migration upgrade. Missing tables are what causes the Public API to failed on my end.

Read more here.

Domain Config

In my case, I still want to use as my website URL. Unfortunately, Github Pages have already used this name. So, what I did was to remove or rename the content of CNAME file in my Github repo, for both gh-pages and master branch.

Next, I have to remove the A and CNAME record in my domain manager that is still pointing to Github's IP address and make a new one which points to my droplet's IP address.

So, in my A record now has DROPLET_IP with as the value. This might take awhile to have effect.

Do this on both Digital Ocean and cPanel domain manager.

Server Config (Apache)

I'm only using Apache as my server on the backend. Make sure to enable mod_proxy and mod_proxy_http in Apache config.

a2enmod proxy
a2enmod proxy_http

After that, I created a new virtual host in /etc/apache2/sites-available called Inside, modify the content like below:

<VirtualHost *:80>
   DocumentRoot /var/www/html/
   ErrorLog ${APACHE_LOG_DIR}/www-aimanbaharum-com.error.log
   CustomLog ${APACHE_LOG_DIR}/www-aimanbaharum-com.access.log combined

   ProxyRequests off
   ProxyErrorOverride On
   ProxyPassReverse /
   ProxyPreserveHost on
   ProxyPass / retry=0                                               

The proxy will redirect port 2368 to the DocumentRoot which is where Ghost blog is located.

a2ensite this file to make it enabled. Restart the server by service apache2 restart.

Make it run, forever

Remember during the Github Pages age that I need to npm start and buster generate and deploy every time I want to create a new post and deploy it? Not anymore. This time, I only need to run npm start once and port 2368 will always open for incoming traffic.

Do that with this command:

screen npm start

Then, press Ctrl+A and d to detach the screen. This command will run npm start in the background unless I kill the node process to close the port or I terminate screen session.

Learn more on screen.


Show Comments

Get the latest posts delivered right to your inbox.