PHP debugging environment

Source: Internet
Author: User

PHP debugging is always so unsatisfactory, but you still need to use it :), such as XAMPP, lamp, lnmp, and other configurations, which always changes with version upgrades, if you have time to write a common configuration tool, share it with everyone.

 

Step 1: ide Selection

Because there were too many tools used in the past, Android, Maven, J2EE, ssh, cxf and other tools are often loaded in eclipse, which caused some inexplicable problems. Therefore, we have the following suggestions:

Download eclipse for PHP developers, address http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliossr2

Of course, you can also choose to download the PDT plug-in or install it directly from eclipse.

Step 2: Select Debugger

There are two debugger options: Zend debugger and xdebug. Of course, because xdebug is completely free, the download is simple. First it, address http://xdebug.org/download.php

When downloading, You need to download the corresponding files for your platform. If you are in Windows, you can download the corresponding binaries. that is, the dynamic library. As for the 64-bit problem, you must download it in the same environment as your php. For example, although you are using a Windows 64 operating system, but you are using a 32-bit PHP build, you also need to use the corresponding 32-bit xdebug. I spent a lot of time solving this problem during configuration.

Step 3: integrate PHP with Debugger

Decompress xdebug and place the obtained DLL in the extension directory corresponding to the PHP used by your web server, because I usually have dozens of development environments on one machine, therefore, you may encounter various problems. You must put them in the PHP environment you used during debugging. Eclipse for PHP does not have a PHP environment. The specific method is:

A, put the php_xdebug-2.2.1-5.4-vc9.dll under the ext directory of PHP.

B. Modify PHP. ini and add the following to the file:

[Xdebug]

Zend_extension = "D:/develop/web/phpbench/EXT/php_xdebug-2.2.1-5.4-vc9.dll"; (the path is set as needed)

Xdebug. auto_trace = on
Xdebug. show_exception_trace = on
Xdebug. remote_autostart = on
Xdebug. remote_enable = on

Note that the zend_extension command is used. In versions earlier than php5.3, different zend_extension commands should be used based on PHP's thread security settings or debug build settings.

For example, if PHP sets thread security, zend_extension_ts = "D:/develop/web/phpbench/EXT/php_xdebug-2.2.1-5.4-vc9.dll" should be used to replace zend_extension. otherwise, an error occurs, whereas PHP versions later than php5.3

You don't have to worry about this. zend_extension is used directly, and zend_extension_ts is no longer used.

The method to test whether the configuration is successful is simple. Start the Web server and use phpinfo () to print the PHP environment data. If you see a lot of xdebug parameters and parameter values, you will succeed. If you don't have it, configure it slowly. If you have any problems, read the English documents.

Address: http://www.eclipse.org/pdt/articles/debugger/os-php-eclipse-pdt-debug-pdf.pdf if not successful, is your level of English problem :)

Step 4: Configure PDT and xdebug for integration.

A. open preferences> php> executables in eclipse for PHP developers. add a third-party PHP environment, that is, the PHP Directory We Just configured (if you have many PHP environments, You have to select the correct one). After adding it here, input PHP executable pathand php.exe‑php-cgi.exe, which are different PHP Execution Methods. Which one is the same. Select debugger, and select xdebug.

B. open preferences> php> debug in eclipse for PHP developers. In default setting, select xdebug for PHP debugger, server can select default PHP Web server PHP executable to select the executable just added.

Step 5: perform initial script debugging.

After the above configuration, you can create a PHP project and directly debug the PHP script in the project. Right-click the project and choose debug as> PHP script for debugging. In this debug, configure a debug configuration. in this debugging configuration, select alternate php as the executable of the PHP just created. the following PHP file selects the PHP file you want to debug in one step.

There is a bug here, that is, when you set the above steps, you must restart eclipse for PHP. Otherwise, xdebug will work, but eclipse for PHP does not display the debugging process, you cannot see whether the breakpoint is executed. Restart and click OK.

Step 6: perform remote web debugging

Based on the above, you need to configure the default PHP Web server. This mainly refers to URL to your php file. For example, when debugging a website, index. php is myproject/index. php In your project, which must be mapped to mapping in the web server configuration.

Http: // localhost/myproject --------- myproject/in this way, when you access http: // localhost/myproject/during debugging, your index. php file will be reflected. I don't want to write more details here.

It mainly understands the principle of debugging:

PHP script example uses the third-party php.exe to execute the PHP file in your project. xdebug will send the execution process information to your eclipse for PHP through port 9000. Then eclipse will send the debugging information to xdebug.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.