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
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!
Pre requisites:
- Start by creating a project on Google Cloud Platform.
- Create a storage bucket to store your images.
- Create a service account 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
- Download and install gcloud on your machine
- Make sure you have a mysql on your own hosting or cloud SQL database on GCP
Building your app:
- Create an empty directory on your machine
- Create 'app.yaml' with the following content
runtime: custom
env: flex
- 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
- 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}"
}
}
}
Change the following parameters:
a. {appengine url} - usually 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 prerequisitesMake sure you move the downloaded service account credentials file to your current directory and rename it to credentials.json
In Terminal or PowerShell go to the created directory and run the following command
gcloud app deploy
Enjoy blogging on your self hosted ghost blog!
Top comments (2)
Thank you I was able to spin up a Ghost instance on App Engine using the following configuration
cloud.google.com/sql/docs/mysql/co...
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
I am getting this error