This article describes the perfect environment for developing Web applications in PHP on the Windows platform (though the software is also available on Linux).
One of the most difficult situations developers face is choosing the perfect environment for application development. Its even tougher with open source tools; there may be glitches in the software you choose, and there are chances that midway through application development, you realise you’re stuck and cannot proceed. The only way to minimise such risks is to carefully choose tried and tested tools, with robust community support. Here we will discuss such an environment, on the Windows platformthe NetBeans IDE, the Symfony framework and the XAMPP Web server package.
A framework is designed to provide basic application functionality such as database interaction, form validation and presentation. With these available, you can focus on writing application code. Also, the less code you write, the fewer bugs you introduce. Our framework here is Symfonyone of the most-used PHP frameworks, with great community support and some prestigious references like Drupal, phpBB, Opensky.com, etc.
You can download version 1.4.17 or 2.0 from the website (http://goo.gl/YiUer); the information there will help you decide which to use. A common difficulty in using Symfony is that it’s hard to learn its commands and file structure. Also, its commands must be run using a command prompt. However, as we will see, using the NetBeans IDE reduces these problems to a large extent. Symfony does not need installationjust unzip the downloaded zip file, and in the IDE section, we can integrate it with NetBeans.
The Web server/database
XAMPP is a bundle of Apache, MySQL and PHP, which we will be using for our development environment. It is completely compatible with NetBeans, and has all the required tools bundled. Download it from http://goo.gl/iQbh2. We will use version 1.7.7.
During installation, when prompted for what services you want to install, just select MySQL and PHP. You can access the XAMPP Control Panel (Figure 1) via its Start Menu button.
The NetBeans IDE has complete Symfony support, and XAMPP also blends well with it. You can download the PHP-only version of NetBeans from http://goo.gl/flm9O and install it.
Let us integrate Symfony with NetBeans, create a Symfony project, look at how to run Symfony commands from NetBeans, and finally check x-debug in NetBeans, to debug our Symfony application.
Integrating Symfony and NetBeans
You can view a screen-cast of this at http://goo.gl/XZF7d. First, in NetBeans, go to the Tools ? Options ? PHP tab. In the General tab’s PHP5 Interpreter field, set the XAMPP php.exe file path (generally, in the xampp/php folder). Then, in the Global Include path, set the Symfony folder path. Now go to the Symfony tab. Here, in the Symfony Script Path, set the Symfony file path (generally symfony x.x/data/bin). Refer to Figures 2 and 3. This completes the NetBeans set-up.
The new Symfony project
Go to New Project and select PHP as the category. In the next page, set the project name, source folder and the PHP version to be used. In the following page, you can set the project URL, and select the Web server. In the final page, check the Symfony PHP Web framework to create a Symfony project. As you select the Symfony framework, you are given the option of selecting the applications to be created. Nevertheless, you can create a new application in the Symfony project at any time. As you click Finish on this page, a new Symfony project is created, along with the complete folder structure and default files. Now all you have to do is to write your application, without bothering much about the logistics.
Running Symfony commands
To run a Symfony command, you can simply go to the project you have created in NetBeans, right-click, and select Symfony ? Run Command. This opens up a list of all the Symfony commands available (see Figure 4), and you can just run a command without having to remember the syntax, or type it at a command prompt.
Debugging the project
To debug projects, change the xampp/php/php.ini file. Just find and uncomment the lines as follows:
zend_extension = “XAMPP_HOME\php\ext\php_xdebug.dll”
xdebug.remote_host=localhost #Change from “localhost” to “127.0.0.1”
xdebug.remote_enable = 0 #Change 0 to 1.
xdebug.remote_handler = “dbgp”
xdebug.remote_port = 9000
Then save this and restart XAMPP. Now you are ready to debug the project. Just click Debug Project in the Symfony main window, and execution stops at the first line of index.php, since this is the default controller in Symfony. You can now go step by step to check your code flow. If you dont want execution to stop at the first line, but at your own breakpoint, just un-check Stop at the first line in the Debugging tab in Tools ? Options ? PHP ? General. When faced with any problems while setting up the debugging function, you can refer to http://goo.gl/dzeBE.
This completes our development environment set-up. Since each component has a robust community behind it, the chance that you will get stuck mid-way is pretty remote. This is the power of open source. I hope you like this article, and you use this set-up to develop applications. Any queries, suggestions, or feedback is most welcome.
I suggest to add the following my favourite free IDE: http://www.codelobster.com