ByteBard How to Deploy a Lightweight CMS Site to DigitalOcean App Platform

Deployment
Facebook Twitter LinkedIn LINE Skype EverNote GMail Yahoo Email

Prologue

Some web programmers prefer PaaS over VPS to delegate server maintenances to a (trustworthy) vendor. This article takes DigitalOcean App Platform as an instance to illustrate the process to deploy a Lightweight CMS site to a PaaS.

System Requirements

If you want to try local deployment before putting your Lightweight CMS site online, check our previous article.

Prepare a Lightweight CMS Site

Clone Lightweight CMS locally and rename it:

$ git clone https://github.com/cwchentw/lightweight-cms.git mysite

Change your working directory to root path of the cloned repo:

$ cd mysite

Save the repo to a remote Git repository (either GitHub or GitLab):

$ git remote set-url origin https://example.com/user/mysite.git
$ git push -u origin master

This step is mandatory because DigitalOcean App Platform will fetch code of your Lightweight CMS site from a remote repo.

Run Your Site Locally First

Before deploying a site to a PaaS, you should always try your code locally. Here are steps to run your Lightweight CMS site locally:

$ ./tools/bin/publish
$ cd public
$ php -S localhost:3000

tools/bin/publish is our utility script to deploy a Lightweight CMS site to a PaaS. The script will copy router of Lightweight CMS and assets to public directory. It resembles tools/bin/serve but the former won’t call builtin server of PHP automatically.

Initial Deployment

On initial deployment, a PaaS will fetch your code from a remote repository, trying to build and deploy your website or web application. The article takes DigitalOcean App Platform as an example to demonstrate the process.

Choose your source:

Choose your source for DigitalOcean App Platform

If you are confident to your commits, check "Autodeploy code changes", which will build and deploy your commits automatically.

Configure your application:

Configure your application for DigitalOcean App Platform

Choose Web Services here for external sites. DigitalOcean App Platform provides other types of app for internal uses.

Set your Build Command like this:

tools/bin/publish

This is same command we tried locally.

Set your Run Command as it:

heroku-php-nginx -C tools/etc/nginx_do.conf public/

We write a Nginx configuration for this vendor. In addition, you need to specify application path.

Name your web service:

Name your web service for DigitalOcean App Platform

You should choose a region near your audience here, not yourself.

Choose your plan:

Choose your plan for DigitalOcean App Platform

Here we chose Basic because we just wanted to try out the platform.

It will take a while to build and deploy your Lightweight CMS site:

Deploy your app successfully on DigitalOcean App Platform

Subsequent Deployments

Once your Lightweight site is set, you don’t bother to maintain a web server, which is the reason some programmers choose a PaaS over a VPS. Update your site by committing your changes or triggering a deployment manually.

Set Custom Domain for Your Site

Even if you are satisfied with your PaaS now, you should always set a custom domain. For any reason, you may need to migrate your Lightweight site or other web projects to another host in the future. Here we simulate to set a custom domain on the platform:

Set custom domain for your site on DigitalOcean App Platform

In this case, set your DNS providers as following:

  • ns1.digitalocean.com
  • ns2.digitalocean.com
  • ns3.digitalocean.com

Note for PaaS Beginners

Using PaaS instead of VPS is not as easy as you think. You may encounter several failed deployments before first successful one. Read manuals of your PaaS vendor to figure out the tricky parts and possible workarounds.