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: 127.0.0.1 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 www.aimanbaharum.com 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 www.aimanbaharum.com 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 www.aimanbaharum.com.conf. Inside, modify the content like below:

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

   ProxyRequests off
   ProxyErrorOverride On
   ProxyPassReverse / http://128.199.93.155:2368/
   ProxyPreserveHost on
   ProxyPass / http://128.199.93.155:2368/ retry=0                                               
</VirtualHost>  

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.


Source

Aiman Baharum

More about this blog https://github.com/aimanbaharum/random-wiki/wiki

Kuala Lumpur, Malaysia http://www.aimanbaharum.com

Subscribe to Knowledge Log

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!