fchristant Posted December 29, 2009 Share Posted December 29, 2009 I'm not really an administrator and need some help setting up a cron, well actually calling a PHP script from the command line in the first place. I have a PHP5 script that I need to run at the following location: /var/www/apps/myapp/services/myservice.php Before setting up a cron for that, I wanted to test this manually, like so: php /var/www/apps/myapp/services/myservice.php This results in nothing. I can confirm that that script did not run. There is also no error. However, if I cd into the directory, and then call the script: cd /var/www/apps/myapp/services php myservice.php ..it does work, as I can see from the log file of that script. It must be something incredibly simple that I'm overlooking, but how can I call that PHP script from the command line in one go, without going into the directory first? PS: I'm on Debian Etch, using Apache2 and PHP5. Quote Link to comment https://forums.phpfreaks.com/topic/186547-weird-path-problem-when-calling-a-php-script-from-the-command-line/ Share on other sites More sharing options...
trq Posted December 29, 2009 Share Posted December 29, 2009 Command line script should start with a shebang line which tells your shell what interpreter to use to execute the script. In your case you want to use php so place this on the very first line of your script. #!/usr/bin/php That path should be correct for Debian. Next thing is to make sute the script is executable. chmod 755 /var/www/apps/myapp/services/myservice.php There is no reason why you would need to be within the same directory as the script in order to execute it. How exactly are you confirming it didn't run? Quote Link to comment https://forums.phpfreaks.com/topic/186547-weird-path-problem-when-calling-a-php-script-from-the-command-line/#findComment-985684 Share on other sites More sharing options...
fchristant Posted December 30, 2009 Author Share Posted December 30, 2009 I did put the shebang in it and I did make sure it is executable, sorry for not mentioning that earlier. I did manage to get it to work now, but only by cd-ing into the dir first from the cron job. I'm happy it work, but it is still unexplained why it will not run from any dir, given that I use absolute paths everywhere. Quote Link to comment https://forums.phpfreaks.com/topic/186547-weird-path-problem-when-calling-a-php-script-from-the-command-line/#findComment-985707 Share on other sites More sharing options...
Daniel0 Posted December 30, 2009 Share Posted December 30, 2009 Command line script should start with a shebang line which tells your shell what interpreter to use to execute the script. That's not necessarily when you pass the file path to the interpreter and run that instead. Quote Link to comment https://forums.phpfreaks.com/topic/186547-weird-path-problem-when-calling-a-php-script-from-the-command-line/#findComment-985951 Share on other sites More sharing options...
trq Posted December 30, 2009 Share Posted December 30, 2009 Command line script should start with a shebang line which tells your shell what interpreter to use to execute the script. That's not necessarily when you pass the file path to the interpreter and run that instead. Of course, I am aware of that. Quote Link to comment https://forums.phpfreaks.com/topic/186547-weird-path-problem-when-calling-a-php-script-from-the-command-line/#findComment-986158 Share on other sites More sharing options...
Daniel0 Posted December 30, 2009 Share Posted December 30, 2009 I don't doubt you know, but the OP might not. Quote Link to comment https://forums.phpfreaks.com/topic/186547-weird-path-problem-when-calling-a-php-script-from-the-command-line/#findComment-986159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.