have a cron job that is located in a folder in the normal directory.
I am trying to not allow access to this file by anyone else EXCEPT my server for running the cron job.
I tried:
order deny,allow
deny from all
allow from 127.0.0.1
But no luck. I have gone down the root of putting the cron job outside the web root but i could not get it to run no matter what me and my host tried.
Thanks.
Two things here: (a) getting the cronjob to run, (b) access restriction.
Cronjob
New crontab entry:
*/10 * * * * /usr/bin/php /somewhere/www/cronjob.php
Set correct permissons on cronjob.php:
chmod +x /somewhere/www/cronjob.php
Access Restriction
In general, it is a good practice, to place the script files for cronjobs outside of the www
path.
If you really need to place them in www
, then you might protect them with an access restriction. For the webserver Apache, this would work via .htaccess, like so:
.htaccess
inside /somewhere/www/
:
<Files "cronjob.php">
Order Allow,Deny
Deny from all
</Files>
This protects the file cronjob.php from outside access, but allows cron to execute the file.
If nothing works, follow my step by step guide: https://stackoverflow.com/a/22744360/1163786
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With