Home Backend Development PHP Tutorial 怎么调试php《转》

怎么调试php《转》

Jun 13, 2016 am 11:39 AM
apache eclipse php xampp xdebug

如何调试php《转》

一个好的代码调试器可以让你在解决问题的时候事半功倍,因为代码调试器可以设置断点,可以逐行逐行代码进行跟踪,可以查看变量的值等等优点。每一种开发语言都有很好的代码调试器,PHP也不例外,Xdebug、Zend Debugger等都是十分好的php调试工具,本文将为您展示如何用eclipse+pdt+xdebug来调试php网站。

?

1.工具准备

?

eclipse,地球上的软件开发人员都知道能用它来开发java项目,其实还可以用它来开发php网站,点击这里下载集成了pdt的eclipse版本。选择适用于您的操作系统的进行下载。

php+apache,这两种工具只需要安装集apache、php、mysql、phpMyAdmin等于一身的xampp即可,如果您不知道如何安装和使用xampp,请阅读《如何安装xampp》和《如何安装部署php网站》。

Xdebug,如果您使用的是xampp,那么你无须下载xdebug,因为它已经集成了,你只需要在xampp的php.ini文件开启xdebug就行了。如果您没有使用xampp,那么你一定要选择合适您php版本的xdebug,否则会集成不成功的,如何知道要下载什么版本的xdebug?首先先创建一个php文件,里面的代码为,然后部署到php下运行,查看php的相关信息,把所有信息复制到xdebug官方的分析工具页面进行分析,它会给出您的php对应的分析结果,提示您下载对应版本的xdebug。

?

2.配置eclipse pdt

?

下载eclipse for php developers后,解压就可以使用了,打开后eclipse工具后就可以配置php和xdebug的相关信息了。

window->Preferences->php,

phpeclipse1

如何调用php网站1

先配置php运行程序

phpeclipse2

如何调用php网站2

配置运行环境

phpeclipse3

如何调用php网站3

选择php版本

phpeclipse4

如何调用php网站4

配置服务器

phpeclipse5

如何调用php网站5

配置xdebug

phpeclipse6

如何调用php网站6

?

3.配置php,集成xdebug

?

如果您没有安装xampp,那么您就需要先下载你与您安装的php版本对应的xdebug,具体做法在第一点工具准备中已经说明,如果您已经安装了xampp,那么恭喜您,你只需要开启xdebug就行,具体做法就是打开php.ini,然后搜索Xdebug,找到后把zend_extension前的;去掉,把=号右面的路径改为”D:\xampp\php\ext\php_xdebug.dll”,(注:路径要修改为您自己安装的目录),然后把以下几个选项前的;也去掉,并把=号右面的值改与下面的一致

xdebug.remote_enable=On

xdebug.remote_host=”localhost”,注:这里的localhost改为你的服务器对应的IP

xdebug.remote_port=9000

xdebug.remote_handler=”dbgp”

?

4.配置apache

?

通过配置apache服务器可以实现将访问路径映射到你本地的php网站程序目录,如果您安装了xampp,那么只需要修改apache\conf\extra目录下的httpd-xampp.conf文件,在标签内增加以下的代码:

Alias /phpip “D:/phpworkspace/HelloWorld/”

Options Indexes FollowSymLinks Includes ExecCGI

AllowOverride all Order allow,deny

Allow from all

其中,/phpip改为您想在浏览器中输入访问到项目的名称,D:/phpworkspace/HelloWorld/改为您程序对应的目录。

?

5.设置断点并调试

?

在eclipse中设置php调试断点,然后在浏览器中输入“http://servername/phpname/调试的文件”进行访问,servername是您的服务器的地址,phpname是您在apache中设置的php项目名。eclipse会提示是否打开调试控制面板,如下图:

phpeclipse7

如何调试php网站7

接着可以逐行代码进行调试

phpeclipse8

如何调试php网站8

在Debug output面板还可以查看网页浏览输出

phpeclipse9

如何调试php网站9

实际访问网页结果

phpeclipse10

如何调试php网站10

到此,你已经学会如何调试php,赶快试试吧。

?

原文地址:http://www.laokboke.net/2011/05/09/how-to-debug-php-using-xdebug/

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

See all articles