Executing PHP script in crontab (include path problems)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Executing PHP script in crontab (include path problems)
I'm attempting to run a script by launching it daily from the crontab. The script works fine when I call it from the browser. However, whenever the crontab attempts to initiate the script it gets an error.
Warning: require_once(/pathtomyscript/includes/co… failed to open stream: No such file or directory in /pathtomyscript/cron.php
Apparently the crontab has difficulties with executing scripts that contain relative paths. To fix this I tried changing the path to an absolute path like /home/www/public_html/pathtoscript/inclu… however this gives me the error of illegal include. How should I control my include paths so that they work with the cron tab?
The scripts are owned by root and the cronjob is executed by root.
When you say: "call it from the browser" ... is it actually meant to
be run under the control of apache? If so, why don't you point a
command-line browser like lynx, links or even curl or wget to it
from your cron-job?
Is this secure? Eventually I had planned on either moving the script to a non web-accessible location or password protecting it. The purpose of the script is to initiate a reindex of my database for my search engine.
I'm using mysql and the sphider php search engine. The indexing script has some degree of complexity.
Shouldn't I be able to adjust the include path so that the crontab located in
/etc/crontab
can call the index script in
/home/www/public_html/search/admin/cron_index.php
and the cron script can include a config file at:
/home/www/public_html/search/includes/config.conf
The script does not have to be accessible to anything other than the crontab. It is in the search directory just to keep it in close proximity with all the search elements.
My knowledge of PHP is quite limited, but my guess is that the paths
in the web-based interface are relative to the document root of the
site - which is why I suggested to access it via a browser. If you
modify the include directives within the php-scripts you may break
the behaviour of the web part. All this, of course, is just general
hand-waving, derived from my ideas on how things work, and why they
don't work from cron. I don't think that any include path you throw
at cron will fix the interdepencies of the scripts.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.