You are not logged in.

#1 2010-01-09 22:06:46

DWilliams
Member
From: Everywhere
Registered: 2009-11-22
Posts: 119

Installing PHP CLI

I'm trying to develop a non-web based PHP script. I don't want to install a webserver, I just want the PHP CLI so that I can run what scripts I write. I installed the "php" package, but it doesn't seem to do anything.

If I call php with either "php myfile.php" or "php -f myfile.php" it just echoes the file back to me. If I run the "php" command by itself it just sits there accepting input and doesn't do anything with it (no errors no execution no anything). Is "php" the right package here? If I type "man php" it describes itself as the PHP CLI...

Offline

#2 2010-01-10 02:47:13

dmartins
Member
Registered: 2006-09-23
Posts: 360

Re: Installing PHP CLI

Did you surround your code with <?php ?> tags? I think they are still needed to let the php interpreter know that what follows is php code.

Offline

#3 2010-01-12 14:26:07

habbit
Member
From: Melbourne, Australia
Registered: 2010-01-12
Posts: 2

Re: Installing PHP CLI

dmartins wrote:

Did you surround your code with <?php ?> tags? I think they are still needed to let the php interpreter know that what follows is php code.

The alternative would be to run

php -r myscript.php

Which would negate the need for the <?php ?> tags.

Offline

#4 2010-01-13 06:14:30

hrabbit
Member
From: Melbourne, Victoria, Australia
Registered: 2010-01-13
Posts: 1

Re: Installing PHP CLI

DWilliams wrote:

If I run the "php" command by itself it just sits there accepting input and doesn't do anything with it (no errors no execution no anything). Is "php" the right package here? If I type "man php" it describes itself as the PHP CLI...

Sorry, can't edit my post above, change of nick..

If you run a command by hand from the CLI you would need to press ctl+d to have it interpreted. Of course, without the -r you would still need the php tags, even when writing your script by hand.

Example

# php
<?php echo "foo\n"; ?>

followed by a control+d will output "foo"

Offline

Board footer

Powered by FluxBB