I was trying to get the following linux command to work using PHP. I read about the shell_exec command in PHP, that can be used to execute shell commands.
I am trying to output some simple text to a text file. I tried the following:
<?php
$cmd = 'echo "hi" > Desktop/test/output.txt';
shell_exec($cmd);
?>
Please note that, I am running this on Ubuntu 16.04. I have also made the www-data the owner of the Desktop/test folder so that it can write to it. The following is the command I used for that:
sudo chown -R www-data:www-data Desktop/test
When I execute the above command, directly in a shell I can see an output.txt file created with the string output.
However, when I execute the php script through apache web server, I cannot see the output.txt file being created.
Glad if you can point me towards the right direction.
Thanks
/home/yourUserName/Desktop/test/output.txt