0

I'm trying to run a PHP script on the command line.

listing for myscript.out

<?php
   echo "Hello world";
?>

Let's try running it...

$ php myscript.php > myscript.out

$ cat myscript.out

Expected output in myscript.out:

Hello world

Actual output:

<?php
   echo "Hello world";
?>

Whatever the script, php simply echos out the contents and does not attempt to run the script.

$ php -v
PHP 5.3.2 (cli) (built: Jun 25 2010 13:04:28) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

I'm on OSX Snow Leopard and have installed php via macports.

1
  • What's the output on the command line if you call php myscript.php?
    – Andrew
    Jun 28, 2010 at 7:16

2 Answers 2

0

Try to run php -q myscript.php.

-1

This is an indirect solution to your problem.. Very likely php is not configured properly. XAMPP is a 1-click setup for PHP/MySQL/Apache and a few other useful things. It will very likely solve your problem. ;-)

4
  • 3
    Solved my own problem - my scripts had the following opening two lines: #!/usr/bin/php <? I've recently reinstalled php and changed the location. What an idiot!
    – user46968
    Jun 28, 2010 at 7:27
  • You know, if you had XAMPP installed it, you wouldn't have to run PHP as CGI, and thus you wouldn't have to list the path with each file. That's the great thing about PHP over Perl.. Perl, you always have to begin by citing the path to perl, but PHP, you can start with <?php
    – inac
    Jun 29, 2010 at 9:20
  • And, that's mean of you for giving me a -1 on my first attempt at answering a question here! :-(
    – inac
    Jun 29, 2010 at 9:21
  • You should probably vote to close this question then. I don't have enough rep on this network yet to do that. Feb 18, 2019 at 3:36

You must log in to answer this question.