Edit PHP.INI File for XDebug: Difference between revisions

From Joomla! Documentation

Cmb (talk | contribs)
Corrected the Linux 'Loaded Configuration File' text.
Cmb (talk | contribs)
URL corrections. Other text editing.
 
Line 1: Line 1:
=Edit PHP.INI File for XDebug=
==For Windows==
==For Windows==
Starting with version 1.7, XAMPP includes the XDebug PHP debugger, but it needs to be configured for use. To do that, we will edit the "php.ini" file to configure XDebug. The "Loaded Configuration File" in the screenshot above tells you what "php.ini" file is being used. For Windows, this is normally "c:\xampp\apache\bin\php.ini".
Starting with version 1.7, XAMPP includes the XDebug PHP debugger, but it needs to be configured for use. To do that, we will edit the ''php.ini'' file to configure XDebug. The ''Loaded Configuration File'' tells you which ''php.ini'' file is being used. For Windows, this is normally ''c:\xampp\apache\bin\php.ini''.


<blockquote>''Important note for Windows 7 & Vista users: As of August 2013 (XAMPP version 1.8.2), the file "php_xdebug.dll" that is included with XAMPP now works with Windows 7 & Vista. In some earlier versions of XAMPP, the distributed version of XDebug did not work correctly. The symptom of this earlier problem was that the Apache server would stop if this version of XDebug is loaded. To check that you are running the correct version of XDebug on your system, [http://xdebug.org/wizard.php follow these instructions] on the XDebug site.''
<blockquote>Important note for Windows 7 & Vista users: As of August 2013 (XAMPP version 1.8.2), the file ''php_xdebug.dll'' that is included with XAMPP now works with Windows 7 & Vista. In some earlier versions of XAMPP, the distributed version of XDebug did not work correctly. The symptom of this earlier problem was that the Apache server would stop if this version of XDebug is loaded. To check that you are running the correct version of XDebug on your system, [https://xdebug.org/wizard follow these instructions] on the XDebug site.
</blockquote>
</blockquote>


We need to edit this file to configure XDebug as follows:
We need to edit this file to configure XDebug as follows:
# Find the line "implicit_flush" and set it as follows: <syntaxhighlight lang="ini">implicit_flush = On</syntaxhighlight>
# Find the line ''implicit_flush'' and set it as follows: <syntaxhighlight lang="ini">implicit_flush = On</syntaxhighlight>
# Find the section called "[Zend]" and comment out all of the lines by putting a semi-colon (";") at the start of each line.
# Find the section called ''[Zend]'' and comment out all of the lines by putting a semicolon (;) at the start of each line.
# Find the line: zend_extension = "c:\xampp\php\ext\php_xdebug.dll" and uncomment it out.
# Find the line: ''zend_extension = "c:\xampp\php\ext\php_xdebug.dll"'' and uncomment it.
# Find the "[XDebug]" section and uncomment out all of the lines (except for the first comment line). For Windows, it should look like the example below:<syntaxhighlight lang="ini">
# Find the ''[XDebug]'' section and uncomment all of the lines (except for the first comment line). For Windows, it should look like the example below:
<syntaxhighlight lang="ini">
[XDebug]
[XDebug]
;; Only Zend OR (!) XDebug
; Only Zend OR (!) XDebug
zend_extension_ts="C:\xampp\php\ext\php_xdebug.dll"
zend_extension_ts="C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=true
xdebug.remote_enable=true
Line 21: Line 20:
</syntaxhighlight>
</syntaxhighlight>


You do not need to enable XDebug profiling to use XDebug to debug Joomla code. Profiling allows you to find performance bottlenecks in your PHP code. However, enabling profiling with XDebug can slow down your system substantially, so it is not recommended unless you need it. To enable XDebug profiling, add these entries to your php.ini file.
You do not need to enable XDebug profiling to use XDebug to debug Joomla code. Profiling allows you to find performance bottlenecks in your PHP code. However, enabling profiling with XDebug can slow down your system substantially, so it is not recommended unless you need it. To enable XDebug profiling, add these entries to your ''php.ini'' file.
<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
xdebug.profiler_enable=1
xdebug.profiler_enable=1
Line 32: Line 31:
</syntaxhighlight>
</syntaxhighlight>


For PHP version 5.3 or later, the "_ts" has been dropped, so the first line will read
For PHP version 5.3 and later, the ''_ts'' has been dropped, so the first line will read:
<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
</syntaxhighlight>
</syntaxhighlight>


In XAMPP 1.7.3 on Windows 7 (currently not verified/tested with prior Windows versions), XDebug may not work correctly if the path to the DLL file is in quotes. In this case, the line should be
In XAMPP 1.7.3 on Windows 7, XDebug may not work correctly if the path to the DLL file is in quotes. In this case, the line should be
<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
zend_extension = C:\xampp\php\ext\php_xdebug-2.1.0-5.3-vc6.dll
zend_extension = C:\xampp\php\ext\php_xdebug-2.1.0-5.3-vc6.dll
Line 43: Line 42:


==For Linux==
==For Linux==
We will edit the ''php.ini'' file to configure XDebug. The ''Loaded Configuration File'' in your ''phpinfo'' display tells you what ''php.ini'' file is being used. For Linux, it will be something like ''/etc/php/7.2/apache2/php.ini''. (The PHP configuration is available in the Administrator of your Website: ''Administrator > System > System Information > PHP Information tab''.)
We will edit the ''php.ini'' file to configure XDebug. The ''Loaded Configuration File'' in your ''phpinfo'' display tells you what ''php.ini'' file is being used. For Linux, it will be something like ''/etc/php/7.2/apache2/php.ini''. (The PHP configuration is available in the Administrator of your website: {{rarr|Administrator,System,System Information,PHP Information}} tab''.)


Edit this file to configure XDebug as follows:
Edit this file to configure XDebug as follows:
Line 61: Line 60:
;xDebug Configuration ends </syntaxhighlight>
;xDebug Configuration ends </syntaxhighlight>


'''If using php5-xdebug on Ubuntu'''
===If Using ''php5-xdebug'' on Ubuntu===
The xDebug Configuration detailed above can be appended to:
The xDebug Configuration detailed above can be appended to:
<syntaxhighlight lang="ini">/etc/php5/apache2/conf.d/xdebug.ini </syntaxhighlight>
<syntaxhighlight lang="ini">/etc/php5/apache2/conf.d/xdebug.ini </syntaxhighlight>
Line 72: Line 71:
xdebug.remote_handler="dbgp"</syntaxhighlight>
xdebug.remote_handler="dbgp"</syntaxhighlight>


'''Tip for users with LAN or remote servers:'''
===Tip for Users with LAN or Remote Servers===
<syntaxhighlight lang="ini">xdebug.remote_host="localhost"</syntaxhighlight>
<syntaxhighlight lang="ini">xdebug.remote_host="localhost"</syntaxhighlight>
Should be set to the IP address of your Eclipse workstation [LAN users] or your public IP. For example:
Should be set to the IP address of your Eclipse workstation [LAN users] or your public IP. For example:
Line 78: Line 77:


==For Mac OS X==
==For Mac OS X==
XAMPP for Mac OS X includes the XDebug PHP debugger, but it needs to be added to the "php.ini" file so that XDebug runs when Apache is started. To do this, open up the php.ini file, located at "/Applications/XAMPP/xamppfiles/etc/php.ini".  
XAMPP for Mac OS X includes the XDebug PHP debugger, but it needs to be added to the ''php.ini'' file so that XDebug runs when Apache is started. To do this, open up the ''php.ini'' file, located at ''/Applications/XAMPP/xamppfiles/etc/php.ini''.


We need to edit this file to configure XDebug as follows:
Edit this file to configure XDebug:
# Find the line "implicit_flush" and set it as follows: <syntaxhighlight lang="ini">implicit_flush = On</syntaxhighlight>
# Find the line ''implicit_flush'' and set it as follows: <syntaxhighlight lang="ini">implicit_flush = On</syntaxhighlight>
# Add the following lines at the end:<syntaxhighlight lang="ini">
# Add the following lines at the end:
<syntaxhighlight lang="ini">
;xDebug Configuration starts
;xDebug Configuration starts


Line 97: Line 97:
</syntaxhighlight>
</syntaxhighlight>


Be sure to navigate to the directory where you targeted the extension and check to see that the file path is correct. The folders in your XAMPP installation may be named differently.
Be sure to navigate to the directory where you targeted the extension and verify that the file path is correct. The folders in your XAMPP installation may be named differently.


The current (as of Sept 2010) version of the XAMPP binary for OS X contains the 2.0.4 version of Xdebug which will not let you see the variable data from included files when running xdebug. You can download a newer version from http://code.activestate.com/komodo/remotedebugging/. Unzip and copy one of the xdebug.so files to /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626. As of Oct 2, 2010 this binary is still out of date (2.1beta3 rather than the stable 2.1) but it will show the variable data appropriately.
The current (as of Sept 2010) version of the XAMPP binary for OS X contains the 2.0.4 version of XDebug which will not let you see the variable data from included files when running XDebug. You can download a newer version from the [https://code.activestate.com/komodo/remotedebugging/ ActiveState website]. Unzip and copy one of the ''xdebug.so'' files to ''/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626''.


==Test XDebug Installation==
==Test the XDebug Installation==
Now, we need to check that XDebug is installed correctly. To do this, we need to re-start XAMPP. In Windows, we can just browse to the "c:\xampp" folder in Windows Explorer and double-click the program "xampp-control.exe" to open the application shown below.
Now we need to verify that XDebug is installed correctly. Restart XAMPP. In Windows, we can just browse to the ''c:\xampp'' folder in Windows Explorer and double-click the program ''xampp-control.exe'' to open the application shown below.


[[Image:Xampp-control.png]]
[[Image:Xampp-control.png]]


Press the "Stop" button for "Apache". The button with then read "Start". Press "Start" for Apache and wait a few seconds and the green "Running" message will again display. Then press "Exit" to close the application.
Press the ''Stop'' button for ''Apache''. The button with then read ''Start''. Press ''Start'' for Apache and wait a few seconds and the green ''Running'' message will again display. Then press ''Exit'' to close the application.
 
In Windows, if you get "ERROR: MySQL service not started [-1]", you may be able to correct this by going to c:\xampp\mysql and running mysql_uninstallservice.bat followed by mysql_installservice.bat.


In Linux, to restart XAMPP execute the command
In Windows, if you get ''ERROR: MySQL service not started [-1]'', you may be able to correct this by going to ''c:\xampp\mysql'' and running ''mysql_uninstallservice.bat'' followed by ''mysql_installservice.bat''.


In Linux, to restart LAMPP execute the command:
<syntaxhighlight lang="shell">
<syntaxhighlight lang="shell">
  sudo /opt/lampp/lampp restart
  sudo /opt/lampp/lampp restart
</syntaxhighlight>
</syntaxhighlight>


In Mac, open the "XAMPP Control" application, stop, and then start the Apache service again.
In Mac, open the ''XAMPP Control'' application, stop, and then start the Apache service.


Once XAMPP has been restarted, open a browser and navigate to "http://localhost" to display the XAMPP welcome message (if you set XAMPP to listen to another port, you must append the port to the url; e.g.:"http://localhost:8080/"). Press the "phpinfo()" link again to display the PHP information screen. Scroll down to the lower part of the screen. You should see a section for "XDebug" as shown below.
Once XAMPP has been restarted, open a browser and navigate to http://localhost to display the XAMPP welcome message. (If you set XAMPP to listen to another port, you must append the port to the URL. For example: http://localhost:8080/). Press the ''phpinfo()'' link again to display the PHP information screen. Scroll down to the lower part of the screen. You should see a section for ''XDebug'' as shown below.


[[Image:Phpinfo_xdebug.png]]
[[Image:Phpinfo_xdebug.png]]


Look at the settings you entered in the "php.ini" file above. You should see these same settings in the xdebug display, as shown below.
Look at the settings you entered in the ''php.ini'' file above. You should see these same settings in the XDebug display, as shown below.


[[Image:Xdebug settings.png]]
[[Image:Xdebug settings.png]]

Latest revision as of 20:57, 29 June 2023

For Windows

Starting with version 1.7, XAMPP includes the XDebug PHP debugger, but it needs to be configured for use. To do that, we will edit the php.ini file to configure XDebug. The Loaded Configuration File tells you which php.ini file is being used. For Windows, this is normally c:\xampp\apache\bin\php.ini.

Important note for Windows 7 & Vista users: As of August 2013 (XAMPP version 1.8.2), the file php_xdebug.dll that is included with XAMPP now works with Windows 7 & Vista. In some earlier versions of XAMPP, the distributed version of XDebug did not work correctly. The symptom of this earlier problem was that the Apache server would stop if this version of XDebug is loaded. To check that you are running the correct version of XDebug on your system, follow these instructions on the XDebug site.

We need to edit this file to configure XDebug as follows:

  1. Find the line implicit_flush and set it as follows:
    implicit_flush = On
    
  2. Find the section called [Zend] and comment out all of the lines by putting a semicolon (;) at the start of each line.
  3. Find the line: zend_extension = "c:\xampp\php\ext\php_xdebug.dll" and uncomment it.
  4. Find the [XDebug] section and uncomment all of the lines (except for the first comment line). For Windows, it should look like the example below:
[XDebug]
; Only Zend OR (!) XDebug
zend_extension_ts="C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=true
xdebug.remote_host=localhost
xdebug.remote_port=10000
xdebug.remote_handler=dbgp

You do not need to enable XDebug profiling to use XDebug to debug Joomla code. Profiling allows you to find performance bottlenecks in your PHP code. However, enabling profiling with XDebug can slow down your system substantially, so it is not recommended unless you need it. To enable XDebug profiling, add these entries to your php.ini file.

xdebug.profiler_enable=1
xdebug.profiler_output_dir="C:\xampp\tmp"

For Windows 7 & Vista, you will use the file downloaded from the XDebug site. So the first line will be

zend_extension_ts="C:\xampp\php\ext\php_xdebug-2.0.0-5.2.2.dll"

For PHP version 5.3 and later, the _ts has been dropped, so the first line will read:

zend_extension="C:\xampp\php\ext\php_xdebug.dll"

In XAMPP 1.7.3 on Windows 7, XDebug may not work correctly if the path to the DLL file is in quotes. In this case, the line should be

zend_extension = C:\xampp\php\ext\php_xdebug-2.1.0-5.3-vc6.dll

For Linux

We will edit the php.ini file to configure XDebug. The Loaded Configuration File in your phpinfo display tells you what php.ini file is being used. For Linux, it will be something like /etc/php/7.2/apache2/php.ini. (The PHP configuration is available in the Administrator of your website: Administrator  System  System Information  PHP Information tab.)

Edit this file to configure XDebug as follows:

  1. Find the line implicit_flush and set it as follows:
    implicit_flush = On
    
  2. Add the following lines at the end:
    ;xDebug Configuration starts
    
    zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
    
    xdebug.profiler_output_dir = "/tmp/xdebug/"
    xdebug.profiler_enable = On
    xdebug.remote_enable=On
    xdebug.remote_host="localhost"
    xdebug.remote_port=10000
    xdebug.remote_handler="dbgp"
    
    ;xDebug Configuration ends
    

If Using php5-xdebug on Ubuntu

The xDebug Configuration detailed above can be appended to:

/etc/php5/apache2/conf.d/xdebug.ini

It should already contain the zend_extension variable and only needs the following variables added:

xdebug.profiler_enable = On
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=10000
xdebug.remote_handler="dbgp"

Tip for Users with LAN or Remote Servers

xdebug.remote_host="localhost"

Should be set to the IP address of your Eclipse workstation [LAN users] or your public IP. For example:

xdebug.remote_host=192.168.0.199

For Mac OS X

XAMPP for Mac OS X includes the XDebug PHP debugger, but it needs to be added to the php.ini file so that XDebug runs when Apache is started. To do this, open up the php.ini file, located at /Applications/XAMPP/xamppfiles/etc/php.ini.

Edit this file to configure XDebug:

  1. Find the line implicit_flush and set it as follows:
    implicit_flush = On
    
  2. Add the following lines at the end:
;xDebug Configuration starts

zend_extension="/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so"

xdebug.profiler_output_dir = "/tmp/xdebug/"
xdebug.profiler_enable = On
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=10000
xdebug.remote_handler="dbgp"

;xDebug Configuration ends

Be sure to navigate to the directory where you targeted the extension and verify that the file path is correct. The folders in your XAMPP installation may be named differently.

The current (as of Sept 2010) version of the XAMPP binary for OS X contains the 2.0.4 version of XDebug which will not let you see the variable data from included files when running XDebug. You can download a newer version from the ActiveState website. Unzip and copy one of the xdebug.so files to /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626.

Test the XDebug Installation

Now we need to verify that XDebug is installed correctly. Restart XAMPP. In Windows, we can just browse to the c:\xampp folder in Windows Explorer and double-click the program xampp-control.exe to open the application shown below.

Press the Stop button for Apache. The button with then read Start. Press Start for Apache and wait a few seconds and the green Running message will again display. Then press Exit to close the application.

In Windows, if you get ERROR: MySQL service not started [-1], you may be able to correct this by going to c:\xampp\mysql and running mysql_uninstallservice.bat followed by mysql_installservice.bat.

In Linux, to restart LAMPP execute the command:

 sudo /opt/lampp/lampp restart

In Mac, open the XAMPP Control application, stop, and then start the Apache service.

Once XAMPP has been restarted, open a browser and navigate to http://localhost to display the XAMPP welcome message. (If you set XAMPP to listen to another port, you must append the port to the URL. For example: http://localhost:8080/). Press the phpinfo() link again to display the PHP information screen. Scroll down to the lower part of the screen. You should see a section for XDebug as shown below.

Look at the settings you entered in the php.ini file above. You should see these same settings in the XDebug display, as shown below.

At this point, XDebug is set up correctly.