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.


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.


Allow your Ghost website to be embedded 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


Fix Images Upload Error 500

sudo chown -R ghost:ghost ./content

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


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

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

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}}