Build an eclipse php development environment

Source: Internet
Author: User
Tags php debugger php development environment php web server

Build a php development environment:
1. Prepare and install the following software:

MySQL 5.1.30: http://dev.mysql.com/downloads /.
Apache 2.2.14: http://httpd.apache.org/. Three text boxes appear during installation, the above two enter your local IP (for example: 127.0.0.1), enter your email at the bottom. After the installation is complete, Apache is automatically started to test whether Apache is started successfully. Enter http: // localhost/or http: // 127.0.0.1 in the address bar of the browser. If "It works. ", congratulations, Apache has been successfully installed. At the same time, there is a green Apache server running icon in the taskbar in the lower right corner of the computer.
PHP 5.2.11: http://www.php.net/downloads.php. download a zip package that does not need to be installed. Do not use the installer package. (if this is used, many PHP extensions are not installed, such as the MySQL extension of PHP, as a result, the MySQL database cannot be connected ).
Zend debugger 5.2: http://www.zend.com/en/products/studio/downloads. Select studio Web debugger.
Eclipse for PHP: http://www.eclipse.org/downloads/. Note that it is the version of Galileo packages based on Eclipse 3.5 sr1. Eclipse's workspace is set to D:/php_workspace.
After installation, make some basic configurations for eclipse. If you want to make the development of applications have better international support, to maximize support for Chinese output, it is best to use UTF-8 encoding.
However, the default character encoding of the eclipse workspace is the default encoding of the operating system. The default encoding of the simplified Chinese operating system (Windows XP, Windows 2000 Simplified Chinese) is GBK or gb18030, the project code created in this workspace is GBK or gb18030, and the text files created in the project are also GBK or gb18030. If you want to make a new project, file to make UTF-8 directly, you need to do the following:
Open Window-> preferences-> General-> workspace, set "thext file encodiing" to a UTF-8, and the text file encoding in its properties dialog box will be a UTF-8.
Modify the encoding of various files: In window-> preferences-> General-> content type, there are various file formats under text. Select the corresponding file format, in the default encoding input box below
Enter the UTF-8 and click Update. For PHP development, it is best to set HTML and PHP file encoding as UTF-8.
2. Load Apache into the PHP module:
Conf/httpd. conf. Add the following content at the end to load the PHP module. Note that the version must be consistent.

Phpinidir "D:/PHP/" <br/> loadmodule php5_module "D:/PHP/php5apache2_2.dll" <br/> addtype application/X-httpd-PHP. php

Note that if your Apache version is 2.0, enter loadmodule php5_module "D:/PHP/php5apache2. dll ".
3. Add the virtual directory and default homepage:
The default site home directory is Apache's htdocs directory. To place all eclipse projects under D:/php_workspace, you need to create a virtual directory pointing to the directory where the Eclipse project is located to access the PHP files under each project. Modify httpd. conf and add the following content at the end of the file:

Alias/workspace/"D:/php_workspace/" <br/> <directory "D: /php_workspace/"> <br/> options indexes Multiviews <br/> AllowOverride none <br/> order allow, deny <br/> allow from all <br/> </directory>

The advantage of this is that all PHP projects share an Apache configuration, and you can access the PHP file under the corresponding project through http: // localhost/workspace/projectdirectory.
4. php Configuration:

(1) Rename PHP. ini-recommended under D:/PHP to PhP. ini.
(2) set the following items:

Zend. ze1_compatibility_mode = off // whether PhP4 is supported. You 'd better disable it, otherwise, an error occurs when processing the ZIP file with PhP5. <br/> post_max_size = 20 m // maximum size of post information <br/> magic_quotes_gpc = off // whether to use magic quotes <br/> extension_dir = "D: /PHP/EXT "// PHP extension <br/> upload_max_filesize = 20 m // Upload File Size <br/> max_execution_time = 6000 // maximum page execution time (seconds) <br/> max_input_time = 600 // maximum script parsing time (seconds) <br/> memory_limit = 20 m // maximum memory allocated by the script <br/> output_buffering = on // whether to enable the output buffer <br/> implicit_flush = on // output the buffer content in a timely manner

(3) enable error message: To make debugging easier during development, enable the display_errors and display_startup_errors variables in PHP. ini. The display_errors variable has an obvious purpose,
It tells PHP whether an error is displayed. In addition, the default value of the variable error_reporting is e_all. This setting displays all information from poor coding practices to harmless prompts to errors. E_all is a little too detailed for the development process,
Because it displays a prompt on the screen for some trivial matters (such as the variable is not initialized), it will mess up the browser output. If you only want to see errors and bad code practices, but do not want to see harmless prompts, you can set it to the following values:

Error_reporting = e_all &~ E_notice
(The following configuration is optional) depends on what Apache is doing. Opening an error report in PHP may not work because multiple PHP versions may exist on the computer. Sometimes it is difficult to tell which PHP version Apache is using, because Apache can only view one PHP. ini file. I don't know which PHP. ini file Apache is using to configure itself as a security issue. However, there is a way to configure the PHP variable in Apache to ensure that the correct error level is set. In addition, it is better to know how to set these configuration variables on the server side to reject or preemptible the PHP. ini file to provide higher-level security. To add the following lines to the httpd. conf file to overwrite any PHP. ini file:

Php_flag display_errors on <br/> php_value error_reporting 2039

This overwrites the flag set for display_errors and the value of error_reporting in the PHP. ini file. The value 2039 represents e_all &~ E_notice. If you want to use e_all, set the value to 2047.
Similarly, restart Apache.
(4) Find the dynamic extensions item. Here is the PHP extension Settings section. Enable the following common extensions (remove the previous ";").

Extension = php_bz2.dll <br/> extension = php_curl.dll <br/> extension = extensions <br/> extension = php_dbase.dll <br/> extension = php_gd2.dll <br/> extension = php_imap.dll <br /> extension = php_ldap.dll <br/> extension = php_mbstring.dll <br/> extension = extensions <br/> extension = php_mysql.dll // MySQL extension <br/> extension = php_mysqli.dll <br/> extension = php_pdo.dll // PDO extension <br/> extension = extensions // pdo_mysql extension <br/> extension = php_sockets.dll <br/> extension = php_xmlrpc.dll <br/> extension = php_xsl.dll <br/> extension = php_zip.dll

(5) decompress Zend debugger, copy zenddebugger. dll corresponding to the PHP version to the PHP installation directory, modify PHP. ini, and add the following content:

[Zend] <br/> zend_extension_ts = D:/PHP/zenddebugger. dll <br/> zend_debugger.allow_hosts = 127.0.0.1 <br/> always = always

Decompress the extracted dummy. put php In the httpd DocumentRoot directory and D:/php_workspace/to test whether the debugger is connected in eclipse (debug deployments-> php web page-> test debugger ),
A success message is displayed. (By modifying the corresponding site directory of worksapce, configure "Default PHP Web server" can also be placed under the subdirectory of the website ).
(6) This step is not necessary: to prevent future problems, put the php5ts under PHP. DLL, libmysql. DLL, and ext/php_mysql.dll, ext/php_mysqli.dll (if this extension is used) three files are copied to Windows/system32.
Note that there are many problems that are hard to solve without code, and the reason for the failure to properly load the extension is (even if the extension_dir in PHP. ini points to the ext directory ).
It is because the PHP module is loaded by Apache, which is two different software and may often encounter some collaboration problems. In this case, you need to copy the extension you used from ext to system32.
5. Configure eclipse to point to the PHP module:
Open Window-> preferences-> PHP executables-> Add in eclipse to add
Name: PhP 5.2.11
Executable path: D:/PHP/php.exe
Php ini file (optional): D:/PHP. ini
PHP Debugger: Zend Debugger
6. Configure the PHP File Access URL in Eclipse:
Open Window> preferences> php> PHP server, edit the default PHP Web Server entry, and change the URL to http: // localhost/workspace. Note that workspace is added to the URL bar,
This is the directory alias added in httpd. conf.
7. test:
Restart Apache after configuration, and create a new PHP project named firstphptest. Of course, we use D:/php_workspace as the eclipse workspace directory. Create in Project
PHP file, such as phpinfo. php. Content is

<? Php <br/> phpinfo (); <br/>?>

Right-click phpinfo. php and choose run as> php web page.

Related Article

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.