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:
- Execute flag:
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