Running php scripts that include relative paths with cron

I recently had a problem running a php script which had an include() in it using cron. It worked fine in normal testing, but not as a cron job.

The reason is that when browser testing the working diorectory is the script’s directory. Cron uses the php location as the working directory, so the relative paths won’t be the same.


Either use absolute paths or change the working directory.

One Comment on “Running php scripts that include relative paths with cron”

  • David Polehonski April 26th, 2012 1:30 pm

    I had the exact same problem a couple of months back, I also had to contend with a shared server environment with magic constants turned off. I had a similar solution to yours.

Leave a Reply