Re: PHP CLI Problem
| From: | Jim Lucas | Date: | Wed, 06 Feb 2008 15:44:40 +0000 |
| Subject: | Re: PHP CLI Problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268784@lists.php.net to get a copy of this message | ||
Robbert van Andel wrote:
I am having trouble with a PHP CLI script I wrote to help manage my website. The site is on a shared hosting server where the PHP installation is set up as a CGI. The script creates some backups of my databases and sends them to Amazon's S3 service. First off, the script runs great from the command line when I type "php5 backup.php" but when I type ./backup.php I get an error: "bash: ./backup.php: No such file or directory". I thought maybe this is a problem with the top declaration in the script "#!/usr/local/bin/php5". The problem is that it appears the server has several php5s I can reference /usr/local/apache/share/cgi-bin/php5 /usr/local/bin/php5 But it doesn't matter which one I put at the top of the script, I get the same error. Okay, so I can live with having to type "php5 backup.php". However, when I try to make a cron job from the script, the script never runs. The crontab entry looks like this 1 0 * * 2 php5 /kunden/homepages/23/d117947228/htdocs/oregonswimming/administration/backup/ backup.php > backup.logAre you trying to add this to your /etc/crontab file directly, or are you issuing crontab -e from the command line? If you are entering the above line into the crontab directly, then you are missing a parameter. Between the day of the week and where you have php5, you need to add the user that the script is suppose to run as. Since you are able to run the script manually, it must be something to do with how/where you are entering it into cron and/or the environment variables available to the user that your crontag launches the script as. Maybe without a complete login, the cron user doesn't have the /usr/local/bin/ in its PATH ? Just a couple thoughts.
I know the backup never runs because I redirect the output to a file and have an email sent to me upon conclusion of the script. The log file doesn't show anything nor do I ever receive an email. My web host will not provide any support for scripting, so I'm hoping someone here can help. Questions: * How do I determine what to put at the top of the script so that I can just call "backup.php"? * What, if anything, do I need to do to make the script work from cron? I've seen some comments on the web regarding PHP CLI when PHP is a CGI, but none of them seem to apply to me. Thank you in advance for your help. Robbert-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare