I run Ghost on an Ubuntu server on DigitalOcean, which means I manually update ghost, ghost-cli
and other parts that make it work.
Often, it breaks... which is one reason I'm strongly considering moving to a hosted site. Just $29 a month for no headaches... whereas I'm spending $10 a month now for occasionally freaking out about my server being down.
Problem: Ghost-CLI crashes
Recently, after upgrading ghost-cli
, and then upgrading my ghost version, I found that I could not restart Ghost - it kept crashing.
It would also crash or hang on 'starting ghost' after typing ghost start
or ghost restart
:
☴ Starting Ghost...
I tried manually running ghost with the command /usr/bin/node /usr/bin ghost start
and that gave me an error:
static async _run(commandName, argv = {}, extensions) {
^^^^
SyntaxError: Unexpected identifier
In my case, it was that my version of NodeJS had become outdated and I had to upgrade it. But I checked a bunch of other things too.
Update NodeJS
This is the primary reason this occurs: old versions of NodeJS are not supported. Some still recent versions of Ubuntu ship with outdated versions, so if you've recently updated Ghost CLI and you can't start, then check your NodeJS version.
Here are general guidelines on the Ghost website.
Check your node version with this command:
nodejs --version
If it's 6.anything, it needs to get upgraded.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E
apt-get install -y nodejs
Set your server port correctly
Sometimes the port configuration can go awry. It happens occasionaly during upgrades.
Check your config.production.json
. Look for the port number
{
"url": "https://_MY_DOMAIN.com/",
"server": {
"port": 2368,
"host": "127.0.0.1"
},
.
.
.
}
Make sure it matches the port number you set in your nginx config file.
server {
listen 80;
listen [::]:80;
server_name _MY_DOMAIN_.com;
root /var/www/ghost/system/nginx-root;
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:2369;
}
.
.
.
}
Use this command to set your port:
ghost config set server.port 2369
Set the right path for node
After an upgrade of node, the file can move from /usr/bin/node
to /usr/local/bin/node
.
You can either create a symlink, or modify the environment variable (this is better)
Look in /etc/systemd/system
for your ghost_localhost.service
. There should be a link to a .service file
in your-site/system/files/ghost_localhost.service
.
Open the file with vim
, and look at the ExecStart entry.
It should look something like this
ExecStart=/usr/bin/node /usr/bin/ghost run
Does that node file exist? If it does, you're OK. If it has moved, update the path to node in the file.
If you modify it, tell systemd
with a reload: sudo systemctl daemon-reload
.
If there are other solutions you've found (or if something is unclear), drop me a line and I'll see if I can help.