Ghost won't start. Mismatched Node version (?) after mysql issue

To start, ghost doctor told me my version of node was out of date. I installed and used n to update to version 18.x per this page in docs.
After upgrading node, I got the following error:

1) GhostError

Message: Ghost was able to start, but errored during boot with: connect ECONNREFUSED ::1:3306
Help: Unknown database error

I followed the steps in this guide with no success.

I created a new Linode server following these guides. When I got to ghost install I had another issue with mysql during setup where it failed to create a new mysql user (see last line) and then would have the same error as above:

? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: larkinministries_prod
✔ Configuring Ghost
✔ Setting up instance
+ sudo chown -R ghost:ghost /var/www/larkinministries/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes
✖ Setting up "ghost" mysql user

I tried the recommendations from these posts

No success. Then I installed n on this new server and changed node version from 18.x to 16.x and after this, everything worked and the site is up on the new server. So it seems the issue was caused by the node version even though Ghost documentation says v18.x is supported and actually recommended. All I know is v18 did not work and v16 does.

So then I want to switch the original server to node v16 from v18 since that was the fix I found on the new test server. On the old server, using n to downgrade node from 18.x to 16.x results in the following ghost doctor output:

✔ Checking system Node.js version - found v16.20.2
✔ Checking logged in user
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
✔ Checking system compatibility
✔ Checking for a MySQL installation
+ sudo systemctl is-active ghost_www-sitename-com
Instance is currently running
ℹ Validating config [skipped]
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
✔ Checking binary dependencies
✔ Checking free space
✔ Checking systemd unit file
Warning: Ghost is running with node v18.17.1.
Your current node version is v16.20.2.
✔ Checking systemd node version - found v18.17.1

Note that system Node.js version - found v16.20.2 but Warning: Ghost is running with node v18.17.1. Your current node version is v16.20.2.

I tried using n to uninstall all other versions of node, tried updating ghost-cli, and updating ghost itself

How can I get Ghost to run under node version 16.20.2 (installed) and not 18.17.1 (which I uninstalled and which was not working)?

Trying ghost start just hangs indefinitely. Hitting ctrl-c to stop it results in the ghost process running but with a 502 error if you try to access the site. Ghost restart also just hangs indefinitely. (I left it for 15m and it was still trying)

Debug Information:
    OS: Ubuntu, v20.04.6 LTS
    Node Version: v16.20.2
    Ghost Version: 5.59.3
    Ghost-CLI Version: 1.24.2
    Environment: production
    Command: 'ghost start'

I’ve migrated data to the new server which is running, and am giving up on the old server.

When migrating, the ghost backup generated members csv was not complete. It had 15 of the 133 members. I had to connect to the mysql database and copy the members list straight out of the database.
For anyone’s reference in the future: if you have a Ghost instance that won’t start, you can still get data out of the mysql database by just connecting directly to it.

The node mismatch error has come up a couple of times recently, so let’s look at how it’s actually calculated.

There are a couple places where the message could be generated.

One reference to it is here:

That’s part of Ghost Doctor. In that case, it appears to be parsing the path to node out of the systemd service file, and then calls that copy of Node with --version to check the version.

You can check this version yourself using:

grep node /lib/systemd/system/*ghost*

On my Linux server, these all point to /usr/bin/node

At the same time, Ghost doctor calculates “your current version of node” by checking the version of node that ghost doctor is running as.

From looking the source of /usr/bin/ghost, I can see that it looks up the version of node to use by using:

/usr/bin/env node

If you want to find out what version of Node would be used that case, you can use which node to check.

So what we have learned about the mismatch can happen?

systemd doesn’t consult the environment to decide which version to run. It always a fixed path, like /usr/bin/node. But ghost doctor runs a version of node that is influenced by the environment, namely $PATH.

What about using nvm and n as Node version managers for Ghost?

nvm is sure to cause problems because it works by modifying your environment variables, so it will affect which Node is used by ghost doctor, but not by systemd. Not good.

n is better as a Node version manager, but where does it actually installed Node? According to the docs, it will the Node versions into /usr/local, meaning /usr/local/bin/node. This is better than nvm because at least it’s not using environment variables, but notice that this is not the same as /usr/bin/node, so a mismatch is still possible.

If you want to use a version of Node that’s not supplied by the OS, after you have installed n to install a version of Node into /usr/local/bin, you could uninstall the OS nodejs package, and then create a symlink from /usr/local/bin/node to /usr/bin/node that would sync the version installed by n with the location that systemd is looking for Node:

ln -s /usr/local/bin/node /usr/bin/node

Are there better solutions to avoid Node mismatch errors?

  1. If you already have Node 16 installed, don’t install Node 18-- Node 16 is supported and works fine!
  2. This situation could be considered a bug in Ghost doctor. If Ghost is hardcoding /usr/bin/node in the systemd files, when the ghost CLI is installed, it should do the same thing-- if it did that, getting a version mismatch would be impossible.
1 Like

The node path is not hardcoded in the cli, it uses the binary that’s executing the cli when you install ghost - so if the path to node in your environment changes after installing a ghost instance, you’ll get a mismatch.

The mismatch becomes in issue when node drops an LTS version, because if you don’t know how to update one of the node versions, there’s potential for unexpected crashes.

1 Like