Ghost blog on App Engine
Tags: appengine, ghost
Published: 2019-04-29 11:10:23

---
title: Ghost blog on App Engine
published: true
tags: App Engine, Ghost
canonical_url: https://vanlatum.dev/ghost-appengine/
---

 ![Ghost blog on App Engine](https://storage.googleapis.com/vanlatum-dev-images/2019/04/Blog1-1.jpg)

In this blog we will explore how to host a Ghost blog on Google App Engine.

App Engine is a very scalable and reliable system but it comes with a couple of things you need to consider. For example you can't store files or images in App Engine because your blog runs in containers. But we can serve those files from Google Cloud Storage with a custom storage adapter.

Because the current cloud platform storage adapter does not seem to work with the most recent version of ghost I wrote up a storage adapter that works with Google Cloud Platform: [https://github.com/thomas-vl/ghost-gcs](https://github.com/thomas-vl/ghost-gcs)

You also can't use the sqlite3 database so you need a public accessible mysql database. If you have a webhosting with direct admin you can add '%' to the list of Access Hosts to make it public available.

Let's jump in and build our ghost blog!

<!--kg-card-begin: markdown-->

Pre requisites:

1. Start by [creating a project](https://console.cloud.google.com/projectcreate) on Google Cloud Platform.
2. Create a [storage bucket](https://console.cloud.google.com/storage/create-bucket) to store your images.
3. Create a [service account](https://console.cloud.google.com/iam-admin/serviceaccounts/create)  
a. Give your service account a name and click create.  
b. Add the Storage Admin role to your service account.  
c. Generate a json key by clicking Create Key and Create
4. Download and install [gcloud](https://cloud.google.com/sdk/) on your machine
5. Make sure you have a mysql on your own hosting or [cloud SQL](https://console.cloud.google.com/sql/create-instance-mysql) database on GCP

<!--kg-card-end: markdown-->
<!--kg-card-begin: markdown-->

Building your app:

1. Create an empty directory on your machine
2. Create 'app.yaml' with the following content

```
runtime: custom
env: flex
```

1. Create 'Dockerfile' with the following content

```
FROM ghost

COPY config.production.json /var/lib/ghost/config.production.json

#install the google cloud storage adapter
WORKDIR /var/lib/ghost
COPY credentials.json /var/lib/ghost/credentials.json
RUN npm install ghost-gcs --no-save 
WORKDIR /var/lib/ghost/content/adapters/storage/ghost-gcs/
ADD https://raw.githubusercontent.com/thomas-vl/ghost-gcs/master/export.js index.js

WORKDIR /var/lib/ghost
```

1. Create 'config.production.json' with the following content

```
{
    "url": "{appengine url}",
    "server": {
      "port": 8080,
      "host": "0.0.0.0"
    },
    "database": {
      "client": "mysql",
      "connection": {
        "host": "{db ip}",
        "port": "{db port}",
        "user": "{db user}",
        "password": "{db password}",
        "database": "{db name}"
      }
    },
    "mail": {
      "transport": "Direct"
    },
    "logging": {
      "transports": [
        "file",
        "stdout"
      ]
    },
    "process": "systemd",
    "paths": {
      "contentPath": "/var/lib/ghost/content"
    },
    "storage": {
        "active": "ghost-gcs",
        "ghost-gcs": {
            "key": "credentials.json",
            "bucket": "{bucket name}"
        }
    }
}
```

1. Change the following parameters:
    a. {appengine url} - usually [https://your-project-id.appspot.com](https://your-project-id.appspot.com)
    b. {db ip} - your mysql database ip address
    c. {db port} - usually 3306
    d. {db user} - your mysql user
    e. {db password} - your mysql password
    f. {db name} - your msql database name
    g. {bucket name} - the full name of the bucket created in the prerequisites

2. Make sure you move the downloaded service account credentials file to your current directory and rename it to credentials.json
3. In Terminal or PowerShell go to the created directory and run the following command  
`gcloud app deploy`

<!--kg-card-end: markdown-->

Enjoy blogging on your self hosted ghost blog!