Building Chinese Web Sites using PHP
Dr. Herong Yang, Version 2.11

Running PHP Scripts

This section describes how to run PHP scripts in a command window in normal mode and in CGI mode.

PHP scripts can be executed with two different command interfaces:

  • PHP CLI (Command Line Interface), php.exe - Scripts are executed under the normal operation system environment.
  • PHP CGI (Common Gateway Interface), php-cgi.exe - Scripts are executed under the CGI environment created by a Web server.

To do a quick test with both interfaces, I wrote the following simple script, hello.php, with a text editor:

Hello <?php echo "world!"; ?>

I used the \local\php\php.exe to execute this script in a command window:

C:\>\local\php\php hello.php
Hello world!

I then the \local\php\php-cgi.exe to execute this script in a command window:

>\php\php-cgi Hello.php
Content-type: text/html
X-Powered-By: PHP/5.0.4

Hello world!

PHP CGI, php-cgi.exe, generated the HTTP response header as required by the Web server.

To learn more about running PHP scripts, read my other book: PHP Tutorials - Herong's Tutorial Notes

Sections in This Chapter

Download and Install PHP 5.2.2 on Windows

Running PHP Scripts

Dr. Herong Yang, updated in 2007
Running PHP Scripts