In part 1 of this series, I looked at the web browsers and (Windows) IDEs. Today I’m going to look at a local development server and its PHP configuration, as well as some of the IDEs/editors available for Linux, especially the cross-platform options.
Local development server
Now, when developing your applications, you can’t simply keep uploading to your web host’s server for testing. Having a local development server with PHP and MySQL is invaluable; whether it’s on your local machine or a seperate box (I use an old P4). Configuring all the applications under Windows can be a real pain, but luckily there are some all-in-one installers that make it easy:
WampServer is by far the best option for Windows; it comes with Apache, PHP, MySQL and phpMyAdmin all ready and configured. Best of all, you can manage multiple versions of Apache, PHP and MySQL, and it supports easy switching out of the box, to closely replicate your production environment.
While WampServer is certainly very powerful and effective, I personally use XAMPP Lite, as it offers the usual Apache/PHP/MySQL, phpMyAdmin, and best of all, it’s entirely portable – I can pop it on a USB stick and take it to another machine if needed. The XAMPP control panel is also simple and effective.
Thanks to the wide availability of online tutorials in this area, setting up your own Apache/PHP/MySQL server isn’t as hard as it used to be. If you really want to roll your own WAMP, take a look at one of these tutorials.
If you’re on a Linux box, you can probably just install Apache, PHP and MySQL from your package manager. If you’re running Ubuntu, try this guide.
Seeing as you won’t be running a production web server from your local development setup, you might as well configure it to best suit development. With a few of these simple changes, you can tweak your PHP setup to best suit you. Load up your PHP.ini file and have a read through these suggestions.
short_open_tag = On
If you’re working with view files written for a PHP framework, or just generally open source PHP applications, chances are you’ll need to enable this directive. When it comes to PHP tags, <?php is the standard, and <? is widely accepted but not always available. Save yourself a lot of hassle by enabling this directive.
implicit_flush = On
When you make a call to echo() or print(), or put a HTML block between PHP code blocks, PHP doesn’t always output it automatically. Setting implicit_flush to On forces it to do so. This is a great help for debugging; the moment something happens, you’ll see it in your browser/console window. (I believe PHP-CLI enables this by default.) However, by no means enable this on a production server, as it has serious performance implications.
docref_root = “/phpmanual/” and docref_ext = .html
Do yourself a favour and grab a copy of the PHP manual, pop it on your local development server and point docref_root to it. Enable docref_ext as .html as well; whenever you see a PHP error, it’ll link to your readily-accessible local copy of the manual. An invaluable debugging tool.
Depending on how you want to manage your resource usage on your local machine, set memory_limit to either 16M or some reasonably high amount (a quarter of RAM is appropriate; mine is set to 128M on a 512mb RAM box). If you have fairly resource intensive scripts, setting memory_limit to a high value should help avoid problems later on; if you’re on a constrained shared host and need to get used to not being able to use a lot of memory, set it fairly low – 16M or maybe 32M at the most. Remember that you can usually override this within your scripts using ini_set(‘memory_limit’, ‘xxxM’);
When it comes to php editors on Linux, there aren’t too many real Linux options. Luckily, however, some of the best cross platform editors work far better on Linux than on Windows (quite possibly as a result of Linux OSes being typically more efficient than Windows on the same hardware). Here are some of the best options.
Eclipse is pretty much the gold standard for IDEs. It’s entirely open source and heavily customisable, so much so that some professional IDEs are built on top of Eclipse, as we’ll see in a moment. Eclipse was built with Java in mind, but thanks to its powerful plugin system, Zend provides the PHP Development Tools (PDT) for Eclipse, which can transform your Eclipse IDE into a fully-fledged PHP development environment.
Zend Studio for Eclipse
Well, bring on the Eclipse derivatives. Next up is Zend Studio for Eclipse, the successor to the old Zend Studio (which was actually rather powerful, albeit terribly underperforming). With ZSE, the IDE is almost managable for Windows, and certainly an option for developers on Linux boxes. Zend advertises it as the most powerful IDE for PHP, and they’re probably right; the feature set is more or less unmatched from any other general cross-platform PHP IDE, although interestingly PhpED on Windows does come close. To identify the differences between ZSE and just PDT on Eclipse, Zend provides a comparison table.
Aptana PHP Development Environment is yet another Eclipse derivative; the Aptana-provided PHP plugin has one of the best editing systems for PHP, and is very helpful when bashing out code and identifying syntax errors. Interestingly, it’s a general plugin for Aptana’s derivative of Eclipse, and you can also install their RadRails plugin alongside to quickly switch between PHP and RoR. If you don’t want to download Aptana’s editor and already have Eclipse, you can install Aptana itself as a plugin on top of Eclipse.
Of course, for quick hacks you can’t go past a simple text editor. I usually work with Gnome, so I always keep gedit handy, and gphpedit is useful; for KDE, there’s Quanta and a few alternatives. You don’t really need autocomplete and other code intelligence in your spare editor; syntax highlighting will help you put together hacks quickly and effectively.
That’s all, folks!
And that’s all for part two of our series on the ultimate php web development environment. In part 3, we’ll take a look at setting up a linux server to help with your PHP web development, from the usual LAMP to samba shares, a local SVN server to webmin for web-based server administration. If you liked this part of the series, please subscribe to our PHP RSS feed to keep up to date on our latest PHP articles.