Problem running php script via crond

I'm trying to run a PHP script from crond and I keep getting the following error:

Fatal error: Call to undefined function mysql_connect() in /path/to/script on line 45

I can run the script fine from a superuser bash prompt via ssh by literally copying and pasting the command from my crontab to the prompt and hitting enter, but if I set it to run through crond I always get this error. I thought the script might be running as a user that does not have permissions to access the mysql module, but I'm fairly certain the script is running as root as I have installed the cron entry in /etc/crontab as the root user (I'm running CentOS with php 5.2.x).

Any help would be greatly appreciated.

2 Replies

Make sure the PHP it's running through cron is configured to load the mysql module. Use which to see what you're running when it works and use that path in your scripts shebang.

Wow you're right, apparently there's a slightly earlier version of the cli in my /usr/bin and my most recent version elsewhere. Specifying the full path to the php cli I actually want in my crontab did the trick. Was working on this for a looong time. You're the man!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct