您的位置:首页 > 运维架构 > Linux

Ubuntu(Linux)+XAMPP(LAMPP)+eclipse+PHP+XDebug 完整的开发环境配置方法

2010-12-14 10:11 926 查看
首先是安装JRE或者JDK,网上大把方法,敬请搜寻。我偷懒。

其次,装XAMPP,安装方法链接如下:这里假设XAMPP的安装路径为:/opt/lampp

http://unixfans.blogbus.com/logs/34373510.html

再次,装eclipse,安装PDT集成版本的eclipse,下载地址如下,选择ALL IN ONE版本的PDT

http://www.eclipse.org/pdt/downloads/

这个最简单,下好后直接解压到你希望的目录地址就算安装完成了,我这里假设安装在:/home/yourname/eclipse

eclipse运行前的一些配置步骤,看这里的第2部分:http://unixfans.blogbus.com/logs/33942617.html

第一次运行eclipse时,需要指定workspace的地址,如果你只是为了开发php,那么可以把工作区地址指定到:/opt/lampp/htdocs ,因为这里是XAMPP中apache的docs地址,添加的php文件可以直接在浏览器中运行。但坏处是删除文件时要小心,不然把XAMPP中htdocs文件夹里原有的文件删除了。也可以不这样做,将工作区用ln命令链接到htdocs文件夹下即可。

以上两样的安装都比较简单,直接解压就搞定了。下面开始装Xdebug,在这里下载已经编译好的Xdebug remote文件,注意你的版本和系统类型。

http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging

下载好后j将xdebug.so文件,拷贝到你的LAMPP文件夹内,本文中路径如下:/opt/lampp/lib/php/extensions/

然后打开php.ini进行编辑,路径如下/opt/lampp/etc/php.ini

在此文件倒数第二行加入如下代码段,注意zend_extension和xdebug.profiler_output_dir要对应你的lampp的安装地址,我这里红色高亮。

[XDebug]
zend_extension="/opt/lampp/lib/php/extensions/xdebug.so"
xdebug.remote_enable=true
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/opt/lampp/tmp"

保存,退出。好,到此,xdebug安装完成,如果已经开启xampp了,请重启。

登录http://localhost/xampp ,点左边栏的phpinfo() ,查找“xdebug”关键字,如果有xdebug的详细信息,说明安装成功。

这里有个小问题:官站说明文档中介绍:http://www.xdebug.org/docs/install#configure-php

add the following line to php.ini: zend_extension="/wherever/you/put/it/xdebug.so" (for non-threaded use of PHP, for example the CLI, CGI or Apache 1.3 module)

or: zend_extension_ts="/wherever/you/put/it/xdebug.so" (for threaded usage of PHP, for example the Apache 2 work MPM or the the ISAPI module).

虽然我的XAMPP中的apache版本是2.2.11,但是使用zend_extension_ts语句是无法加载xdebug的,请读者自行测试,如果zend_extension_ts不能加载,那么和我一样请用zend_extension。

打开Eclipse,在里面设定xdebug,
window->preferences->PHP->Debug,
PHP Debugger 选择 Xdebug
Server 选择 php Default Web Server,
php Executalbe 点进去之后按Add, 在Executable Path按Browse,选择/opt/lampp/bin/php-5.2.8 ,php ini文件路径在/opt/lampp/etc/php.ini ,名字嘛,随便给个就好,叫php吧,php debuger选择XDebug ,点ok

同样是在preferences里,点general,web browser ,点new ,指定下外部的Firefox浏览器地址:/usr/bin/firefox

下面添加一个php文件测试下是否成功。新建一个名为first的php project,在此project里新建一个php file,名字也叫first.php,点next,试用而已,所以选择new simple php file ,
填入下列代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Basic PHP Page</title>
</head>
<body>
<p>This is standard HTML.</p>
</body>
</html>
保存,然后右击first.php, properties ,Run/Debug Settings ,点new ,选择php web server。
名称:first
server debugger :XDebug
PHP Server :Default。。。。。。
File一栏输入创建的PHP项目的相对路径,如果项目的绝对路径是/opt/lampp/htdocs/first/first.php,那么此栏只输入/first/first.php

URL勾选auto generate就是。
点apply应用。

OK,右击first.php,run as PHP Web Page 看看成果。正常情况下应该是自动打开一个Firefox窗口,地址是http://localhost/first/first.php ,页面内容是:This is standard HTML. 想试试debug也一样,debug as PHP Web Page ,此时会提醒你是否切换到debug视角,点yes ,进入debug模式,用过别的IDE的应该很熟悉。想再换回PHP编辑视角,点右上角的PHP 图标的perspective就回来了。

以下作者和网站对本文完成有帮助:

http://blog.sina.com.cn/s/blog_4dda073c0100bikk.html

http://www.ibm.com/developerworks/cn/linux/l-xampp/

http://www.latenightpc.com/blog/archives/2008/05/24/a-complete-lamp-development-environment-xampp-eclipse-pdt-and-xdebug
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: