Setup PHP On Windows For Development and Debugging is a guide designed for people installing PHP with debugging for the first time. This guide also forms part of a larger collection aimed at setting up development environments.

Hint to make this process easier.

There is a reasonable amount of configuration file editing involved in this process. While it is possible to use notepad, it is hard to read compared to other editors. Both Notepad++ and Visual Studio code make reading the files much easier. Since this is a development environment, Visual Studio Code is probably a better choice as it offers greater scope in other areas. It is available from the Microsoft Website Downloads. While installing it is suggested you include ‘edit with Code’ options in Windows Explorer

Setup PHP On Windows – Download And Extract

Visit the PHP downloads page for Windows and choose the thread-safe version which matches your system (32 or 64 bit). At the time of writing the current version of PHP is 7.4.

First, extract the PHP Zip file into the Downloads folder rather than directly into its final location. Secondly, go into Windows Explorer. Navigate to your download then right-click it and choose extract all.

Setup PHP On Windows With Debugging - Extract the PHP Zip File
Extract the PHP Zip File

Once the folder has been extracted, rename it to either ‘php’ or ‘php-7.4.12’. Either option is ok, however, if you only intend to install one version of PHP on your system choosing ‘php’ is the most sensible choice.

Now move the folder to the root of your C:\ drive.

Setup PHP On Windows – Add PHP Folder to the system path

The PHP folder needs to be part of the system path. Use the following procedure to achieve this.

  1. Type ‘Environment’ into the search bar next to the start button and choose Edit the system environment
  2. Next Click on Environment Variables
  3. In the System Environment section find path, select it then click Edit
  4. Choose the new button in the following window
  5. Follow this by clicking browse
  6. Navigate to the PHP folder which was created above and click OK

Now restart the system. A restart might not be required, but this depends on the version of Windows and other system settings. Restart to be sure.

Configure Apache To Work with PHP

Apache needs to know where to find and how to use PHP files. Firstly navigate to the Apache folder. Secondly into a subfolder called ‘conf’ and edit the file called ‘httpd.conf’. Thirdly add the text below to the bottom of the file and save. Finally, The location of the Apache folder is not fixed. Consequently, if the PHP folder is not located at ‘C:\php’, the text below will need editing to match your system. The default location is c:\Apache24 for version 2.4*. A Guide to setting up Apache 2.4 is available in Setup Apache On Windows 10.

#php config
PHPIniDir "C:/php"
AddHandler application/x-httpd-php .php
LoadModule php7_module "C:/php/php7apache2_4.dll"

Also edit the server name section to read

# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
# If your host doesn't have a registered DNS name, enter its IP address here.
ServerName localhost:80

Configure PHP

  • Navigate to the PHP folder
  • Find the file called ‘php.ini-development’
  • Copy this to a new file called ‘php.ini’
  • Edit the php.ini file

Essential Changes

Paths and Directories Sections: Remove the semi colons before

  • extension_dir = “ext”
  • include_path = “.;c:\php\includes”
; Paths and Directories ;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
; Windows: "\path1;\path2"
include_path = ".;c:\php\includes"
; PHP's default setting for include_path is ".;/path/to/php/pear"

; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues.  The alternate is to use the
; cgi.force_redirect configuration below
doc_root =

; The directory under which PHP opens the script using /~username used only
; if nonempty.
user_dir =

; Directory in which the loadable extensions (modules) reside.
;extension_dir = "./"
; On windows:
extension_dir = "ext"

Helpful Changes

Remove semi colons to un-comment the following extensions

  • extension=curl
  • extension=fileinfo
  • extension=gd2
  • extension=mbstring
  • extension=pdo_mysql
  • extension=pdo_sqlite
  • extension=shmop
; Dynamic Extensions ;

; If you wish to have an extension loaded automatically, use the following
; syntax:
;   extension=modulename
; For example:
;   extension=mysqli
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;   extension=/path/to/extension/
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
; Notes for Windows environments :
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.
;extension=exif      ; Must be after mbstring as it depends on it
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client

Check PHP is working in command line

  • Type ‘cmd’ into the search box next to the start button
  • Click on Command Prompt
  • Type ‘php-v’ into the command prompt window
Setup PHP On Windows With Debugging - Check PHP using the command line
Check PHP using the command line

Restart Apache Server

  • Type ‘services’ into the search bar near the start button
  • Click on the Services application
  • Navigate to Apache
  • Right-click and choose restart

Testing PHP In A Browser

  • Navigate to the Apache Folder
  • Then into a subfolder called ‘htdocs’
  • Add a new file called info.php
Create info.php file
Create info.php file
  • Edit ‘info.php’ and add the PHP code below
// Show all information, defaults to INFO_ALL
Edit info.php in Visual Studio Code
Edit info.php in Visual Studio Code
  • Save the file
  • Open a browser and navigate to ‘localhost/info.php’
Setup PHP On Windows With Debugging - PHP info page
PHP info page

Setup PHP On Windows – Add Extension for Microsoft SQL Server

  • First, download the files from the Microsoft Site or use the direct download
  • Second, Run the executable
  • Accept the licence agreement
  • Browse to the PHP folders ‘ext’ subfolder
  • Click OK
Install SqlSrv for SQL Server to PHP extensions folder
Install SqlSrv for SQL Server to PHP ext folder
  • Navigate to the php.ini file
  • Edit php.ini and add the lines below to the end of the extensions
  • N.B if you did not install PHP to C:\php the path in these lines will need adjusting accordingly.
  • N.B.2 If your system is an X86 adjust the file name accordingly
  • N.B.3 If you installed the non-thread-safe version adjust the file name accordingly
Add Sqlsrv extensions to php.ini
Add Sqlsrv extensions to php.ini

Setup PHP On Windows – Add Xdebug Extension

  • Open command prompt
  • Type in ‘php -i’
  • Copy the entire output to the clipboard
  • Visit the Xdebug install instructions page for windows
  • Paste the output into the analyse box
  • Download the file suggested

At the time of writing the suggested file is php_xdebug-2.9.8-7.4-vc15-x86_64.dll. This may change over time. If it does the file name added to the configuration files will also need to be updated.

  • Finally Add the following just under the Module Settings
Add Xdebug Settings to php.ini
Add Xdebug Settings to php.ini

If you wish to use Xdebug with PhpStorm also add the following to the end of the [xdebug] section


Test the PHP configuration in the command line.

  • Load cmd as describe above
  • Type in ‘php -v’
  • Hit enter
Setup PHP On Windows With Debugging - PHP command line with Xdebug Installed
PHP command-line with Xdebug Installed
  • Restart Apache again as described above
  • Open a browser and navigate to ‘localhost/info.php’
Setup PHP On Windows With Debugging - Browser Showing Xdebug support in PHP
Browser Showing Xdebug support in PHP

Video Demonstration

Articles Related To – Setup PHP On Windows

This article has 2 comments

  1. Pingback: PhpStorm Xdebug Setup In Windows - Sara Payne's BlogSara Payne's Blog

  2. Pingback: Setup Apache On Windows 10 - Sara Payne's BlogSara Payne's Blog

Leave a Comment

Your email address will not be published. Required fields are marked *