views:

50

answers:

3

Is it possible to execute from crontab a php file inside a folder which is protected with htaccess and how?

A: 

I believe crontab can execute any of your scripts. .htaccess just plays over your web access so it should not stop crontab from executing it.

sushil bharwani
php only executes when served up from the web so .htaccess would stop it.
Malfist
A: 

No. If htaccess is set to deny access from the web it will prevent any web based method from accessing it. Running wget or curl from the commandline is just the same as accessing it in a browser and htaccess will stop it.

You can restrict access to the page with an authentication scheme and make the cron script authenticate and then it will work, but if htaccess is denying access, you can't access it.

It is possible to run php from the commandline without accessing from the web but it's iffy, here's a link that describes how to do it.

Malfist
A: 

.htaccess is a way to limit access from outside (the Internet) and is enforced by the apache. So there's nothing preventing the crontab to run the script.

the_void
What if the php script and htaccess are, lets say, on server 1 and crontab on server 2. Completely different hosting, domain names, etc.
nextu
You could run the script on the remote machine via `ssh`. You should setup `ssh` so that you can login without entering a password.
the_void