- Installing XDEBUG for XAMPP with PHP in Windows.
- STEP 01
- STEP 02
- STEP 03
- STEP 04
- STEP 05
- STEP 06
- Things Need To Be Consider:
- Configure Xdebug
- Download Xdebug
- Integrate Xdebug with the PHP interpreter
- Configure Xdebug in PhpStorm
- Configure Xdebug for using in the On-Demand mode
- Configure Xdebug for using in the Just-In-Time mode
- Command-line scripts
- Web server debugging
- Configure Xdebug running in a Docker container
- Installing and Configuring XAMPP with PhpStorm IDE
- Prerequisites
- Choosing the right XAMPP edition
- XAMPP for Windows
- Downloading the XAMPP installer
- Running the XAMPP installer
- XAMPP installation wizard
- XAMPP Control Panel
- Starting and stopping servers
- Starting a server as a Windows Service
- Integrating XAMPP with the IDE
- Integrating the PHP executable
- Integrating the debugger
- Integrating the Apache server
- Integrating the MySQL server
Installing XDEBUG for XAMPP with PHP in Windows.
Xdebug helps to set the breakpoints in our codes and easily we can see all define variables and even change them while running the code. In this blog post, I will demonstrate how to set up xdebug for xampp with php.
STEP 01
We have to download the xdebug https://xdebug.org/download.php. You have to choose the right version for your installed PHP version.
here, I’m listing some latest xdebug version’s links for you,
STEP 02
Then, copy the installed xdebug file[ php_xdebug-2.7.0–7.3-vc15.dll —this version file for my PHP verson] and paste it in to C:\xampp\php\ext
STEP 03
Then, we need to open the file C:\xampp\php\php.ini with a code editor and need to make the following
In php.ini file we should disable output_buffering=off
STEP 04
And, scroll down the bottom of the php.ini file and copy and paste the following code.
STEP 05
Restart your Apache server.
STEP 06
If everything went well then you will be able to set up a breakpoint as follow in your code and can see the xdebug in action in the PHPSTORM console
Things Need To Be Consider:
Sometimes if you still have an error check your PHP ini that, the file have an additional zend_extension code, u need to comment or delete them.
Configure Xdebug
Download Xdebug
Download the Xdebug extension compatible with your PHP version and install it as described in the installation guide.
Xdebug 3 brings performance improvements, simplified configuration, and PHP 8 support. To learn more on upgrading to Xdebug 3, see the Upgrade guide.
If you are using an AMP package, the Xdebug extension may be already installed. Refer to the instructions specific for your package.
Integrate Xdebug with the PHP interpreter
Open the active php.ini file in the editor:
In the Settings/Preferences dialog Ctrl+Alt+S , click PHP .
On the PHP page that opens, click next to the CLI Interpreter field.
In the CLI Interpreters dialog that opens, the Configuration file read-only field shows the path to the active php.ini file. Click Open in Editor .
To disable the Zend Debugger and Zend Optimizer tools, which block Xdebug, remove or comment out the following lines in the php.ini file:
To enable Xdebug, locate or create the [xdebug] section in the php.ini file and update it as follows:
» xdebug.remote_enable=1 xdebug.remote_host=127.0.0.1 xdebug.remote_port=»
In PHP 5.3 and later, you need to use only zend_extension , not zend_extension_ts , zend_extension_debug , or extension .
To enable multi-user debugging via Xdebug proxies, locate the xdebug.idekey setting and assign it a value of your choice. This value will be used to register your IDE on Xdebug proxy servers.
Save and close the php.ini file.
Verify Xdebug installation by doing any of the following:
In the command line, run the following command:
The output should list Xdebug among the installed extensions:
Create a php file containing the following code:
Configure Xdebug in PhpStorm
In the Settings/Preferences dialog Ctrl+Alt+S , select PHP .
Check the Xdebug installation associated with the selected PHP interpreter:
On the PHP page, choose the relevant PHP installation from the CLI Interpreter list and click next to the field. The list shows all the PHP installations available in PhpStorm, see Configure local PHP interpreters and Configure remote PHP interpreters.
The version of the selected PHP installation.
The name and version of the debugging engine associated with the selected PHP installation (Xdebug or Zend Debugger). If no debugger is configured, PhpStorm shows the corresponding message:
Alternatively, open the Installation Wizard, paste the output of the phpinfo() , and click Analyze my phpinfo() output . Learn more about checking the Xdebug installation in Validate the Configuration of a Debugging Engine.
Define the Xdebug behaviour. Click Debug under the PHP node. On the Debug page that opens, specify the following settings in the Xdebug area:
In the Debug port field, appoint the port through which the tool will communicate with PhpStorm.
This must be the same port number as specified in the php.ini file:
By default, Xdebug 2 listens on port 9000 . For Xdebug 3, the default port has changed from 9000 to 9003 . You can specify several ports by separating them with a comma. By default, the Debug port value is set to 9001,9003 to have PhpStorm listen on both ports simultaneously.
To have PhpStorm accept any incoming connections from Xdebug engine through the port specified in the Debug port field, select the Can accept external connections checkbox.
Select the Force break at first line when no path mapping specified checkbox to have the debugger stop as soon as it reaches and opens a file that is not mapped to any file in the project on the Servers page. The debugger stops at the first line of this file and Examine/update variables shows the following error message: Cannot find a local copy of the file on server
and a link Click to set up mappings . Click the link to open the Resolve Path Mappings Problem dialog and map the problem file to its local copy.
When this checkbox cleared, the debugger does not stop upon reaching and opening an unmapped file, the file is just processed, and no error messages are displayed.
Select the Force break at first line when a script is outside the project checkbox to have the debugger stop at the first line as soon as it reaches and opens a file outside the current project. With this checkbox cleared, the debugger continues upon opening a file outside the current project.
In the External connections area, specify how you want PhpStorm to treat connections received from hosts and through ports that are not registered as deployment server configurations.
Ignore external connections through unregistered server configurations : Select this checkbox to have PhpStorm ignore connections received from hosts and through ports that are not registered as deployment server configurations. When this checkbox is selected, PhpStorm does not attempt to create a deployment server configuration automatically.
Break at first line in PHP scripts : Select this checkbox to have the debugger stop as soon as connection between it and PhpStorm is established (instead of running automatically until the first breakpoint is reached). Alternatively turn on the Run | Break at first line in PHP scripts option from the main menu.
Max. simultaneous connections Use this spin box to limit the number of external connections that can be processed simultaneously.
By default, PhpStorm only listens for incoming IPv4 connections. To enable IPv6 support, you need to make adjustments in PhpStorm JVM options:
Select Help | Edit Custom VM Options from the main menu.
In the .vmoptions file that opens, delete the -Djava.net.preferIPv4Stack=true line.
Configure Xdebug for using in the On-Demand mode
PhpStorm supports the On-Demand mode, where you can disable Xdebug for your global PHP installation and have it enabled automatically on demand only when you are debugging your command-line scripts or when you need code coverage reports. This lets your command line scripts (including Composer and unit tests) run much faster.
Disable Xdebug for command-line scripts:
In the Settings/Preferences dialog Ctrl+Alt+S , go to PHP .
From the PHP executable list, choose the relevant PHP interpreter and click next to it. In the CLI Interpreters dialog that opens, click the Open in Editor link next to the Configuration file:
file. Close all the dialogs and switch to the tab where the php.ini file is opened.
In the php.ini file, find the [xdebug] section and comment the following line in it by adding ; in preposition:
Open the CLI Interpreters dialog and click next to the PHP executable field. PhpStorm informs you that debugger is not installed:
To enable PhpStorm to activate Xdebug when it is necessary, specify the path to it in the Debugger extension field, in the Additional area. Type the path manually or click and select the location in the dialog that opens.
Configure Xdebug for using in the Just-In-Time mode
PhpStorm supports the use of Xdebug in the Just-In-Time (JIT) mode so it is not attached to your code all the time but connects to PhpStorm only when an error occurs or an exception is thrown. Depending on the Xdebug version used, this operation mode is toggled through the following settings:
Xdebug 2 uses the xdebug .remote_mode setting, which has to be set to jit .
Xdebug 3 uses the xdebug.start_upon_error setting, which has to be set to yes .
The mode is available both for debugging command-line scripts and for web server debugging.
Depending on whether you are going to debug command-line scripts or use a Web server, use one of the scenarios below.
Command-line scripts
For debugging command-line scripts, specify the custom -dxdebug.remote_mode=jit (for Xdebug 2) or -dxdebug.start_upon_error=yes (for Xdebug 3) directive as an additional configuration option :
In the Settings/Preferences dialog Ctrl+Alt+S , navigate to PHP .
From the PHP executable list, choose the relevant PHP interpreter and click next to it.
In the CLI Interpreters dialog that opens, click next to the Configuration options field in the Additional area.
In the Configuration Options dialog that opens, click to add a new entry.
For Xdebug 2, type xdebug.remote_mode in the Configuration directive field and jit in the Value field.
For Xdebug 3, type xdebug.start_upon_error in the Configuration directive field and yes in the Value field.
When you click OK , you return to the CLI Interpreters dialog where the Configuration options field shows -dxdebug.remote_mode=jit (for Xdebug 2) or -dxdebug.start_upon_error=yes (for Xdebug 3).
Web server debugging
From the main menu, choose Run | Web Server Debug Validation .
In the Validate Remote Environment that opens, choose the Web server to validate the debugger on.
Choose Local Web Server or Shared Folder to check a debugger associated with a local Web server.
Path to Create Validation Script : In this field, specify the absolute path to the folder under the server document root where the validation script will be created. For Web servers of the type Inplace , the folder is under the project root.
The folder must be accessible through http .
URL to Validation Script : In this field, type the URL address of the folder where the validation script will be created. If the project root is mapped to a folder accessible through http , you can specify the project root or any other folder under it.
Choose Remote Web Server to check a debugger associated with a remote server.
Path to Create Validation Script : In this field, specify the absolute path to the folder under the server document root where the validation script will be created. The folder must be accessible through http .
Deployment Server : In this field, specify the server access configuration of the type Local Server or Remote Server to access the target environment. For details, see Configure synchronization with a Web server.
Choose a configuration from the list or click Browse in the Deployment dialog.
Click Validate to have PhpStorm create a validation script, deploy it to the target remote environment, and run it there.
Open the php.ini file which is reported as loaded and associated with Xdebug.
In the php.ini file, find the [xdebug] section.
Change the value of the xdebug.remote_mode from the default req to jit .
Change the value of the xdebug.start_upon_error from the default default to yes .
Configure Xdebug running in a Docker container
To configure Xdebug running in a Docker container, provide the Xdebug-specific parameters in the Dockerfile , for example:
Installing and Configuring XAMPP with PhpStorm IDE
This tutorial will walk you through choosing and downloading the appropriate edition of XAMPP, downloading and installing the package, starting its components, and integrating them with the PhpStorm IDE.
XAMPP is a cross-platform package consisting of an Apache HTTP server, MySQL database, PHP interpreter, and Perl interpreter. The word «XAMPP» is an acronym, where «X» stands for «cross», meaning «cross-platform», and the other letters stand for the package components.
XAMPP is a reliable and fast way to set up environment for PHP programming. It provides all the components required for developing, running, debugging, and unit testing of PHP applications. XAMPP is a good alternative to installing and configuring a Web server, a PHP engine, a database server, and a debug engine separately. All you need to do to start developing is download XAMPP, run XAMPP installer.exe, and start the components using the XAMPP control panel.
Prerequisites
Before starting, the following tools should be available on your system:
Choosing the right XAMPP edition
From the Apache friends, we can download and install the XAMPP edition which matches our platform and operating system. The following versions are available:
- XAMPP for Windows
- The latest version compatible with Windows NT is XAMPP 1.7.2.
- The earliest version compatible with Windows Vista is XAMPP 1.7.2.
- The earliest version compatible with Windows Server 2008 R2, Windows Server 2012, Windows 7, and Windows 8 is XAMPP 1.7.5.
- XAMPP for Linux
- XAMPP for Mac OS X
- XAMPP for Solaris works only on SPARC systems and does not run on x86 processors.
XAMPP for Windows
In this tutorial, we will use the latest XAMPP 1.8.2 version.
Downloading the XAMPP installer
From the XAMPP downloads page, we can find a list of components that are included in the package. In the Download section, click the XAMPP link to display a list of downloads available.
There are a number of download flavors available:
- The installer, which sets up the XAMPP folder structure
- The ZIP or 7zip files, which contain all required binaries and configuration but don’t come with a wizard to get started
We will be using the installer for now. If you do want to make use of the ZIP or 7zip files, please run the setup_xampp.bat file once the archive is extracted.
Once the download of the installer is completed, we can run it.
Running the XAMPP installer
Once the XAMPP installer is asked, we may be prompted with the following notification:
This warning can be ignored in most situations, please check the http://bitnami.com/antivirus website for more information.
Depending on our operating system and settings, we may also see the following message:
If you have UAC enabled on your Windows Vista, Windows 7 or Windows 8 machine, it is recommended not to install XAMPP into the Program Files folder.
XAMPP installation wizard
The XAMPP installation wizard is pretty straightforward. Using the Next button, we can navigate through all steps in the installation.
One of the first steps where input is required is the Select Components step. In here, we have to specify which components we want to install with XAMPP:
Depending on our plans, we can add/remove certain components here. To work with PHP, we typically require Apache, MySQL (if we want to work with a database) and PHP. Other components are utilities which may come in handy, such as the Fake Sendmail which mimics a mail server that can be used during development.
Next, we have to specify the installation folder. We will be using the c:\xampp folder.
After clicking the Next button again, all required components are extracted to the specified folder.
After extracting and installing all files, we can launch the XAMPP control panel. Let’s keep the checkbox ticked and use the Finish button to complete installation.
XAMPP Control Panel
After installation, we can use the XAMPP Control Panel to perform several actions such as starting / stopping servers and changing configurations.
Starting and stopping servers
To start a specific server, click the Start button next to them. To stop a running server, we can use the Stop button. Let’s start the Apache server by clicking the Start button.
Depending on your system configuration, starting Apache may fail. If that is the case, verify that no other software is listening on TCP ports 80 and 443. Other web servers such as IIS may be using these ports, as well as Skype or other software. Close these other programs and try again, or modify the Apache configuration to listen on different TCP ports.
Starting a server as a Windows Service
By default, none of the servers such as Apache or MySQL are installed as Windows Service. This means that whenever we want to make use of these servers, we have to manually start them through the XAMPP Control Panel.
If we want to run specific servers as a Windows Service so they start whenever Windows is started, we can open the XAMPP Control Panel as an administrator. Next, stop the server using the Stop button.
Once stopped, we can click the X next to the server we want to install as a Windows Service. For example, we can install Apache as a Windows Service. After clicking the X, we have to confirm installation by clicking Yes.
Once the installation succeeds, the server will display a green checkmark, indicating the server is now running as a Windows Service.
Note that we can still start and stop our servers using the button in the XAMPP Control Panel.
Integrating XAMPP with the IDE
Now that we have installed XAMPP and launched its components, we need to tell our IDE where these components are stored and how they are configured.
Integrating the PHP executable
Let’s start by registering the PHP executable from XAMPP in PhpStorm. When in a PHP project, we can do this using the File | Settings menu (Ctrl+Shift+S or Cmd+Shift+S on Mac), navigating to the Project Settings | PHP.
With IntelliJ IDEA and PhpStorm, we can have several separate PHP interpreters registered in the IDE, depending on the PHP version and/or PHP configuration needed for the project. All currently registered installations of PHP interpreters are displayed in the Interpreter drop-down list:
We can add the one we’ve installed with XAMPP by clicking the Browse button (…). This will bring up the Interpreters dialog box.
- In the left-hand pane, click the Add button on the toolbar.
- In the Name text box, type the name to identify the current installation, for example PHP from XAMPP.
- In the PHP Home text box, specify the folder where the PHP executable file php.exe is stored. Since we have installed XAMPP to c:\xampp the PHP home directory will be C:\xampp\php. We can enter this path manually or use the Browse button to find the path on our system.
- The IDE checks whether the specified folder contains a PHP executable file, detects the PHP version, and displays it in the PHP Info read-only field.
We can now save these settings and select the newly added PHP interpreter for our project:
Our IntelliJ IDEA or PhpStorm IDE will now make use of the PHP installation that was bundled with XAMPP.
Integrating the debugger
PhpStorm offers a powerful debugger in which breakpoints can be set and variables can be inspected at runtime. For more information on using PhpStorm’s debugger, have a look at any of the following articles:
Integrating the Apache server
Interaction between IntelliJ IDEA or PhpStorm with Web, FTP, and other servers is supported through the Remote Hosts Access plugin, which is enabled by default for IntelliJ IDEA and PhpStorm. The IDE accesses servers using connection settings specified in the registered server access configurations. These configurations are created and managed in the Project Settings | Deployment page of the Settings dialog box.
Choose File | Settings on the main menu again to open the Settings. Click Deployment under the Project Settings node to go to the Deployment page.
From the toolbar, click the Add button to add a new server. From the Add Server dialog, we can specify a name for our XAMPP server and select the deployment type. For XAMPP’s Apache server, select the Local or mounted folder type.
After clicking OK, we can specify the folder to Apache’s web root (C:\xampp\htdocs) and the URL to the web server, http://localhost. Note that these settings may be different depending on how you have configured the XAMPP Apache server through the C:\xampp\apache\conf\httpd.conf configuration file.
Using the Open button, we can verify settings are ok. Once done, we should be seeing the XAMPP homepage.
Integrating the MySQL server
IntelliJ IDEA and PhpStorm provide us the possibility to connect to the XAMPP MySQL database server using the Database plugin (installed and enabled by default). First of all, make sure the MySQL server is running from the XAMPP Control Panel.
Next, from the right-hand side of our IDE, we can open the database tool window.
Opening the database pane, we can create a new connection or Data Source by using the context menu. We’ll have to specify the JDBC database driver to be used to connect to our database. For MySQL, we can use the MySQL Connector driver available in the list of drivers. PhpStorm doesn’t ship these drivers but a simple click (on Click here) fetches the correct JDBC driver from the Internet.
Next, we’ll have to enter our connection details. As the JDBC driver class, select the com.mysql.jdbc.Driver driver. The Database URL should be a connection string to our MySQL Database, for example jdbc:mysql://localhost:3306/ or jdbc:mysql://localhost:3306/foodb to connect to the foodb database. We can also specify the username and password for MySQL, root and a blank password for a standard XAMPP installation. Note it is recommended to change the default MySQL username and password after the XAMPP installation. This can be done through http://localhost/security/xamppsecurity.php.
When using UTF-8 or unicode characters in the username, password or database name, two additional parameters must be added to the connection string: characterEncoding and useUnicode. An example connection string would be jdbc:mysql://localhost:8889?characterEncoding=utf8&useUnicode=true. It may also be required to select a different JDBC driver from the list, com.mysql.jdbc.NonRegisteringDriver.
Using the Test Connection button, we can verify the settings and make sure PhpStorm can connect to MySQL.
We can now create tables, run queries, update data and so on. See this blog post for more information.