Debugger Setup in CodeIgniter, VS Code for Windows
To set up debugging in CodeIgniter with VS Code on Windows, follow these steps:
Table of Contents
1. Install Xdebug
-
Download the appropriate Xdebug DLL file for your PHP version and architecture from the Xdebug website.
-
Place the downloaded DLL file in the PHP extension directory (e.g.,
C:\php\ext
).For Example WampServer as following-
To place the downloaded DLL file in the PHP extension directory for WampServer, follow these steps:
-
Locate your WampServer installation directory. By default, it is installed in
C:\wamp
orC:\wamp64
. -
Inside the WampServer installation directory, you'll find a subdirectory named
bin
. Open it. -
Inside the
bin
directory, you'll find another subdirectory namedphp
. Open it. -
Inside the
php
directory, you'll find a subdirectory namedext
. This is the directory where you should place the downloaded DLL file. -
Copy the downloaded Xdebug DLL file and paste it into the
ext
directory. -
Once the DLL file is placed in the
ext
directory, you need to configure it in WampServer. -
Right-click on the WampServer icon in the system tray and select "PHP" -> "php.ini".
-
This will open the
php.ini
file in a text editor. Look for the[XDebug]
section. -
Uncomment the line
zend_extension = <path to the Xdebug DLL file>
by removing the semicolon (;) at the beginning of the line. -
In open
php.ini
file and add the following lines at the end:[Xdebug]
zend_extension = <path to the Xdebug DLL file> // For Example- zend_extension="c:/wamp64/bin/php/php8.0.26/ext/php_xdebug-3.2.1-8.0-vs16-x86_64.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000Dummy Example of Finalphp.ini
File after xdebug setup; XDEBUG Extension [xdebug] zend_extension="c:/wamp64/bin/php/php8.0.26/ext/php_xdebug-3.2.1-8.0-vs16-x86_64.dll"
;xdebug.mode allowed are : off develop coverage debug gcstats profile trace
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0
xdebug.log="c:/wamp64/logs/xdebug.log"
;xdebug.log_level : 0 Criticals, 1 Connection, 3 Warnings, 5 Communication, 7 Information, 10 Debug Breakpoint
xdebug.log_level=7
xdebug.profiler_output_name=trace.%H.%t.%p.cgrind
xdebug.use_compression=false
-
Save the changes to the
php.ini
file and close the text editor. -
Restart the WampServer services to apply the changes. You can do this by right-clicking on the WampServer icon and selecting "Restart All Services".
Now Xdebug should be installed and configured in WampServer. You can proceed with the remaining steps to configure Visual Studio Code and start debugging your CodeIgniter application.
-
2. Configure Xdebug
- In your CodeIgniter project, open the
application/config/autoload.php
file. - Uncomment the
$autoload['libraries']
line and add'database'
to the array. It should look like this:$autoload['libraries'] = array('database');
- Open the
application/config/config.php
file. - Set
$config['base_url']
to your CodeIgniter project's base URL (e.g.,'http://localhost/my_project/'
). - Set
$config['index_page']
to an empty string (''
). - Save the changes.
3. Configure Visual Studio Code
- Install the PHP Debug extension in Visual Studio Code.
- Open your project in Visual Studio Code.
- Create a new file called
.vscode/launch.json
in the root directory of your project. - Add the following configuration to
launch.json
:{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000
}
]
}
4. Set Breakpoints
- Open the PHP file in your CodeIgniter project where you want to set breakpoints.
- Click on the left gutter of the line number where you want to set a breakpoint. A red dot should appear, indicating the breakpoint.
5. Start Debugging
- In Visual Studio Code, press
F5
or go to the "Run" menu and select "Start Debugging". - Open your browser and navigate to the page you want to debug in CodeIgniter.
- Visual Studio Code should now stop at the breakpoints you set, allowing you to step through the code and inspect variables.
That's it! You have set up debugging in CodeIgniter with VS Code on Windows. Now you can debug your CodeIgniter application and examine its behavior during runtime.
Note: Ensure that your Xdebug and PHP versions are compatible.