provides software and services that enable enterprises
Live Chat 1-888-673-6564

Open Source Software Technical Articles

  • Home
  • Search
  • Contact Us
  • Products and Support
  • Services
  • Enterprise OSS Blog
  • Wazi Technical Blog
  • About Wazi
  • Attributions and Licensing
  • Supply Chain Compliance
  • How to Contribute
  • Contributors
  • Resources Library
  • Cloud Services
  • Partners
  • Customers
  • Community
  • Company
  • Careers
  • News and Events

Subscribe to Wazi by Email

Your email:


Enterprise Developer Support 24 x 7, Get a Support Quote Now!


click-here-to-chat-with-an-online-representative

download-oss-discovery

Latest Posts

  • The secret to great reporting with Drupal 7
  • A more colorful LibreOffice unveiled
  • Toward a more colorful LibreOffice
  • Flexible administration with Puppet's Facter and templates
  • Knock for OpenSSH
  • Get more out of phpMyAdmin
  • Image annotation in GIMP, Dia, and OpenOffice Draw
  • Solr, Drupal 7, and faceted search
  • Using FreeNAS' new full disk encryption for ZFS
  • Create distributed storage with Gluster

Connect with Us!

Current Articles | RSS Feed RSS Feed

How to Set Up a LAMP Development Environment

Posted by W. Jason Gilmore on Thu, Sep 22, 2011
  
Email This Email Article  
Tweet  
  

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.



Choose an IDE



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:




    • NetBeans is one of the most used and recognizable IDEs, having been developed since 1996. Although it was originally written as a Java IDE, developers have created a wide variety of plugins for other languages, PHP among them. Among its features you'll find support for PHPDoc, PHPUnit, Symfony, Xdebug, and Zend Framework integration, in addition to the expected array of capabilities such as code highlighting, code folding, and project management.

    • PDT, short for PHP Development Tools, is built atop the open source Eclipse IDE, and offers hundreds of useful professional-grade features, including a project explorer, debugging, syntax highlighting, and code assistance.

    • Zend Studio: Built atop PDT, Zend's flagship PHP IDE expands upon its predecessor's capabilities by adding deep integration with the Zend Framework, code generation, and enhanced JavaScript support. Unlike the other IDEs discussed here, Zend Studio is not freely available; a license costs $299.

    • Vim is an extension of the ubiquitous vi editor, and supports not only PHP, but dozens of programming languages. To learn more about developing PHP applications using Vim, peruse Andrei Zmievski's ZendCon presentation "VIM for (PHP) Programmers."

    • Emacs' PHP Mode brings PHP capabilities to the venerable editor.



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.



Install Debugging Utilities


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:




    • Xdebug: Derick Rethan's indispensable PHP debugging extension not only greatly increases the readability of PHP's error output, it also comes packed with a variety of useful debugging, profiling, and code coverage features.

    • Firebug: Although not directly related to LAMP development, the Firebug Firefox extension becomes irreplaceable as you begin integrating Ajax-driven features into your web applications. Among other features, it provides the ability to review PHP-generated server-side output via a convenient console.

    • FirePHP: The FirePHP Firefox extension ties into the aforementioned Firebug console, providing you with a convenient outlet to log PHP debugging data.

    • Web Developer Toolbar: Available for both Chrome and Firefox browsers, this utility ranks among the most useful you'll find anywhere on the web thanks to its incredible array of features. Among other capabilities you'll be able to use the Web Developer Toolbar to inspect the DOM, disable JavaScript and view cookie data, learn more about inline images, and disable style sheets.

    • mytop: mytop is a MySQL process monitor that mimics the Unix top command.


19a98812-f823-48dc-841e-bf029c63c6d7

Use Virtual Hosts



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:


$ 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:




127.0.0.1 gamenomad.localhost.com

Conclusion

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.

Follow @openlogic
Follow @CloudSwing

This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.Follow @openlogic
Follow @OSCloudServices

This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.
Tags: Linux, Eclipse, MySQL, Apache, PHP, CentOS, Technical, Firefox, NetBeans, Tutorial, Vim, Firebug, Programming, Zend Framework, Chrome, FirePHP, Xdebug, PHPUnit, LAMP, Symfony, mytop, Unix top, Emacs, PHPDoc

Comments

Currently, there are no comments. Be the first to post one!
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics

Loading...
Error sending email
Email sent successfully

Email article
Email To : 
Your name : 
Message : (maximum 200 characters)
Home | Search | Contact Us | Products and Support | Services | Enterprise OSS Blog | Wazi Technical Blog | Resources Library | Cloud Services | Partners | Customers | Community | Company | Careers | News and Events
Products
OpenLogic Exchange (OLEX)
License Compliance Module
OSS Discovery
OSS Deep Discovery
OpenUpdate
Services
Open Source Support
CentOS Support
Scanning & Compliance
Open Source Training
Professional Services
Solutions
Support & Indemnification
Open Source Governance
Open Source Scanning
Open Source Provisioning
Consulting & Training
Contact Us
1-888-673-6564


© 2013 OpenLogic, Inc. All rights reserved.
Site Map  |  Privacy Policy