Issue upgrading 4.2.2 → 4.6: EACCES: permission denied, mkdir '/var/www/

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/'
    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 [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)
Path: /var/www/

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/''

I tried setting various permissions per the official guide:.

sudo find /var/www/* -type d -exec chmod 775 {} \;
sudo find /var/www/* -type f -exec chmod 664 {} \;
sudo chown -R ghost:ghost /var/www/*

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

Any advice would be helpful. Thanks :slight_smile:

Still having this issue, though now instead of attempting to upgrade to 4.5 it’s attempting to upgrade to 4.4 again.

Is bumping part of official policy when support is still needed?

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… :pray:

Now ghost-cli version 1.17.3 and attempting to upgrade to 4.6.4, same mkdir permissions issue.

Same issue trying to upgrade to 4.7.0.

This happens due to a permission issue.

Could it be that you have installed Node.js and NPM at the system level and are trying to log in as a normal user?

If this is the problem, you can fix it using one of these options:

  • Perform the action as root (NOT RECOMMENDED)
  • Manually change the default npm directory
  • Reinstall npm using a node version manager

If this is not your problem, check the permissions of the Ghost blog folders

Thanks for your reply @ByteDigital

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

But where do you run ghost update from?

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 followed these instructions to install nvm and then installed the LTS version: nvm install --lts

  • I uninstalled npm globally: sudo npm uninstall npm -g

  • Double-checked that node was installed with nvm: nvm ls (v14.17.0 :heavy_check_mark:)

  • 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:

:heavy_multiplication_x: Downloading and updating Ghost to v4.7.0
An error occurred.
Message: ‘EACCES: permission denied, mkdir ‘/var/www/’’

Debug Information

OS: Ubuntu, v20.04.2 LTS
Node Version: v14.17.0
Ghost Version: 4.2.2
Ghost-CLI Version: 1.17.3
Environment: production
Command: ‘ghost update’

  1. Checked this official guide (Using nvm with local and production installs) to make sure nvm was installed correctly (it is).

  2. 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

  3. ghost update 4.2.2 --force does not work, similar permissions error.

  4. 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.

sudo chown -R $USER:$USER /var/www/
sudo chown -R ghost:ghost /var/www/

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).

sudo nano /lib/systemd/system/ghost_mysite-com.service

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.

sudo systemctl daemon-reload
sudo systemctl restart ghost_mysite-com
sudo systemctl status ghost_mysite-com

If there’s an issue, you can see why it failed with the following command:

sudo journalctl -u ghost_mysite-com -n 50

Hope that helps anyone else with similar issues.

1 Like