Skip to content

Ghost Tips & Tricks

Tips, scripts, and tricks on different things related to Ghost.

When working on the server, always make sure to have a backup.


Access DigitalOcean Droplet

This assumes you already configured the connection between your computer and DigitalOcean. Change your droplet IP.

ssh root@207.154.195.220

Multiple Ghost Installations • DigitalOcean

I assume:

  • You are logged in to your droplet using SSH from the command line
  • Your domain name is ready and connected to the droplet IP
  • You know what you are doing :)

➊ You need the current MySQL host, username, and password.

cd /var/www/ghost/

cat config.production.json

Take notes of them. You will use them later in steps 3 and 5.

➋ Create a website directory, for example, ubud.

cd /var/www/
sudo mkdir ubud
sudo chown ghost-mgr:ghost-mgr ubud/

➌ Login to MySQL and create a new database

sudo mysql -u root -p

CREATE DATABASE ubud;
GRANT ALL PRIVILEGES ON ubud.* to 'ghost'@'localhost' IDENTIFIED BY '7d150600c49e7c5860be7ce03d4f8df67259176738d926ec';
FLUSH PRIVILEGES;
exit
  • ghost → database user
  • localhost → database host
  • 7d150600c49e7c5860be7ce03d4f8df67259176738d926ec → database password

➍ Switch to the ghost-mgr user

sudo -i -u ghost-mgr

➎ Install Ghost and follow the installation steps

cd /var/www/ubud/
ghost install

Update Multiple Installation on the Same Droplet • DigitalOcean

for d in /var/www/*/ ; do (cd "$d/" && ghost update); done

Modified version of Daniel script.


Renew Let’s Encrypt SSL Certificate • DigitalOcean

/root/.acme.sh/acme.sh --force --renew --home /etc/letsencrypt --domain nubia.aspirethemes.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail ahmad@aspirethemes.com

Replace example.com with your domain and mail@example.com with your email.


Download & Upload Images • DigitalOcean

When you want to download the website images from one server and upload them to another server. Change the IP and paths.

Download

scp root@207.154.195.220:/var/www/ghost/content/images.zip /Users/ahmadajmi/Desktop

Upload

scp /Users/ahmadajmi/Desktop/images.zip root@159.65.227.236:/var/www/ghost/content/

Zip and Unzip Images

zip -r images.zip images

unzip -o images.zip

Fix Images Upload Error 500 • DigitalOcean

sudo chown -R ghost:ghost ./content

Make your Ghost website embeddable in an <iframe>

cd /etc/nginx/sites-available/

vim ubud.ubudthemes.com-ssl.conf

---


➋ Add:

add_header X-Frame-Options "ALLOW-FROM *";

---

➌ Ex:

location / {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $http_host;
  proxy_pass http://127.0.0.1:2370;

  add_header X-Frame-Options "ALLOW-FROM *";
}

---sudo nginx -s reload

X-Frame-Options


Quickly Edit a Post • Source

Append /edit to your post URL, and you will be redirected to the post editor.

http://example.com/welcome → http://example.com/welcome/edit

Of course, you need to be logged in.

Chrome Extention — Ghost Edit Button


Output How Many Posts in Total and How Many Paid • Source

{{#get "posts" limit="1" as |posts pagination|}}
  {{pagination.total}} total posts
{{/get}}

{{#get "posts" limit="1" filter="visibility:public" as |posts pagination|}}
  {{pagination.total}} public posts
{{/get}}

{{#get "posts" limit="1" filter="visibility:-paid" as |posts pagination|}}
  {{pagination.total}} free posts
{{/get}}

{{#get "posts" limit="1" filter="visibility:members" as |posts pagination|}}
  {{pagination.total}} members posts
{{/get}}

{{#get "posts" limit="1" filter="visibility:paid" as |posts pagination|}}
  {{pagination.total}} paid-members-only posts
{{/get}}

Handlebars Comments

You can add comments to Ghost theme Handlebars files (.hbs) by wrapping the content you want to hide within {{!-- --}}.

For example,

{{!--
<h1>Heading</h1>
--}}

or in one line as:

{{!-- <h1>Heading</h1> --}}

Commenting code is helpful if you want to edit the theme and don’t want to remove the lines but keep them fur future reference.