Apache 2.x on Microsoft Windows
This section contains notes and hints specific to Apache 2.x installs
of PHP on Microsoft Windows systems.
Note:
You should read the manual
installation steps first!
It is strongly recommended to consult the
» Apache Documentation
to get have a basic understanding of the Apache 2.x Server.
Also consider reading the
» Windows specific notes
for Apache 2.x before reading on here.
Download the most recent version of
» Apache 2.x
and a fitting PHP version. Follow the
Manual Installation Steps
and come back to go on with the integration of PHP and Apache.
There are three ways to set up PHP to work with Apache 2.x on Windows.
PHP can be run as a handler, as a CGI, or under FastCGI.
Note: Souvenez-vous que lorsque vous ajoutez
des valeurs représentants un chemin dans la configuration d'Apache sous Windows,
tous les antislash, comme c:\repertoire\fichier.ext, devraient être
convertis en slashes, comme
c:/repertoire/fichier.ext. Un slash final peut
également être nécessaire pour les dossiers.
Installing as an Apache handler
To load the PHP module for Apache 2.x the following lines in the
Apache httpd.conf configuration file must be inserted:
Exemple #1 PHP and Apache 2.x as handler
#
LoadModule php8_module "c:/php/php8apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
Note:
Remember, the actual path to PHP on must be substituted instead of
C:/php/ in the above examples.
Take care that the file referenced in the LoadModule directive is at
the specified location, and to use php7apache2_4.dll
for PHP 7, or php8apache2_4.dll for PHP 8.
The above configuration will enable PHP handling of any file that has a
.php extension, even if there are other file extensions. For example, a
file named example.php.txt will be executed by the
PHP handler. To ensure that only files that end in
.php are executed, use the following configuration
instead:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Running PHP as CGI
It is strongly recommended to consult the
» Apache CGI documentation
for a more complete understanding of running CGI on Apache.
To run PHP as CGI, the php-cgi files will need to be placed in a
directory designated as a CGI directory using the ScriptAlias directive.
A #!
line will need to be placed in the PHP files,
which point to the location of the PHP binary:
Exemple #2 PHP and Apache 2.x as CGI
#!C:/php/php.exe
<?php
phpinfo();
?>
Avertissement
Un serveur déployé en mode CGI s'expose à plusieurs vulnérabilités possibles. Veuillez lire notre
section sur la sécurité en mode CGI
pour apprendre comment vous protéger contre ces attaques.
Running PHP under FastCGI
Running PHP under FastCGI has a number of advantages over running it as a
CGI. Setting it up this way is fairly straightforward:
Obtain mod_fcgid
from
» https://www.apachelounge.com.
Win32 binaries are available for download from that site.
Install the module according to the instructions that will come with it.
Configure your web server as shown below, taking care to adjust any paths
to reflect your how you have installed things on your particular system:
Exemple #3 Configure Apache to run PHP as FastCGI
LoadModule fcgid_module modules/mod_fcgid.so
# Where is your php.ini file?
FcgidInitialEnv PHPRC "c:/php"
AddHandler fcgid-script .php
FcgidWrapper "c:/php/php-cgi.exe" .php
Files with a .php extension will now be executed by the PHP FastCGI
wrapper.