1

I set my PHP script to run my node script using exec

exec("node ../server/server-manager/server-manager.js &");

However, my node script is not able to create a log file and outputs this error.

{ Error: EACCES: permission denied, open '../../logs/server-manager/server-manager.06-20-2021 11-01-59 PM.log'

I assume its because the PHP script doesn't have sufficient permission to run the node script as root.

I tried changing the script and folder permissions to 777, but the issue remains.

How can I make my PHP script run my node script with full access?

Here is the output of my script:

Current directory:  /var/www/image-game/top/server/server-manager

{ Error: EACCES: permission denied, open '../../logs/server-manager/server-manager.06-21-2021 00-53-22 AM.log'
    at Object.openSync (fs.js:443:3)
    at Object.writeFileSync (fs.js:1194:35)
    at Object.appendFileSync (fs.js:1240:6)
    at Console.console.log (/var/www/image-game/top/server/console.to.file.js:21:6)
    at Object. (/var/www/image-game/top/server/server-manager/server-manager.js:71:9)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
 path:'../../logs/server-manager/server-manager.06-21-2021 00-53-22 AM.log' }

1 Answer 1

1

unless you have mounted a readonly path or using acls, or other esoteric settings chmod should be enough to make it work.

Then, are you sure about the path expansion ? you can do this to see the current working directory the command is using

echo shell_exec("pwd");

hence the expension

echo shell_exec("realpath ../../logs");

Also, are you sure about the running user ?

echo shell_exec("id"); // may show www-data

because one way to give acces is to do chmod 777. another way is to chown the folder to the one php is run with. chown www-data should work too

Sign up to request clarification or add additional context in comments.

1 Comment

The top of my node script has process.chdir(__dirname); and I confirmed its using the correct directory with process.cwd(). id returns uid=33(www-data) gid=33(www-data) groups=33(www-data). I added more of the console output to the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.