LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2010, 01:25 PM   #1
enormoustrousers
LQ Newbie
 
Registered: Dec 2006
Posts: 5

Rep: Reputation: 0
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.
 
Old 05-27-2010, 01:42 PM   #2
spampig
Member
 
Registered: Feb 2010
Location: /Earth/UK/England/Hampshire
Distribution: Debian, Ubuntu, CentOS, Slackware
Posts: 262
Blog Entries: 2

Rep: Reputation: 56
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 ;-)
 
Old 05-28-2010, 07:14 AM   #3
enormoustrousers
LQ Newbie
 
Registered: Dec 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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".
 
Old 05-28-2010, 11:26 AM   #4
enormoustrousers
LQ Newbie
 
Registered: Dec 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Before I keep beating my head against a wall... watcher69b Linux - General 4 02-17-2009 12:38 AM
Beating my head against the email wall - cannot receive email dazed-and-confused Linux - Server 16 09-02-2008 05:14 AM
Sata Raid + IDE = it won't install *head hitting wall* m0ngos3 Slackware - Installation 3 01-23-2005 04:09 PM
DirectColor,16bits, Wall, Head, Bash PhilShaw Linux - Hardware 0 11-11-2003 04:48 AM
bashing my head against a wall mcd Linux - Newbie 12 08-16-2003 01:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration