How to build a PHP debug environment, under Windows
The PHP language is a versatile option to develop since websites, to full web based systems, because of the high level of integration with the HTML sctructure, object orientation support and the fact of not requiring build and compilation. However, depending on the desired complexity, a good debugger and a development environment may be requisites.
In this article I explain how I use to build, under windows, a full PHP development environment, with debug support, using the Eclipse's last version available, because PDT All-In-One package is usually outdated one version or two of the last stable build.
1. Install Zend Server
The Zend Server if a Apache-based webserver, that has PHP support and debug features, easy to install and configure.
- Download the Zend Server: http://www.zend.com/en/products/server/downloads (ZendServer-6.3.0-php-5.3.28-Windows_x86.exe - Use this link to download the Zend Server 32 with PHP 5.3 for Windows).
- Start the installation
- If want to take the opportunnity to install a local MySQL server, at the Setup Type screen, choose "Custom" and check the option "MySQL Server (separated download)"
- At the WebServer screen, keep checked the option "Install an Apache xxxx Web Server". If you want to go with the ISS, I wish you Good Luck! =)
- At the Apache Port Number screen, I prefer changing the port to 81, for security reasons. But if you want to keep 80, no problem. The second field if the port used to access the server administration panel (http://localhost:10081/).
- Then, click the Install button. If you chose to install the MySQL server, it will be downloaded at this moment. The process takes a few minutes.
- Before finishing the install, the system will ask you about the Apache HTTP server (httpd.exe) permissions. Keep checked the Private Networks options and click Allow Access. - here, I apologize for the Portuguese screenshot, but I think it's enough to understand this step.
- Keep the option "Start working with Zend Server" checked and finish the install pressing the Finish button.
2. Zend Server configuration
After install Zend Server, open the url http://localhost:10081/
- License Agreement: Read the term, check the box, and click Next.
- Launch Type: Select Development and click Next.
- User passwords: Define the administrator password, keeping the developer password blank, and click Next.
- Library packages: Wait for all them reach 100% and click Next.
- Summary: This screen shows the settings summary. Click Launch.
3. Testing Zend Server
Go to the folder C:\Program Files (x86)\Zend\Apache2\htdocs. This is the place where the webserver documents are located. Erase everything and create a blank index.html.
4. Eclipse install
Go to the Eclipse project download page (http://www.eclipse.org/downloads/) and download the Eclipse Standard last version.
To install the Eclipse, you must just unpack the compressed file inside any folder. Then, run eclipse.exe.
When running for the first time, you will be asked for your workspace location, that is, the folder where are located your projects. Select the folder C:\Program Files (x86)\Zend\Apache2\htdocs (I suggest using it as default location for your PHP projects). Check the "Use this as default..." option. If you need to change the workspace location, go to File -> Switch workspace.
5. Install PHP Development Tools in Eclipse
To install the PDT (PHP Development Tools) package, select Help -> Install New Software.
Fill the Work with field with the following URL: http://download.eclipse.org/tools/pdt/updates/release and press [Enter].
If everything is fine, you will see a Install Details screen, just a summary of the items about to be installed. Click Next, accept the licence terms and click Finish. Eclipse will download all packages automatically. At the end, will be requested that you restart the Eclipse so the changes can make effect.
6. Eclipse configuration
1. PHP Perspective
2. Web Server address
You must configure your webserver address (if you chose the 81 port for the Zend Server, as mentioned in the step 1.5):
3. Select the Web Browser
4. Avoid the debugger stop at every file first line
By default, the debbuger always stop at every file first line. As I don't like very much this behavior, I disable it: In the Preferences window (Window -> Preferences), go to PHP -> Debug and uncheck the option Break at first line
7. Creating and debugging your first project
Look for the PHP Explorer tab, right-click, and select New -> Project.
Select the option PHP Project and click Next.
Right-click the project entry, select New -> PHP File, and create a index.php file, with the following code:
<?php $a = 1; $b = 2; $c = $a + $b; echo "Result = ". $c;
Another way to do it is right-clicking the source code, or the file itself in the PHP Explorer (it's up to you). Then, the webbrowser you chose at the step 6.3 will open. Go back to the Eclipse window.
It will be asked if you want to open the Debug Perpective. I use to accept and remember the decision, because it has many useful debug panel (breakpoints, variables inspect etc).
If nothing is wrong until here, you already have a PHP debug environment ready to go, using Eclipse latest version and the browser of your choice. Enjoy!