Skip to content

Commit e8d963c

Browse files
Julie POUNYdavlgd
authored andcommitted
Guide deploy ghost
1 parent 707d5fa commit e8d963c

File tree

1 file changed

+279
-0
lines changed

1 file changed

+279
-0
lines changed
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
---
2+
type: docs
3+
title: Ghost Blog
4+
shortdesc: This article shows you how to deploy a Ghost blog on Clever Cloud.
5+
tags:
6+
- deploy
7+
keywords:
8+
- node.js
9+
- ghost
10+
aliases:
11+
- /developers/doc/node/tutorial-ghost
12+
- /doc/deploy/application/node/tutorials/tutorial-ghost
13+
- /doc/node/tutorial-ghost
14+
---
15+
16+
## Overview
17+
18+
[Ghost](https://ghost.org) is a modern, open-source publishing platform ideal for bloggers and content creators. This guide will walk you through the process of deploying a Ghost blog on Clever Cloud using Node.js.
19+
20+
### Prerequisites
21+
22+
- **Node.js 20**
23+
- **MySQL**
24+
- **Cellar S3**
25+
- **Ghost-CLI**
26+
- **Clever Tools CLI** ([documentation](https://www.clever-cloud.com/developers/doc/cli/))
27+
- **Git**
28+
29+
## Installation and Configuration
30+
31+
### Initialize Your Project
32+
33+
Create a project folder and install Ghost locally:
34+
35+
```sh
36+
# Create the project file
37+
mkdir myblog && cd myblog
38+
# Install Ghost-CLI
39+
npm install -g ghost-cli@latest
40+
nvm use 20 #to use node 20
41+
# Install Ghost
42+
ghost install local
43+
ghost stop
44+
```
45+
46+
Remove the default theme and add custom theme submodules:
47+
48+
```sh
49+
rm -r content/themes/casper
50+
cp -r current/content/themes/casper/ content/themes/
51+
git init
52+
cd content/themes/
53+
git submodule add https://github.com/curiositry/mnml-ghost-theme
54+
git submodule add https://github.com/zutrinken/attila/
55+
wget https://github.com/TryGhost/Source/archive/refs/tags/<last-version>.zip -O source.zip #check and use the lastest version https://github.com/TryGhost/Source/releases
56+
rm -R source
57+
unzip source.zip -d temp
58+
mkdir source
59+
mv temp/*/* source/
60+
rm -R temp source.zip
61+
```
62+
63+
Add the S3 module:
64+
65+
```sh
66+
npm install ghost-storage-adapter-s3
67+
mkdir -p ./content/adapters/storage
68+
cp -r ./node_modules/ghost-storage-adapter-s3 ./content/adapters/storage/s3
69+
```
70+
71+
### Create and Configure Node Application and MySQL
72+
73+
Use the [Clever Tools CLI](https://www.clever-cloud.com/developers/doc/cli/install):
74+
75+
Create the Node.js app and a MySQL add-on on Clever Cloud:
76+
77+
```sh
78+
# Create the Node.js app
79+
clever create --type node myblog
80+
81+
# Create MySQL add-on
82+
clever addon create mysql-addon --plan s_sml myblogsql
83+
clever service link-addon myblogsql
84+
```
85+
86+
The Ghost configuration file can't use direct environment variables. Set the following environment variables to connect your app to the database:
87+
88+
```sh
89+
clever env set database__connection__host <ADDON_HOST>
90+
clever env set database__connection__user <ADDON_USER>
91+
clever env set database__connection__password <ADDON_PASSWORD>
92+
clever env set database__connection__database <ADDON_DATABASE>
93+
clever env set database__connection__port <ADDON_PORT>
94+
clever env set url https://<domain_URL_blog>
95+
```
96+
97+
### Install and Configure Cellar S3
98+
99+
Create the Cellar S3 add-on on Clever Cloud:
100+
101+
```sh
102+
# Create and link Cellar add-on
103+
clever addon create cellar-addon --plan s_sml <cellar-app>
104+
clever service link-addon <cellar-app>
105+
```
106+
107+
In your Cellar S3 add-on console, create a bucket for your blog.
108+
109+
Add the environment variables to configure Ghost with Cellar:
110+
111+
```sh
112+
clever env set storage__s3__accessKeyId <CELLAR_ACCESS_KEY>
113+
clever env set storage__s3__secretAccessKey <CELLAR_SECRET_KEY>
114+
clever ens set storage__s3__assetHost <CELLAR_ADDON_HOST>
115+
clever env set storage__s3__bucket <your-bucket>
116+
clever env set storage__s3__region fr
117+
```
118+
119+
Make sure to configure public read access in your Cellar bucket:
120+
121+
```json
122+
{
123+
"Version": "2012-10-17",
124+
"Statement": [
125+
{
126+
"Sid": "VisualEditor0",
127+
"Effect": "Allow",
128+
"Action": "s3:ListBucket",
129+
"Resource": "arn:aws:s3:::<bucket>"
130+
},
131+
{
132+
"Sid": "VisualEditor1",
133+
"Effect": "Allow",
134+
"Action": [
135+
"s3:PutObject",
136+
"s3:GetObject",
137+
"s3:PutObjectVersionAcl",
138+
"s3:DeleteObject",
139+
"s3:PutObjectAcl"
140+
],
141+
"Resource": "arn:aws:s3:::<bucket>/*"
142+
},
143+
{
144+
"Sid": "PublicReadAccess",
145+
"Effect": "Allow",
146+
"Action": "s3:GetObject",
147+
"Resource": "arn:aws:s3:::<bucket>/*",
148+
"Principal": "*"
149+
}
150+
]
151+
}
152+
```
153+
154+
### Create a Pre-Run Hook
155+
156+
In the root folder of your project, create the file `.clevercloud-pre-run-hook.sh`:
157+
158+
```sh
159+
#!/bin/sh
160+
npm install -g ghost-cli
161+
mkdir ghost
162+
cd ghost
163+
ghost install local
164+
ghost stop
165+
cp ../config.production.json .
166+
npm install ghost-storage-adapter-s3
167+
mkdir -p ./content/adapters/storage
168+
cp -r ../content/adapters/storage/s3 content/adapters/storage/s3
169+
rm -R content/themes/source
170+
cp -r ../content/themes/source content/themes/
171+
```
172+
173+
Grant execution permissions to the script:
174+
175+
```sh
176+
sudo chmod +x clevercloud.sh
177+
```
178+
179+
### Configure Ghost
180+
181+
Create the file `config.production.json` in the root folder of your project:
182+
183+
```json
184+
{
185+
"url": "https://<your-url-app>/",
186+
"server": {
187+
"port": 8080,
188+
"host": "0.0.0.0"
189+
},
190+
"database": {
191+
"client": "mysql"
192+
},
193+
"storage": {
194+
"active": "s3"
195+
},
196+
"mail": {
197+
"transport": "SMTP"
198+
},
199+
"process": "local",
200+
"logging": {
201+
"level": "debug",
202+
"transports": ["stdout"]
203+
},
204+
"paths": {
205+
"contentPath": "../../../content/"
206+
}
207+
}
208+
```
209+
210+
### Create `package.json` and `.gitignore`
211+
212+
Create the file `package.json`:
213+
214+
```json
215+
{
216+
"name": "ghost",
217+
"version": "0.1.0",
218+
"description": "",
219+
"scripts": {
220+
"start": "ghost run --dir ghost"
221+
},
222+
"devDependencies": {},
223+
"dependencies": {}
224+
}
225+
```
226+
227+
Create the file `.gitignore`:
228+
229+
```
230+
.ghost-cli
231+
config.development.json
232+
current
233+
versions
234+
node_modules
235+
```
236+
237+
### Set Other Environment Variables for Your Application
238+
239+
Before deploying your application on Clever Cloud, make sure to set the following environment variables:
240+
241+
```sh
242+
clever env set CC_NODE_BUILD_TOOL yarn2
243+
clever env set CC_NODE_VERSION 20
244+
clever env set CC_PRE_RUN_HOOK "./.clevercloud-pre-run-build.sh"
245+
clever env set NODE_ENV production
246+
```
247+
248+
#### Optional: Configure Email Service
249+
250+
Ghost allows you to configure an SMTP service for sending emails (such as invitations, password resets, etc.). You can set it up using the following environment variables:
251+
252+
```sh
253+
clever env set mail__from "your-email@example.com"
254+
clever env set mail__options__service "your-mail-service" # e.g. Mailgun, Gmail, etc.
255+
clever env set mail__options__host "smtp.yourmail.com"
256+
clever env set mail__options__port "587"
257+
clever env set mail__options__secureConnection "false"
258+
clever env set mail__options__auth__user "your-smtp-username"
259+
clever env set mail__options__auth__pass "your-smtp-password"
260+
```
261+
262+
> 💡 **Note**: These environment variables allow Ghost to connect to your email service automatically.
263+
> For more details and supported options, see the [official Ghost SMTP configuration docs](https://ghost.org/docs/config/#mail).
264+
265+
## Deploy on Clever Cloud
266+
267+
Initialize git, add files, and push:
268+
269+
```sh
270+
git add clevercloud.sh package.json config.production.json content
271+
git commit -m "Initial commit"
272+
git remote add clever <CLEVER_GIT_URL>
273+
git push clever <branch>:master
274+
```
275+
276+
## More Information
277+
278+
For a small blog, you can use the XS or S Node.js plan.
279+

0 commit comments

Comments
 (0)