I'd like to create a cronjob to execute a .php file on Ubuntu but it currently does not worked. The .php file is placed at /var/www/createfile.php to create a text file. I've tried to executed some commands on ssh. as follow
'php /usr/bin/php /var/www/createfile.php' after that,
'/user/bin/php /var/www/createfile.php' after that,
'php /var/www/createfile.php'
(those are executed one after I found that the previous command doesn't worked)
The results from those commands are the same, there is no '.txt' file as expected. However, when I run 'php createfile.php' when I was at the directory storing the 'createfile.php', I got a '.txt' file as intending.
I'm not quite sure what did I do wrong?
thanks in advance.
// below this is what I would update, the above statement might confusing some of you. I'm sorry for that.
this is the code in '.php' targeted to execute
> <?php
$myfile = fopen("newfile.txt", "w");
$txt = "Mickey Mouse\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
Obviously, it's just simply create a file with a line of phrase. here is the ways I'd tried but doesn't work
- create cronjob like 'minute * * * * php /var/www/createfile.php' << this did work. So, I tried the commands like what I described at root directory with root permission.
However, the file was created by other user (let's say by Alice) I have no idea if Alice vs. root permission is a certain point of concern?
HOWEVER: there currently is one way which work. I've to run the command like 'php createfile.php' when I locating at '/var/www' (it is the path the 'createfile.php' locates) << this is the way which currently work.