Novice web developers installing their first LAMP-driven website may stumble over unfamiliar technologies, but with a little Googling and guidance they soon succeed at viewing their own PHP-enabled pages. While reaching this milestone is a crucial first step toward becoming a proficient LAMP developer, it's what occurs next that determines the speed and efficacy with which a developer can create and manage websites. Extras like integrated development environments (IDE) and debugging tools can make a real difference. Here's a variety of software, tips, and best practices that should become part of your daily development regimen.
PHP is particularly attractive to novice developers thanks to its low barrier to entry. After installing the software, you can begin writing PHP scripts using even a simple text editor. But just because you can do something doesn't mean you should, and in fact developing PHP code using just a text editor quickly leads to unforeseen difficulties and poor practices. Instead, consider one of these PHP development frameworks:
Lacking any additional guidance, choosing one IDE over another might seem like quite the conundrum. If you're already comfortable with Emacs or Vim, then continuing to work within the environment you know seems the most effective choice. Alternatively, consider spending time experimenting with both NetBeans and PDT, as the interfaces tend to diverge dramatically, meaning you may tend to prefer one over the other. If PDT happens to be your preference, then it's a good idea to download the Zend Studio trial in order to obtain a better understanding of whether the additional features Zend Studio offers over PDT are worth the admittedly minimal licensing costs.
LAMP, MAMP, or WAMP?Although I refer to LAMP (Linux, Apache, MySQL, PHP) throughout this article, all of the tips described herein are just as applicable to developing MySQL- and PHP-powered websites on Mac OS X and Windows.
Regardless of your experience level, few tasks are more frustrating than tracking down an elusive bug. You owe it to yourself to use every tool at your disposal to minimize the time and effort you put into diagnosing and fixing programming errors. Fortunately, quite a few fantastic utilities are available to help you:
To help novices get their LAMP environment up and running, most beginning LAMP tutorials recommend developers place their PHP scripts in Apache's default document root directory. If you're running Windows, Apache's default document root is likely set to C:/Program Files/Apache Group/Apache/htdocs/, while on Ubuntu the document root is likely /var/www/. Any files placed within this directory are immediately accessible by browsers that visit http://localhost.
This practice works well enough for getting your feet wet, but becomes unwieldy if you simultaneously create and maintain multiple websites. For instance, a quick count indicates I'm managing 112 current and past web projects, approximately 15 of which are under active development. Clearly it's not practical to update Apache's document root every time I want to begin or continue work on a project.
The easy solution to this dilemma involves managing each project within a virtual host. By doing so, you can access each project via its own local web address – for instance, http://gamenomad.localhost.com, http://wjgilmore.localhost.com, and http://workshops.localhost.com.
Configuring a virtual host on CentOS or Ubuntu is easy. Copy the following configuration script into a text file, updating the ServerName, DocumentRoot, and Directory settings, and saving the file to the directory /etc/httpd/conf.d/ under CentOS, or /etc/apache2/sites-available/ under Ubuntu, using a name that makes clear the domain name it is intended to represent. For instance, if you wanted to create the virtual host http://gamenomad.localhost.com, you should name the file gamenomad.localhost.com.conf under CentOS; under Ubuntu you can leave off the .conf extension:
<VirtualHost *> ServerAdmin webmaster@localhost ServerName gamenomad.localhost.com DocumentRoot /var/www/gamenomad.localhost.com <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/gamenomad.localhost.com/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/gamenomad-error.log LogLevel debug CustomLog /var/log/apache2/gamenomad-access.log combined</VirtualHost>
You don't need to understand all of the Apache configuration directives found in this example; it's enough to merely understand that you can use the virtual host settings to define site-specific project characteristics, such as how Apache behaves in accordance with requests and where log information is saved. If you're running CentOS, after saving the file restart Apache by executing the command /sbin/service httpd restart. If you're running Ubuntu, you'll need to first enable the virtual host, then reload Apache:
/sbin/service httpd restart
$ sudo a2ensite gamenomad.localhost.com$ sudo /etc/init.d/apache2 reload
Finally, update your hosts file so that when you call http://gamenomad.localhost.com from your browser, your laptop will know to resolve the address locally. To do so, add the following line to /etc/hosts:
Even if you're eager to jump into building that first website, taking the time to properly configure your development environment will pay off in countless ways, not only in terms of productivity gains, but also from the natural adoption of best practices that come with the integration of the aforementioned technologies and methodologies.
Allowed tags: <a> link, <b> bold, <i> italics