OS : Ubuntu, v20.04.2 LTS Node Version: v12.22.1 Ghost Version: 4.2.2 Ghost-CLI Version: 1.17.2 Environment: production
I’m having some sort of issue updating ghost (again). It appears to be another permissions issue:
Stack: Error: EACCES: permission denied, mkdir '/var/www/mysite.com/blog/versions/4.4.0'
at Object.mkdirSync (fs.js:921:3)
at Object.module.exports.makeDirSync (/usr/lib/node_modules/ghost-cli/node_modules/fs-extra/lib/mkdirs/make-dir.js:101:15)
at Task.download [as task] (/usr/lib/node_modules/ghost-cli/lib/tasks/yarn-install.js:49:12)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Code: EACCES
Path: /var/www/mysite.com/blog/versions/4.4.0
Everything seems to work until trying to create the new version directory.
✔ Checking system Node.js version - found v12.22.1
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
✔ Checking free space
✔ Checking for available migrations
✔ Checking for latest Ghost version
… (new version notes removed for brevity)
✔ Fetched release notes
✖ Downloading and updating Ghost to v4.4.0
An error occurred.
Message: 'EACCES: permission denied, mkdir '/var/www/mysite.com/blog/versions/4.4.0''
.ghost-cli is still owned by my own user (not the ghost user) which is important or else there’ll be another error during upgrading. ghost doctor passes without issue, but ghost upgrade still doesn’t work.
Still not working… is there anyone who has successfully upgraded ghost recently who can tell me what permissions there are on their /versions folder and who owns it? That probably would tell me all I need to know…
Yes, it is a permissions issue. As far as I can tell it’s not related to any sort of login; it happens when I try to update ghost with ghost update (accidentally wrote ghost upgrade in my original post). So it’s also something I can’t do as root because the command requires a non-root user.
What makes you think NPM has anything to do with the error?
But where do you run ghost update from? From a system console? In that case your user may not have enough to modify the path of /var/www/mysite.com/blog/versions or he simply does not have permissions to perform actions with system npm modules in /usr/lib/node_modules/ because his system user does not have access to NPM or Node.js
I have a dedicated server so I login via SSH, perform the usual updates to my server and ghost cli, and I navigate to the ghost installation directory and run ghost update.
I uninstalled npm globally: sudo npm uninstall npm -g
Double-checked that node was installed with nvm: nvm ls (v14.17.0 )
Tried to update ghost, failed (same permissions issue)
Ran ghost doctor, said Ghost is running with different node version than the current
Ran ghost update 4.2.2 --force as recommended, but it failed because of permissions (normally I lacked permissions to create a directory, in this case I lacked permissions to remove the old one)
Decided to purge nodejs. I stopped ghost and ran: sudo apt-get purge --auto-remove nodejs
It complained the node_modules folder was not empty (it contained ghost cli files). I forced deleted anyways.
Rebooted the server, made sure to use LTS version: nvm use --lts
Made sure the latest npm was installed: nvm install-latest-npm
Reinstalled ghost cli: npm i -g ghost-cli@latest
It complained about “5 high severity vulnerabilities”:
To address all issues (including breaking changes), run: npm audit fix --force
Run npm audit for details.
$ npm audit
npm ERR! code ENOLOCK
npm ERR! audit This command requires an existing lockfile.
npm ERR! audit Try creating one first with: npm i --package-lock-only
npm ERR! audit Original error: loadVirtual requires existing shrinkwrap file
Ignored the vulnerabilities. Navigated to my ghost directory and tried to update again: ghost update:
Downloading and updating Ghost to v4.7.0
An error occurred.
Message: ‘EACCES: permission denied, mkdir ‘/var/www/mysite.com/blog/versions/4.7.0’’
Ran ghost doctor again, it complained:
a) One or more errors occurred.
Checking binary dependencies
Message: The installed node version has changed since Ghost was installed.
Help: Run ghost update 4.2.2 --force to re-install binary dependencies.
b) SystemError
Message: Unable to determine node version in use by systemd
Help: Ensure ‘ExecStart’ exists in /lib/systemd/system/ghost_mywebsite-com.service and uses a valid Node version
ghost update 4.2.2 --force does not work, similar permissions error.
I edited /lib/systemd/system/ghost_mywebsite-com.service and replaced /usr/bin/node with just node. Reloaded systemd with sudo systemctl daemon-reload. Didn’t work. Tried directly referencing the path returned from which node but that also didn’t work.
Turns out all that mattered was that the versions folder and config.production.json needed to be owned by me. In fact, it seems that only content needs to be owned by ghost.
However, since I switched to nvm, the systemd file needed to be updated:
which node && which ghost
Note the two paths shown. Then edit the systemd file for ghost (you can find out what the exact name of it is for your instance by navigating to your ghost root directory and typing ghost status).
Edit the ExecStart= line by replacing usr/bin/node and /usr/bin/ghost with the above paths.
Then reload systemd, restart the ghost service, and make sure it’s running.