CyberPanel Community

Shell_exec returns permissions error

Ah
Ahmed #1

Hi,

Trying to copy files from /home/core_files to website folder, but permissions error returns

any idea how to fix it?

function copyStoreFiles($domain) {
  
    $cp = shell_exec('cp -r /home/core_files/* /home/'.$domain.'/public_html');
  
   // updateConfigValues();
}

4 replies
jo
josephgodwinke #2

Welcome @chillyplate Happy you are here

You need to run your command as root/sudo user e.g.

shell_exec('sudo cp -r /home/core_files/* /home/'.$domain.'/public_html');

Let me know if this works

Ah
Ahmed #3

Thanks for the suggestion, but I tried running the command as sudo as you suggested, but unfortunately, it still isn’t working.

jo
josephgodwinke #4

Then you have to allow www-data to not use password by editing the sudoers file sudo visudo but this is not best practice

Ah
Ahmed #5

I’ve fixed it by getting the Linux user

shell_exec('whoami');

then copy the user and add it to the sudoers list

Sign in to reply