Click here to Skip to main content
15,904,416 members
Articles / Programming Languages / PHP
Tip/Trick

Debug a PHP Application using the IIS Express, PHP 7.1 and XDebug for Visual Studio Code

Rate me:
Please Sign up or sign in to vote.
3.00/5 (4 votes)
6 Jun 2017CPOL3 min read 22.6K   5   1
Debug PHP applications under IIS Express

Introduction

As a .NET developer, I do not have much interest in configuring another web server like the Apache/ Tomcat. There is always the IIS that comes integrated with your Windows or Visual Studio. Why not use it?

Steps

So, assuming that you have Windows 10 x64 and Visual Studio Code, the following steps brought me to debug a PHP application using the IIS Express, PHP 7.1 and XDebug for Visual Studio Code:

  1. Check if you have the Microsoft Web Platform Installer 5.0 on your system: either in search bar, or in the Control Panel.

    If you do not have it, you may download it from here.

    Please install it.

  2. Check if you have IIS Express installed using the Control Panel.

    If you do not have it, open Microsoft Web Platform Installer 5.0 and type in the search box: “IIS express” and click enter. The “IIS 10.0 Express” should be available and click the “Add” button and the “Install” button. Follow the steps and finish the IIS Express installation.

  3. Again in the search box of the Microsoft Web Platform, type “PHP Express” this time and “PHP 7.1.1 (x86) For IIS Express” should be available. Click the “Add” button and then “Install” button. Follow the steps and finish the PHP for IIS Express installation.
  4. Go to %systemdrive%\Program Files (x86)\IIS Express\PHP\v7.1. There should be the PHP express installed.
  5. Open a browser window and download the XDebug library for PHP:

  6. Copy the downloaded file to extension folder of the PHP installation:

    %systemdrive%\Program Files (x86)\IIS Express\PHP\v7.1\ext

  7. Go to %systemdrive%\Program Files (x86)\IIS Express\PHP\v7.1 and open the PHP.INI file in an elevated editor (Notepad run as administrator). Add this XDebug section at the end and save the file:
    [XDebug]
    
    zend_extension = 
    "C:\Program Files (x86)\iis express\PHP\v7.1\ext\php_xdebug-2.5.4-7.1-vc14-nts.dll"
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1

    Note: I am assuming this is a fresh install of PHP, otherwise please check for a section or xdebug reference in the ini file and delete or update accordingly.

  8. Open Visual Studio Code and install the following extensions:
    • PHP Debug
    • PHP Intellisense

    You may install others, if you wish.

  9. Close Visual Studio Code.
  10. Create a folder and open the folder in Visual Studio Code.
  11. Create a new file index.php and do a phpinfo() call.
    PHP
    <?php
    phpinfo();
    ?>
  12. Insert a breakpoint to phpinfo(); line.
  13. Go to Debug and start Listen for XDebug.
  14. In the Visual Studio Code menu, go to View->Integrated Terminal. The terminal appears.
  15. Enter and run the command:
    > runphp.cmd

    A website should be available for browsing at http://localhost:8080

    Note: If an error occurs, that there are not sufficient rights, modify the file:

    %systemdrive%\Program Files (x86)\IIS Express\PHP\v7.1\runphp.cmd

    to add the localhost as in the following example:

    %appcmd% add site /name:WebSite1 /physicalPath:"%currentdir%" 
    /bindings:http/*:8080:localhost /apphostconfig:"%currentdir%\apphost.config"

  16. After the Debug is running and the IIS is running, open a browser and go to http://localhost:8080.

    The execution should stop to the breakpoint. Continue the execution and the PHP information will be displayed.

  17. Additionally, the Xdebug bookmarklets may be added from the phpstorm website to your favorites from https://www.jetbrains.com/phpstorm/marklets/.

Enjoy XDebug under IIS!

Points of Interest

Multiple articles on debugging with XDebug, but most of them under XAMPP or WAMP.

I just wanted something for IIS, good for other .NET enthusiasts like me.

History

  • June 5, 2017 - Initial version
  • June 6, 2017 - Added images again

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Self
Canada Canada
Software engineer with more than 10 years experience in the art of programming and data expression always enjoying a motivated environment within a mature and progressive organization that provides opportunities to express my expertise and abilities in the world of Information Technology.

Comments and Discussions

 
QuestionThanks a lot! Pin
Member 1204833721-Jan-20 16:02
Member 1204833721-Jan-20 16:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.