LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   PHP CLI has me shebanging my head against the wall (https://www.linuxquestions.org/questions/linux-newbie-8/php-cli-has-me-shebanging-my-head-against-the-wall-810513/)

enormoustrousers 05-27-2010 01:25 PM

PHP CLI has me shebanging my head against the wall
 
I am using Zend Server CE on one of my servers and I’d like to do some PHP work from the CLI. Zend comes bundled with the PHP executable and an associated wrapper for the CLI, cleverly called php-cli. Among other things, this wrapper points to the correct php.ini file, which is key as it contains the information necessary to get PDO (DB abstraction) up and running.
The wrapper essentially contains this code:

Code:

#!/bin/sh
/opt/zend/bin/php -c /opt/zend/etc/php.ini $@

The problem I’m having comes from my attempt to use php-cli for scripting. I foolishly thought this would work:

Code:

#!/opt/zend/bin/php-cli
<?php
    // Code goes here

But, of course, I was being stupid. Doing this fails to interpret the PHP at all and I receive this error:

Code:

./cli-test.php: line 2: ?php: No such file or directory
In an attempt to salvage what remained of my tarnished reputation, I tried to completely bypass the wrapper and mimic the same functionality with the executable by doing the following:

Code:

#!/opt/zend/bin/php –c /opt/zend/etc/php.ini
<?php
    // Code goes here

Code interpretation works, but the ini file is not loaded (I know this because the DB drivers are not loaded). If, however, I try this from the command line in interactive mode as follows, the DB drivers are loaded and it works fine:

Code:

php –c /opt/zend/etc/php.ini
Any thoughts would be greatly appreciated as I’ve wrestled with this for quite a few hours now, the net effect of which has me questioning my career choice. I suppose the world always needs shepherds.

spampig 05-27-2010 01:42 PM

So if you do 'which php' do you get something sane back? e.g;
Quote:

# which php
/usr/bin/php
If so, set your shebang to that path, as in:
Quote:

#!/usr/bin/php
<?php
echo "Helo World\n";
?>
Not sure if that is much more help than tits on a fish - but good luck ;-)

enormoustrousers 05-28-2010 07:14 AM

Thanks for your reply. The PHP executable and the wrapper (php-cli) are both located in /opt/zend/bin, which is the same path returned by "which php".

enormoustrousers 05-28-2010 11:26 AM

As anticipated, I'm a fool. The problem was that PHP was looking for php.ini in /usr/local/zend/etc, which doesn't exist. I added a symbolic link to redirect it to the correct place and viola -- success! Of course, I still don't know why it wasn't looking where I told it to with the -c flag, but I'm content in my victory however small.


All times are GMT -5. The time now is 04:09 PM.