PHP on Windows

The main PHP: Hypertext Preprocessor website, at first glance, seems to have nothing for Windows users. However, it is there, you just need to visit PHP For Windows.

The PHP For Windows site is fine for basic PHP use, however if you want to use it with the Apache Web Server (Welcome! - The Apache HTTP Server Project), then it is recommended you download both from the Apache Lounge. I just downloaded a Zip file for the version of PHP I wanted and extracted it. Not "well integrated" but it works for what I need.

Command Line

I did not find it obvious how to run a PHP script from the command prompt. Turns out you need something like this:
D:\Dev\php-5.4\php.exe -f D:\Development\PHP\Test.php note that I have used fully qualified paths for clarity.

These are some command line arguments when you use PHP from a console:

  • php -v displays the version of PHP
  • php -m lists the modules installed
  • php -r "echo 'Hello World';" executes the line of code
  • php -f <filename> executes the PHP script file
  • php -i displays more PHP information than you probably want, the command line version of phpinfo()
It is worth noting that executing php-win always produces no output, although the script will execute.