Reputation: 1
I have several php scripts I am trying to set up (recently moved to a new server) they will run from the command line and through the browser but only one will run through cron the other seems to have a permissions problem, if the file is set to 644 I get this message from cron: /bin/sh: /home/xyz/public_html/scripts/update-script.php: Permission denied
If I set permissions to 777 I get this message:
/home/xyz/public_html/scripts/update-script.php: line 1: ?php: No such file or directory
/home/xyz/public_html/scripts/update-script.php: line 2: syntax error near unexpected token `"includes/clsDatabase-list.php"'
/home/xyz/public_html/scripts/update-script.php: line 2: ` require_once("includes/clsDatabase-list.php");'
yet the script runs from the command line and via browser AND i have another script that is almost identical to this one (calls for the same include on line 1, is located in exactly same folder) that will run through cron! So I know my paths and cron job that I setup in Cpanel are right. If I copy the working one in the command line, the copied version also fails to run via cron. Thanks!
Upvotes: 0
Views: 1292
Reputation: 318798
You need to add a shebang to your file to execute it directly:
#!/usr/bin/env php
<?php
//...
Another option would be calling it like this in your cronjob:
* * * * * php /home/xyz/public_html/scripts/update-script.php
Of course you'd replace the * * * * *
with the actual crontab data unless you want it to run every minute.
Upvotes: 1