Home php教程 php手册 搭建Eclipse PHP开发环境

搭建Eclipse PHP开发环境

Jun 06, 2016 pm 07:45 PM
eclipse php develop build environment

搭建PHP开发环境: 1、准备并安装下列软件: MySQL 5.1.30: http://dev.mysql.com/downloads/。 Apache 2.2.14: http://httpd.apache.org/. 在安装过程中,会出现3个文本框,上面两个输入你的本机IP(如:127.0.0.1),最下面输入你的EMAIL。安装完成后,apac

    搭建PHP开发环境:
    1、准备并安装下列软件:
    MySQL 5.1.30: http://dev.mysql.com/downloads/。
    Apache 2.2.14: http://httpd.apache.org/. 在安装过程中,会出现3个文本框,上面两个输入你的本机IP(如:127.0.0.1),最下面输入你的EMAIL。安装完成后,apache就自动启动,可以测试apache是否成功启动。在浏览器地址栏里输入:http://localhost/或http: //127.0.0.1,如果出现“It works.”,那么恭喜你,apache已经成功安装了;同时在电脑右下角的任务栏里有一个绿色的 apache服务器运行图标。
    PHP 5.2.11: http://www.php.net/downloads.php. 下载无需安装的zip格式的解压包,不要用那个installer版本的安装文件包(用这个的话很多php扩展都没有安装,比如php的mysql扩展,导致不能连接mysql数据库).
    Zend Debugger 5.2: http://www.zend.com/en/products/studio/downloads. 选择Studio Web Debugger.
    Eclipse for PHP: http://www.eclipse.org/downloads/. 注意是Galileo Packages based on Eclipse 3.5 SR1的版本。Eclipse的工作空间设为D:/php_workspace。
    安装完后,对Eclipse作一些基本的配置。如果要使开发的应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使使用UTF-8编码。
然而,Eclipse工作空间(workspace)的缺省字符编码是操作系统缺省的编码,简体中文操作系统 (Windows XP、Windows 2000简体中文)的缺省编码是GBK或GB18030,在此工作空间中建立的工程编码是GBK或GB18030,工程中建立的文本文件也是GBK或GB18030。如果要使新建立工程、文件直接使UTF-8,则需要做以下工作:
    打开Window->Preferences->General->Workspace,将"Thext file encodiing"最好设成UTF-8,以后新建立工程其属性对话框中的Text file encoding即为UTF-8。
    修改各种文件的编码:在Window->Preferences->General->Content Type中,Text下面有各种文件格式,选择相应的文件格式,在下面的Default encoding输入框中
    输入UTF-8,点Update即可。对PHP开发,最好将HTML和PHP文件编码设为UTF-8。   
    2、让apache载入php模块: conf/httpd.conf,在尾部添加下列内容,表示载入php模块,要注意版本要吻合。

    这里注意一下,如果你的apache是2.0版的你就填写LoadModule php5_module "D:/php/php5apache2.dll"。
    3、添加虚拟目录和默认首页: 默认站点主目录为Apache的htdocs目录。由于要在D:/php_workspace下放置所有的Eclipse工程,因此为了能够访问到各个工程    下面的php文件,需要建立一个虚拟目录指向eclipse工程所在目录。修改httpd.conf,在文件结尾添加:

    这样做的好处是,所有php工程都共享一个apache配置,通过http://localhost/Workspace/ProjectDirectory即可访问相应工程下面的php文件。
    4、PHP配置:
    (1)把D:/php下的php.ini-recommended,改名为php.ini。
    (2)设置下面的项目:

    (3)开启出错消息提示:为了在开发时能更好地进行调试,开启php.ini中的display_errors和display_startup_errors变量。display_errors 变量的目的很明显,
它告诉PHP是否显示错误。另外,变量error_reporting 的默认值是 E_ALL。这个设置会显示从不良编码实践到无害提示到出错的所有信息。E_ALL 对于开发过程来说有点太细,
因为它在屏幕上为一些小事(例如变量未初始化)也显示提示,会搞糟浏览器的输出。如果只想看到错误和不良编码实践,但是不想看到无害的提示,可设成以下值:


    (下列配置可选)依赖于Apache正在做的工作,在PHP中打开错误报告可能没法工作,因为在计算机上可能有多个PHP版本。有时很难区分Apache正在使用哪个PHP版本,因为Apache只能查看一个 php.ini 文件。不知道 Apache 正在使用哪个 php.ini 文件配置自己是一个安全问题。但是,有一种方法可以在 Apache 中配置 PHP 变量,从而保证设置了正确的出错级别。而且,最好知道如何在服务器端设置这些配置变量,以否决或抢占 php.ini 文件,从而提供更高级别的安全性。要做在 php.ini 文件中已经做过的事,请把下列各行添加到 httpd.conf,覆盖任何 php.ini 文件:

    这会覆盖在 php.ini 文件中为 display_errors 已经设置的标志,以及 error_reporting 的值。值 2039 代表 E_ALL & ~E_NOTICE。如果愿意采用 E_ALL,请把值设为 2047。
同样,还是要重启 Apache。
    (4)找到Dynamic Extensions项,这里是PHP扩展设置部分,启用下列常用扩展(去掉以下几项前面的“;”).

    (5)解压出Zend Debugger,把与PHP版本相对应的ZendDebugger.dll拷贝到PHP安装目录下,修改php.ini,添加以下内容:

    把解压出来的dummy.php放到httpd DocumentRoot目录以及D:/php_workspace/下,用于在Eclipse里测试Debugger是否连通(Debug Configurations->PHP Web Page->Test Debugger),
成功会出来一个success message。(通过修改worksapce的对应站点目录,Configure "Default PHP Web Server",也可以放到网站的子目录下)。
    (6)这一步不是必须的:为防止以后出问题,把PHP下的php5ts.dll、libmysql.dll、以及ext/php_mysql.dll、ext/php_mysqli.dll(如果使用了这个扩展)三个文件拷贝到Windows/system32下。
注意很多时候出现一些与代码无关的很难解决的问题时,十之八九就是因为扩展没有正确加载的原因(即使php.ini中的extension_dir指向了ext目录),这主要
是因为PHP模块由Apache来加载,这是两个不同的软件,经常会出现一些协作上的问题。这时就要把你使用到的扩展从ext下拷贝到system32下。
    5、配置Eclipse指向PHP模块: 打开Eclipse的Window->Preferences->PHP->PHP Executables->Add,添加
Name: PHP 5.2.11
Executable Path: D:/PHP/php.exe
PHP ini file(optional): D:/PHP/php.ini
PHP debugger: Zend Debugger
    6、配置Eclipse中的php文件访问URL: 打开Window->Preferences->PHP->PHP Server,编辑Default PHP Web Server条目,将URL改为http://localhost/Workspace,注意URL栏中添加了Workspace,
这个是在httpd.conf中添加的目录别名。
    7、测试: 配置完后重启apache,然后新建一个PHP Project命名叫FirstPHPTest, 当然使用的是我们的D:/php_workspace作为Eclipse的workspace目录。在工程中新建
PHP File, 比如使用的phpinfo.php。内容为

    当在phpinfo.php上右键 Run As->PHP Web Page。

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
3 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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

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.

See all articles