Jump to content

php cli in shell script


generaldarkness

Recommended Posts

Having trouble with running php in a shell script.

 

The command im trying to use is

 

 echo '<?php echo "test"; ?>' | php -q 

 

This simply returns nothing from the command line, ive tried path to php aswell and no joy.

 

#!/usr/local/bin/php -q

<?php echo "test"; ?>'

 

Will work, so it looks like the cli is working but i cant execute it from within a shell script.

 

php -v shows

 

PHP 5.2.5 (cli) (built: Nov 22 2007 02:14:24)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
    with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by ionCube Ltd., and
    with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies
    with Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies

 

was built with whm really cant work out how to get this working, anyone got any ideas?

 

Thx in advance

Link to comment
Share on other sites

thx for the reply SemiApocalyptic , that also works for me fine. Trouble is i need to get it working from the following command as its part of a install script, so if it doesnt work at this point the rest of the install doesnt work properly.

 

Heres the full section that it stops at.

 

# make sure PHP is sane
PHPTEST=`echo '<?php echo "test"; ?>' | php  -q 2>&1`
if [ "x$PHPTEST" != "xtest" ]; then
echo "Your PHP CLI binary does not appear to be working correctly.  Please"
echo "correct this problem and then restart this installation script."
exit 1

Link to comment
Share on other sites

PHPTEST=$(/usr/bin/php -r 'echo "test";')
if [ "$PHPTEST" != "test" ]; then
  echo "Your PHP CLI binary does not appear to be working correctly.  Please"
  echo "correct this problem and then restart this installation script."
  exit 1
fi

 

Of course, you would be much better of checking whereis to see if php exists somewhere else. Who says it must be in /usr/bin/php

Link to comment
Share on other sites

Hey thorpe thanks for the reply, which php shows /usr/local/bin/php, but running this still returns nothing from the command line, plus i need to be able to find php by using the php command not the path to it.

 

Do you think there must be something wrong with my php? and do you think a recompile would help?.

 

Edit: after waking up i realised this was meant to return nothing from the command line, so it is working by using php aswell. So does this mean my php is working ok and do you know why it wouldnt work the other way as my install doesnt seem to be working properly when it gets stuck at this point of the script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.