This article describes how to set up your tooling if you want a free and lightweight option for developing PHP projects on Windows (tested for PHP 8).
- Download PHP from http://windows.php.net/download/. I'm using the
VC18 x64 Non Thread Safe
version - Extract it to
c:\php
- Copy contents of
php.ini-production
tophp.ini
- Edit
php.ini
and uncommentextension_dir = “ext”
- Uncomment some basic extensions
extension=bz2
extension=curl
extension=fileinfo
extension=gd
extension=intl
extension=mbstring
extension=exif ; Must be after mbstring as it depends on it
extension=openssl
-
Go to
c:\php
-
SHIFT
+Right click
in the folder ->Open PowerShell window here
-
Run
./php -i
(alternatively, in case you receive'php' not recognized
, run./php -r "phpinfo();"
and press Enter)- In powershell you can use
.\php -i | clip.exe
to sent the output directly to clipboard.
- In powershell you can use
-
Copy the output
-
Paste it here https://xdebug.org/wizard.php and follow the instructions which basically say:
-
Click download
-
Extract it to
C:\php\ext
-
Open
c:\php\php.ini
and append the XDebug section to the end of the file (if it's already there, adjust it accordingly):[XDebug] ; for XDebug v 2.x.x zend_extension = php_xdebug-3.1.3-8.0-vs16-nts-x86_64.dll ; Use the name of the DLL you copied to ext folder xdebug.default_enable = 1 xdebug.scream = 1 xdebug.coverage_enable = 1 xdebug.profiler_enable = 0 xdebug.profiler_enable_trigger = 1 xdebug.profiler_output_dir = "C:\php\profiles" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_host=127.0.0.1 xdebug.remote_port = 9003
[XDebug]; for XDebug v3.x.x https://stackoverflow.com/questions/43783482/visual-studio-code-php-debugging-not-working/70351090#70351090 xdebug.mode = coverage ; or debug xdebug.start_with_request = yes zend_extension = "C:\php\ext\php_xdebug-3.2.2-8.2-vs16-x86_64.dll" ; Use the name of the DLL you copied to ext folder xdebug.stopOnEntry = true xdebug.profiler_enable = off xdebug.profiler_enable_trigger = Off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.output_dir ="c:\php\tmp" xdebug.show_local_vars=0 xdebug.remote_handler = "dbgp" xdebug.client_host = "127.0.0.1" xdebug.log = "C:\php\tmp\xdebug.txt" xdebug.client_port = 9003 xdebug.remote_cookie_expire_time = 36000
-
Add
c:\php
to your PATH environment variable -
Add key:
XDEBUG_CONFIG
with value:idekey=VSCODE
to your System Variables
See the differences for multiple XDebug configurations https://stackoverflow.com/a/70351090/3529135.
-
Download and install VS Code https://code.visualstudio.com/
-
Learn
CTRL
+SHIFT
+P
to run any command (aka Command Palette) -
Use the Command Palette shortcut and search for "Inst Ext"
-
Install Composer into your OS from https://getcomposer.org/doc/00-intro.md#installation-windows _ You might experience error during installation, validate the
php_xdebug-XYZ.dll
file name from error is the same as in theC:\php\ext
dir. Change name or config appropriately. . Install the following extensions: _ Composer _ You can also download it separately: https://getcomposer.org/download/ _ You must set composer.executablePath user setting as:"composer.executablePath": "C:\\ProgramData\\ComposerSetup\\bin\\composer.bat"
_ You will be unable to use this plugin unless you configure this setting before first use. _ Validate correct settings viaComposer: Validate
_ PHPUnit _ Can be installed also via Composer by runningcomposer global require phpunit/phpunit
_ PHP IntelliSense _ PHP Debug * XML Tools -
Use the Command Palette to "Open User Settings (JSON)"
-
Configure PHP-related settings
{ "php.executablePath": "C:\\php\\php.exe", "php.validate.executablePath": "C:\\php\\php.exe", "php.validate.enable": true, "php.validate.run": "onType", "phpunit.execPath": "C:\\Users\\<yourusername>\\AppData\\Roaming\\Composer\\vendor\\bin\\phpunit.bat", "phpunit.args": [] }
You're ready to start coding in PHP!
Part 2: Continue reading about debugging, unit testing, autoloading, bootstrapping...
More detailed resources that helped me assemble this tutorial: