Ryan
Ryan

Reputation: 14659

Does my PHP command line have a bug?

As I type a script into it, or even something like this:

$ php -v

absolutely nothing happens.

Edit: Operating System: Windows 7

$ echo %PATH%

absolutely nothings happens

Full path to PHP:

C:/Program Files(x86)/PHP

Upvotes: 1

Views: 753

Answers (2)

Patrick
Patrick

Reputation: 3440

I am willing to bet that you are running something like WAMP or another application that allows you to run a web server from your local machine. The problem with this is you are not running PHP directly on your machine. What instead is going on is that the Apache web server is launching a PHP instance on the fly.

The PHP instance that runs from a command line is completely separate from the one that Apache launches. Sometimes it is from the same codebase/copy of PHP, but one does not suggest the other. So you can have PHP working in one but not the other. It can be a little confusing but it has to do with how the web server operates more than anything else.

So you need to actually install PHP in Windows. This copy of PHP WILL NOT be the copy that your web server is using. For example, my work computer is running Mac OS X (my home is Win7) and it comes with PHP and Apache installed. But I don't use the original install. Instead I use Zend Server Community Edition (for my own reasons) most of the time and sometimes I even run XAMPP. So in my case I actually have 3 different copies of PHP on my machine. The one that came with my machine (and that runs in the command line), the one in Zend, and the one in XAMPP.

For my situation running a command line PHP instance will use separate settings/config from Zend and XAMPP.

You can find the Windows binaries for PHP here: http://windows.php.net/download/
I would recommend PHP 5.2.x for compatibility reasons (with most PHP apps): http://windows.php.net/download/#php-5.2-ts-VC6-x86

Upvotes: 2

Alex Turpin
Alex Turpin

Reputation: 47776

What were you trying to do?

If you want the PHP version, do

php --version

If you want an interactive shell, do

php -a

If you want to interpret a file, do

php -f your_file.php

Upvotes: 0

Related Questions