6

shell_exec("touch /Users/Nerses/Downloads/ads.txt 2>&1")

I have a problem with the PHP exec(shel_exec) function. It says that I do not have permissions to execute the command.

How can I open these permissions?

Dakkaron
  • 5,930
  • 2
  • 36
  • 51
user3918128
  • 101
  • 1
  • 2
  • 9
  • Can you please edit the question and copy+paste the exact error message? – Álvaro González Aug 18 '15 at 08:54
  • "touch: /Users/Nerses/Downloads/ads.txt: Permission denied " – user3918128 Aug 18 '15 at 09:14
  • It says you don't have permissions to edit the **file**. Such file is in the home directory of "Nerses". I guess you run PHP with the Apache user or something similar-you'll have to tweak file system permissions (assuming SELinux or some other tool doesn't prevent further access). – Álvaro González Aug 18 '15 at 09:26

1 Answers1

13

Your PHP code is trying to access /Users/Nerses/Downloads/ads.txt, as you can see, that folder is owned by the user called "Nerses".

He is the only one (and root) who can access it (unless you change the permissions to that folder).

Normally, the user that executes shell_exec is called www-data, so give permissions to that user, or change the ones in that folder.

Other option is to execute

shell_exec('sudo -S YOUR COMMAND');

You can check out the user you use with the command

shell_exec('whoami');
SpongePablo
  • 870
  • 10
  • 24
  • Thank you! The folder where my file was is owned by other user than the apache's, so changing the parent folder's ownership to the apache's user and group did it for me. – GTodorov Apr 15 '16 at 04:59