I need some help as my script doesn't create a file. I want to run this script at cronjob. I am using Debian Linux with PHP and Apache.
My script is locate at /var/www/myapplication folder. I want to create / write a file at /var/www/myapplication/testfolder.
The commands I use in the php script is:
echo `whoami`;
exec ('whatever >> testfolder/testing.txt');
Folder rights:
drwxrwxrwx 2 www-data www-data 4096 Jul 27 09:55 testfolder
When I run the script directly from browser (http://127.0.0.1/myscript.php)
- it doesn't create the file (testing.txt)
- echo whoami says: www-data
When I run the script from the server with root rights (su):
php -q /var/www/myapplication/myscript.php >>log3.txt
- it creates the file (testing.txt)
- echo whoami says: root
log3.txt is created at /var/www/myapplication folder
When I run the script from crontab:
- /usr/bin/php -q /var/www/myapplication/myscript.php >>log3.txt
it doesn't create the file (testing.txt)
- echo whoami says: root
- log3.txt is created at /root folder
Why isn't testing.txt created my I run my script from crontab as a cronjob ?
shell_exec. Also, make sure the www-data user has correct write permissions for the directory.