Setting up PHP-CLI on Windows XP

This is just a quick one, but something I found information about strikingly absent.

All the PHP-CLI guides explain how to install it so typing “php -v” gives you the expected CLI response, but nobody bothered to explain how to link PHP scripts so you can run them like an EXE without having to type PHP first.

Grab PHP from any of the php.net FTPs. If you’re lazy like me, get both the zip and the installer–the installer lacks all the goodies like zip support and GDLIB.

Run the installer, stick it in C:\PHP, choose not to configure a web server. Next, open the zip, extract everything into the same folder. Rename php.exe to php2.exe or php.exe.bak. Now copy the php.exe from the C:\PHP\CLI folder to C:\PHP.

Right-click My Computer and pick properties. Click the Advanced tab, then the Environment Variables at the bottom. In the second list-box you’ll see a line for PATH. Double-click it and add to the end of the existing line “;C:\PHP” This should give you something like:

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\Program Files\Command;C:\PHP

Click OK.

Now open a Command Prompt and type the following lines:

ASSOC .php=PHPScript
FTYPE PHPScript="C:\PHP\PHP.EXE" "%1" %*

You’re all set. You can now just type a PHP script name to run it like an EXE. No need to type PHP first.

Related Posts

Related posts brought to you by Yet Another Related Posts Plugin.


About this entry