Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

listing for myscript.out

   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:

   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.

share|improve this question
What's the output on the command line if you call php myscript.php? – Andrew Jun 28 '10 at 7:16

Try to run php -q myscript.php.

share|improve this answer

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. ;-)

share|improve this answer
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 '10 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 '10 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 '10 at 9:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.