Install Ghost on Plesk Onyx (17.x) vServer with docker

Install Ghost on Plesk Onyx (17.x) vServer with docker

UPDATE 2019: I wrote a newer guide on how to install Ghost on a Plesk Onyx (17.8.x) vServer here: 2019 Update: Install Ghost (2.27.0) on Plesk Onyx (17.8.x) vServer with docker

It took a while and it is not perfect. But for some time now, this blog is running an up-to-date Ghost version on my plesk vServer, with one hassle*
*more at the bottom - please read the last chapter before following all instructions!

At the time I wrote this post, my vServer Plesk Installation had no docker support and still has none. I ordered a new vServer from my hoster, which supports docker. Ask your hosting provider with which configuration docker is available in plesk. I needed a virtual machined vServer and not a containerized. I ordered the smallest machine (~ 8,99€s/month).

step 0 - backup your actual ghost blog

Backup your data and media! Use Ghosts backup function for your data and save your media files from your server. If I remember correctly, I uploaded all media after the following process by hand (aka scp).

step 1 - install docker in plesk

plesk-ghost-docker-setup-step-1

In Plesk Admin Panel open Tools & Settings:

plesk-ghost-docker-setup-step-0

and click on Plesk ⇢ Updates and Upgrades and you'll find yourself here:

plesk-ghost-docker-setup-step-0.5

click in the middle and check if docker is installed or install docker (first image of this chapter).

step 2 - download docker image

Back at Plesk Admin Panel, there will be a new navigation entry Docker.

plesk-ghost-docker-setup-step-2

On a fresh setup, you will not find any boxes. Just type ghost into the Docker Image Catalog input:

plesk-ghost-docker-setup-step-3

The (local) may not be shown in your listing, it indicates docker images you already downloaded. For today (july the 26th 2018) choose 1.24.7-alpine. -alpine images are smaller than not -alpine images, and they do the job!

Click on that image and plesk will start the download.

step 3 - configure docker container

plesk-ghost-docker-setup-step-4-1

Make sure that your docker container will start on reboot, has a manual port mapping and a volume mapping to a non www-reachable place.

step 4 - add docker proxy rule

Go to your domain settings and click on docker proxy rules:

plesk-ghost-docker-setup-step-5

In the next screen click on add rule and select your downloaded ghost docker image:

plesk-ghost-docker-setup-step-6

and click OK.

With this configuration your ghost installation will respond to your domain.

Heads up your let's encrypt subscription might not get updated with this docker proxy rule. If you get an email about failed renewed certificates, log in to plesk, disable the docker proxy rule, renew the let's encrypt certificate and activate docker proxy rule again.

step 5 - create admin account, import data

Because this installation is a fresh setup, you will need to setup your ghost account again.

Everything else needs to be setup too (Name, Theme, etc.).

After that navigate to Labs and upload your backup.json file:

plesk-ghost-docker-setup-step-7

And last, upload your media data back to you server. You will find the mapped docker volume in step 3.

Looks like your dockerized ghost is up and running...
... but have a look at your html source!

*the hassle ?

UPDATE 2019: please have a look at [this](2019 Update: Install Ghost (2.27.0) on Plesk Onyx (17.8.x) vServer with docker) guide, it is hassle free.

plesk-ghost-docker-setup-step-8-1

All meta data is displayed with http instead of correct https...

Before today - all meta data pointed to localhost:2368 which was a seo-desaster. For this post, I searched the internet and tried many many things to fix this. The situation with http instead of https is better, but not perfect... I'll post an update if I get this fixed.

the docs

Here or here the ghost people tell you how to configure your url correctly. But in Plesk Panel and docker you will never reach that point, where you can set this!

I tried to set the environment variables with the plesk docker panel, but both URL and GHOST_URL did not work.

bad practice solution

I ended up, editing the running docker container configuration, which is a) bad and b) very techy.

bad ?

Why bad? The docker container will be rebuild on updates, or when you hit recreate and maybe on other circumstances. You need to check every now and than, if your altered configuration needs to be altered again.

techy?

Why techy? You need root access to your webserver and know your way around with vi!

Access your server via ssh and make yourself a root sudo -s. Type docker container ls --all and you get your docker container ids. With the running ghost-docker-container-id bash yourself into the docker container with this command docker exec -it <container-id> bash.

plesk-ghost-docker-setup-step-9

Docker images only provide programs and functions they really need. I was happy, that vi is one of them - if you have no experience with vi you might not be happy ;-)

In the container you type vi config.production.json. To enter edit mode hit i and edit the url to your url (with http instead of https). Hit ESC and type :wq to write and quit vi.

Back to Plesk Panel, click on Restart on your docker container and your website will work.

why not https in config?

My first try, was with https://... in the config and my webserver redirected any request to infinity...

I think here is the solution, I need to tweak my nginx configuration:

location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # 2 lines below are to avoid Ghost https redirect bug
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
}

But if I put this into the Additional nginx directives and set up the https:// url the redirects to infinity still happen.

For now, it is the best I've come along with.

tbc...

Follow Ups @Drake told me via twitter that he wrote a plesk, docker, ghost tutorial as well:

Article image from Guillaume Bolduc via unsplash and ghost.