This guide explains how to install PHP and Apache HTTP Server (httpd) on Windows.
-
Visual C++ Redistributable
- Download and install the repository
- Extract the ZIP file to
c:\servicesor another location.
-
Configure Apache:
- Open the
httpd.conffile located inc:\services\httpd\confand update the following lines:Define SRVROOT "c:/services/httpd" Define DIRPHP "c:/services/php" Define DIRROOT "c:/www"
- Open the
-
Install & Start Apache:
- Open Command Prompt as Administrator.
- Navigate to the Apache
bindirectory:cd C:/services/httpd/bin - Install the Apache server:
httpd.exe -k install
- Start the Apache server:
httpd -k start
-
Download PHP:
- Choose your desired PHP version:
PHP Version Download Link PHP 5.6.40 Download PHP 7.0.33 Download PHP 7.1.33 Download PHP 7.2.34 Download PHP 7.3.29 Download PHP 7.4.33 Download PHP 8.0.30 Download PHP 8.1.29 Download PHP 8.2.22 Download PHP 8.3.10 Download
-
Extract PHP:
- Extract the ZIP file to
C:/services/php/5.6 .....or another location.
- Extract the ZIP file to
-
Configure PHP:
- Rename
php.ini-developmentorphp.ini-productiontophp.ini. - Open
php.iniin a text editor and:- Enable extensions:
extension=mbstring extension=curl extension=gd2
- Set the timezone:
date.timezone = "America/New_York"
- Enable extensions:
- Rename
-
Add PHP to System Path:
- Add
c:/services/php/5.6to the systemPathenvironment variable.
- Add
-
Verify PHP:
- Open Command Prompt and type:
php -v
- Open Command Prompt and type:
-
Configure Apache to Use PHP:
- Open the
httpd-vhosts.conffile inc:/services/httpd/conf/extra/httpd-vhosts.conf. Using the PHP version you downloaded fcgi enabled & vhost-host configured add the following configuration:
Listen 9081 <VirtualHost *:9081> ServerName localhost:9081 FcgidInitialEnv PATH "${DIRPHP}/8.1;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;" FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:/WINDOWS/Temp" FcgidInitialEnv TMP "C:/WINDOWS/Temp" FcgidInitialEnv windir "C:/WINDOWS" FcgidIOTimeout 64 FcgidConnectTimeout 16 FcgidMaxRequestsPerProcess 1000 FcgidMaxRequestLen 8131072 # Location php.ini: FcgidInitialEnv PHPRC "${DIRPHP}/8.1" FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 DirectoryIndex index.php FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" <Files ~ "\.php$>" AddHandler fcgid-script .php FcgidWrapper "${DIRPHP}/8.1/php-cgi.exe" .php </Files> DocumentRoot "${DIRROOT}" <Directory "${DIRROOT}"> Require all granted Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All </Directory> </VirtualHost>
- Open the
-
Restart Apache:
- Restart Apache to apply the changes:
httpd -k restart
- Restart Apache to apply the changes:
-
Test PHP with Apache:
- Create a
phpinfo.phpfile in thehtdocsdirectory (c:/www) with the following content:<?php phpinfo(); ?>
- Open your browser and navigate to
http://localhost:9056/phpinfo.php. You should see the PHP information page. PHP 5.6
- Create a
-
Apache won’t start:
- Check the
httpd.conffile for syntax errors:httpd -t
- Ensure no other application (e.g., Skype) is using port 80.
- Check the
-
PHP extensions not working:
- Verify the
extension_dirsetting inphp.inimatches your PHP installation:extension_dir = "c:/services/php/5.6/ext"
- Verify the
You now have PHP and Apache installed and configured on your Windows system. Happy coding! 🎉