EACCES: permission denied node_modules "moment-timezone" ghost versions 4.2.1

Hello guys,
I know this is kinda the common problem everybody encounter. However, I have searched through the whole forum for error on EACCES but unfortunately I cannot find any working solution, neither understand what is wrong with my installation.

I tried to instantiate a new Ghost v4.2.1 under /var/www/myghost/ using ghost install as written on the official guide.

The creation went well. I got the following folder tree :

-rw-r--r-- 1 adghost adghost  571 avril 14 20:30 config.production.json
drwxr-xr-x 8 ghost   ghost   4096 avril 14 20:12 content
lrwxrwxrwx 1 adghost adghost   36 avril 14 20:25 current -> /var/www/myghost/versions/4.2.1
drwxr-xr-x 3 adghost adghost 4096 avril 14 20:12 versions

However when I tried to launch ghost run, I got the following EACCES error :

The `ghost run` command is used by the configured Ghost process manager and for debugging. If you're not running this to debug something, you should run `ghost start` instead.                                                                                                   + sudo node current/index.js                                                                                                             internal/fs/utils.js:269                                                                                                                     throw err;
    ^

Error: EACCES: permission denied, open '/var/www/myghost/versions/4.2.1/node_modules/moment-timezone/index.js'
    at Object.openSync (fs.js:462:3)
    at Object.readFileSync (fs.js:364:35)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1025:18)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/var/www/myghost/versions/4.2.1/core/server/overrides.js:8:16)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) {
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/var/www/myghost/versions/4.2.1/node_modules/moment-timezone/index.js'
}

I know that this is related to some ownership or R/W permissions on some files for nodejs. But when I tried to display the permission for the related file, everything seems ok (see below)

adghost@raspberrypi:/var/www/myghost $ ll /var/www/myghost/versions/4.2.1/node_modules/moment-timezone/index.js
-rwxr-x--- 1 adghost adghost 116 févr. 13 00:01 /var/www/myghost/versions/4.2.1/node_modules/moment-timezone/index.js

At this point, we can see that /var/www/myghost/versions/4.2.1/node_modules/moment-timezone/index.js belongs to adghost and this is the user used to run ghost run (and also ghost start). However, the error seems to tell otherwise (as if adghost doesn’t have the right permissions).

Could somebody please help me with this ? I am stucked and have no other alternative :frowning_face:

  • How was Ghost installed and configured? → production mode using ghost install
  • What Node version, database, OS & browser are you using? → node : v12.22.0 + database : mariadb (Ver 15.1 Distrib 10.3.27-MariaDB) + OS : raspbian
  • What errors or information do you see in the console? → see above

Thanks in advance for your help.
Regards,
Rahenda

The error tells you the problem!

You should not be using ghost run directly.

@Hannah I forgot to mention in the initial post that I already tried ghost start. The command gave me the same error below

-- Logs begin at Thu 2021-04-15 14:36:09 CEST, end at Fri 2021-04-16 09:13:42 CEST. --
avril 16 09:01:23 raspberrypi node[4601]: Error: EACCES: permission denied, open '/var/www/mywebsite/versions/4.2.1/node_modules/moment-timezone/index.js'
avril 16 09:01:23 raspberrypi node[4601]:     at Object.openSync (fs.js:462:3)
avril 16 09:01:23 raspberrypi node[4601]:     at Object.readFileSync (fs.js:364:35)
avril 16 09:01:23 raspberrypi node[4601]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1025:18)
avril 16 09:01:23 raspberrypi node[4601]:     at Module.load (internal/modules/cjs/loader.js:863:32)
avril 16 09:01:23 raspberrypi node[4601]:     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
avril 16 09:01:23 raspberrypi node[4601]:     at Module.require (internal/modules/cjs/loader.js:887:19)
avril 16 09:01:23 raspberrypi node[4601]:     at require (internal/modules/cjs/helpers.js:74:18)
avril 16 09:01:23 raspberrypi node[4601]:     at Object.<anonymous> (/var/www/mywebsite/versions/4.2.1/core/server/overrides.js:8:16)
avril 16 09:01:23 raspberrypi node[4601]:     at Module._compile (internal/modules/cjs/loader.js:999:30)
avril 16 09:01:23 raspberrypi node[4601]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) {
avril 16 09:01:23 raspberrypi node[4601]:   errno: -13,
avril 16 09:01:23 raspberrypi node[4601]:   syscall: 'open',
avril 16 09:01:23 raspberrypi node[4601]:   code: 'EACCES',
avril 16 09:01:23 raspberrypi node[4601]:   path: '/var/www/mywebsite/versions/4.2.1/node_modules/moment-timezone/index.js'
avril 16 09:01:23 raspberrypi node[4601]: }
avril 16 09:01:23 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Succeeded.
avril 16 09:01:23 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Service RestartSec=100ms expired, scheduling restart.
avril 16 09:01:23 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Scheduled restart job, restart counter is at 84.
avril 16 09:01:23 raspberrypi systemd[1]: Stopped Ghost systemd service for blog: mywebsite-fr.
avril 16 09:01:23 raspberrypi systemd[1]: Started Ghost systemd service for blog: mywebsite-fr.
avril 16 09:01:26 raspberrypi node[4637]: - Inspecting operating system
avril 16 09:01:27 raspberrypi node[4637]: internal/fs/utils.js:269
avril 16 09:01:27 raspberrypi node[4637]:     throw err;
avril 16 09:01:27 raspberrypi node[4637]:     ^
avril 16 09:01:27 raspberrypi node[4637]: Error: EACCES: permission denied, open '/var/www/mywebsite/versions/4.2.1/node_modules/moment-timezone/index.js'
avril 16 09:01:27 raspberrypi node[4637]:     at Object.openSync (fs.js:462:3)
avril 16 09:01:27 raspberrypi node[4637]:     at Object.readFileSync (fs.js:364:35)
avril 16 09:01:27 raspberrypi node[4637]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1025:18)
avril 16 09:01:27 raspberrypi node[4637]:     at Module.load (internal/modules/cjs/loader.js:863:32)
avril 16 09:01:27 raspberrypi node[4637]:     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
avril 16 09:01:27 raspberrypi node[4637]:     at Module.require (internal/modules/cjs/loader.js:887:19)
avril 16 09:01:27 raspberrypi node[4637]:     at require (internal/modules/cjs/helpers.js:74:18)
avril 16 09:01:27 raspberrypi node[4637]:     at Object.<anonymous> (/var/www/mywebsite/versions/4.2.1/core/server/overrides.js:8:16)
avril 16 09:01:27 raspberrypi node[4637]:     at Module._compile (internal/modules/cjs/loader.js:999:30)
avril 16 09:01:27 raspberrypi node[4637]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) {
avril 16 09:01:27 raspberrypi node[4637]:   errno: -13,
avril 16 09:01:27 raspberrypi node[4637]:   syscall: 'open',
avril 16 09:01:27 raspberrypi node[4637]:   code: 'EACCES',
avril 16 09:01:27 raspberrypi node[4637]:   path: '/var/www/mywebsite/versions/4.2.1/node_modules/moment-timezone/index.js'
avril 16 09:01:27 raspberrypi node[4637]: }
avril 16 09:01:27 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Succeeded.
avril 16 09:01:27 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Service RestartSec=100ms expired, scheduling restart.
avril 16 09:01:27 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Scheduled restart job, restart counter is at 85.
avril 16 09:01:27 raspberrypi systemd[1]: Stopped Ghost systemd service for blog: mywebsite-fr.
avril 16 09:01:27 raspberrypi systemd[1]: Started Ghost systemd service for blog: mywebsite-fr.
avril 16 09:01:28 raspberrypi systemd[1]: Stopping Ghost systemd service for blog: mywebsite-fr...
avril 16 09:01:28 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Main process exited, code=killed, status=15/TERM
avril 16 09:01:28 raspberrypi systemd[1]: ghost_mywebsite-fr.service: Succeeded.
avril 16 09:01:28 raspberrypi systemd[1]: Stopped Ghost systemd service for blog: mywebsite-fr.

Then I tried to launch ghost doctor and it told me everything is ok :

adghost@raspberrypi:/var/www/mywebsite $ ghost doctor
✔ Checking system Node.js version
✔ 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
System checks failed with message: 'Linux version is not Ubuntu 16, 18, or 20'
Some features of Ghost-CLI may not work without additional configuration.
For local installs we recommend using `ghost install local` instead.
? Continue anyway? Yes
System stack check skipped
ℹ Checking system compatibility [skipped]
✔ Checking for a MySQL installation
+ sudo systemctl is-active ghost_mywebsite-fr
? Sudo Password [hidden]
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
✔ Checking binary dependencies
✔ Checking free space

So the reason I launched ghost run is for debugging but I couldn’t get more info from it

Fyi : A couple of months ago I also installed another Ghost instance v3.41.5 on the same machine and using the same user, everything went well. I can’t figure out the root cause of this permission problem on v4.2.1.

Thank you in advance for your help.