Configuring Apache for PHP CGI Scripts

This section describes how to configure Apache server to support PHP CGI scripts.

With both PHP engine and Apache Web server installed on my Windows system, I continued to configure the Apache server to support PHP CGI scripts:

1. Open the Apache configuration file, \apache\conf\httpd.conf, in a text editor

2. First I have to define a CGI script directory alias, mapping an Apache document directory to a real directory where php-cgi.exe is located. Go to alias_module section and add one line:

<IfModule alias_module>
   ScriptAlias /cgi-bin-php/ "/local/php/"

3. Then I need to add an access control section for this directory as:

<Directory "/local/php/">
     AllowOverride None
     Options None
     Require all granted

4. Next, I have to define a new MIME type to support the .php file extension. Go to mime_module section and one line:

<IfModule mime_module>
    AddType application/x-httpd-php .php 

5. The last setting is to tell Apache to serve the new MIME type with php-cgi.exe located in the directory alias /cgi-bin-php/: At the root level below the LoadModule section, define an "Action" entry:

#LoadModule xml2enc_module modules/

Action application/x-httpd-php "/cgi-bin-php/php-cgi.exe"

6. The configuration changes are done. Now restart the Apache server by closing the following command line window and re-enter it again:

C:\herong> \apache\bin\httpd

Another way to integrate Apache with PHP is to set PHP as a load module. This is more efficient than the CGI script interface. But for my personal testing purpose, the CGI script interface is good enough.

Last update: 2019.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.3

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Introduction of Class and Object

Integrating PHP with Apache Web Server

 Downloading Apache 2.4.37 Binary for Windows

 Installing Apache 2.4.37 on Windows Systems

 Publishing HTML Documents as Web Pages

 Starting and Stopping Apache Server

Configuring Apache for PHP CGI Scripts

 Publishing PHP Scripts as Web Pages

 Permission Error on php-cgi.exe

 Configuring Apache PHP Load Module

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Configuring and Sending out Emails

 Outdated Tutorials


 Full Version in PDF/EPUB