Shell_exec returns permissions error


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();

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

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

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

I’ve fixed it by getting the Linux user


then copy the user and add it to the sudoers list