Answer the question
In order to leave comments, you need to log in
Why is the file created in /home/admin/ and not /home/admin/domains/mydomain.com/public_html/?
I create a CRON job in DirectAdmin.
/usr/local/bin/php /home/admin/domains/mydomain.com/public_html/1.php >/dev/null 2>&1
Content 1.php
<?php
file_put_contents( '1.txt', '1' , false);
?>
The script runs, but the file is not created in /home/admin/domains/mydomain.com/public_html/ but in /home/admin/.
Answer the question
In order to leave comments, you need to log in
because the cron is running as some user. in this case - from the user admin.
And by default, the current directory is its home.
Because the working folder at this launch will be /home/admin, add to the script
at the very beginning, then the working folder will be the one where the script is located
chdir(dirname(__FILE__));
Everything is absolutely correct,
cron works as root and, accordingly, root has a completely different home directory, environment variables, php version, etc., etc.
Solution
1. crontab -e -uUSER NAME - but there are also subtleties with PHP, since they are not quite the same as those specified in the apache nginx configs, because again you did not specify which php.ini file to initialize and which version of which PHP representation.
2. but there is a much simpler way
, this is a cron and it doesn’t matter under which user since we will download a page from the site, which means that environment variables will be loaded from the site, all constants and php will be from the site, the site engine, etc., etc. .
In short, here
50 15 * * /usr/bin/wget -t 1 -O - 'http://site.ua/script.php?p1=a&p2=b'
50 15 * * /usr/bin/wget -O /dev/null -q http://test.ru/test/index.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question