June 12, 2007

Get started developing Web applications in Linux


A Linux distribution is a popular environment for developing applications for the web. Whether you are designing a personal Web page or a multi-page, database-driven, AJAX-enabled Web site, Linux has tools to make the task easier.

Any article on Web development warrants mention of the Linux, Apache, MySQL, and PHP, Perl, or Python (LAMP) platform. LAMP is the culmination of a Linux distribution, together with the Apache Web server, the MySQL database, and one (or more) of the scripting languages.

The components of the LAMP platform offer developers a complete environment for developing and hosting complex Web apps. Scripting languages are the glue between the Web servers and databases. They ensure that all requests for information received by Web servers are transfered to the databases.


PHP is an object-oriented, server-side scripting language used to build dynamic Web sites. It's often compared to Microsoft's ASP.NET, but can run on several Web servers and can talk to popular databases, across all major operating systems. According to Netcraft, in April 2007, about 20 million domains were on servers with PHP installed. The TIOBE programming community index lists PHP as the forth most popular programming language after Java, C, and C++. WordPress, a popular blogging engine, and MediaWiki -- which drives Wikipedia -- are both written in PHP.

PHP is a pre-processor, which means it reads a file with specific instructions written in PHP, processes the page and outputs another page to the Web browser. Here's a simple example of a PHP program:

echo 'Hello, World!';

A page with these lines will go through PHP, which converts the echo statement into normal text. A normal page will contain a mixture of HTML tags and PHP syntax, enclosed within the <?php and ?> delimiters. Anything not contained in php delimiters is not processed.

When you decide to write an application in PHP, you may find the PHP Extension and Application Repository (PEAR) project particularly useful. PEAR is a repository of libraries and components that you can use for PHP development to add functionality like parsing RSS, connect to an IMAP server, or generate images on the fly. PHP's Wikipedia page has a lot of details about PEAR's features and a comprehensive list of its libraries.

PHP doesn't have an in-built debugger. But PHP programmers have two very powerful debuggers to choose from: The Advanced PHP Debugger (ADP) and Xdebug. Once included in a script, both APD and Xdebug can profile and analyze the scripts execution. Xdebug can also plug into development environments like Eclipse.

PHP is also useful for writing template engines. A Web template system produces Web pages by manipulating data in a database with the template. Smarty is a popular template system written in PHP.

PHP has a comprehensive manual, which covers everything from installation and PHP basics right up to using several functions and PHP internals. New users should also read the PHP FAQ and subscribe to the appropriate mailing list. There's also a manual for Smarty which covers installation and usage.


Perl is an object-oriented, cross platform language known for its text extraction capabilities. Web developers and others took to Perl since it had features not available in other languages at the time of its introduction in 1987. For example, it could process large amounts of text and generate easy to read reports in no time.

Part of Perl's popularity stems from its extensive add-on modules from Comprehensive Perl Archive Network (CPAN), which houses over 11,000 modules. CPAN helps programmers locate modules and scripts that aren't included in the standard Perl distribution.

Perl borrows several features and syntax from other languages like C, sed, and Lisp. Perl includes a special syntax for writing regular expressions, which is now being used by several other languages, like PHP, through the Perl Compatible Regular Expression library. Perl is also the most popular language for writing Common Gateway Interface (CGI) scripts. CGI is a standard that defines how information is exchanged between a script and a Web server.

Here's the sample "Hello, World" program in perl:

print '<b>Hello, World!</b>';

This produces the same result as in PHP, the "Hello, World", in bold font. Again, this is just a very simple demo.

Perl has an in-built debugger. Perl's -d switch makes the script run under the Perl source debugger. Within the environment you can do common debugging tasks, like setting breakpoints and changing variable values. Perl also has the -w option, which warns of any questionable code it encounters while running the program.

Perl's documentation Web site hosts a FAQ and tutorials to covers everything from installation to regular expressions to using Perl's objected-oriented features. You'll also find the Perl Beginner's Web site useful. It has links to a number of online Perl tutorials, Perl book reviews, articles, mailing lists, forum boards, wikis, and IRC channels that revolve around Perl.

Popular blogging software, Slash, which runs Slashdot, is written in Perl. So is the software that runs LiveJournal.


Ruby is another powerful and popular scripting language that has a syntax similar to Perl. The Ruby FAQ suggests that Perl developers will feel at home with Ruby's syntax. Ruby also supports Perl-like regular expressions. Ruby's object-oriented features are similar to Smalltalk.

A sample Ruby program to print the "Hello, World" message:

puts 'Hello, World!'

Like the other scripting languages we've covered, Ruby is cross-platform. Similarly Ruby too has repositories of libraries and applications. The Ruby Application Archive (RAA) is home to several libraries and also hosts some documentation.

Though RAA also hosts some applications built on Ruby, like games, the real place to find them is RubyForge. RubyForge hosts over 2500 projects. Ruby has a package manager, called RubyGems, that defines the format for distributing Ruby programs and libraries. It also acts as a download manager and its usage is similar to apt-get.

Ruby has a built-in debugger that can be called with the -rdebug option. But there's a more popular debugger, ruby-debug. Like other debuggers, it can set catch points and breakpoints as well as display the contents of the stack.

The easiest way to learn Ruby is to use the interactive tutorial. The Ruby Web site also has lots of tutorials for absolute beginners to programming as well as programmers migrating from other languages. Also on the site are a few in-depth manuals and books. The Ruby On-Page Web site, lists snippets of Ruby code along with an explanation to help users get familiar with Ruby's syntax.


The Python programming language is popular with first time programmers since it focuses on readability. Python is object-oriented and multi-platform. Google and YouTube both use Python, which speaks a lot about the language's usability.

Python achieves the high levels of readability by using English keywords and in its use of white space. In programming languages, blocks of codes have traditionally been enclosed in braces ({}) and punctuation (;). Python relies on indentation.

For example, a function in C that calls other functions depending on the type of user would look like:

void foo(int x) {
if (newuser == 0) {
help ();
} else {

The same function in Python would look like this:

def foo(x):
if newuser == 0:

Notice the difference in the Python version? Some developers criticize Python for forcing them to stick with strict syntax, because if the Python program isn't properly indented, it would misbehave or fail to run. Other developers prefer Python's strict syntax.

Python has a debugger, pdb, which available as a module. It can set breakpoints and also be invoked as a script to debug other scripts.

Like all popular languages, there's no dearth of Python documentation. If you are new to Python, the detailed official tutorial, along with the online edition of Dive Into Python book and How to Think Like a Computer Scientist: Learning Python, have enough information to get you started.


Novell's Mono project provides a set of tools that can run code written in .Net. The Mono tools are compliant with the Ecma International standard and can run on several platforms.

The Mono tools are under heavy development and the latest version provides the core API of .NET Framework 2.0. Mono also bundles a Visual Basic component to allow VB apps to run under Linux, even those that have been compiled under Windows. There's also a VB compiler that can allow .Net programmers to write and compile .Net code just like they would under Windows.

The best way to get started with Mono is by using its VMware image that contains everything a developer needs to get started migrating Windows applications to Linux. The Mono Migration Analyzer (MoMA) tool helps identify issues that programmers may have when porting their .Net application to Mono. There's a guide to using MoMA on its home page.

Mono's FAQ answers several questions regarding the project and its capabilities. We have a quick tutorial for people interested in running .Net application with Mono. Mono also has a number of mailing lists that discuss various aspects of Mono and its tools.


Java applications, either standalone or Web applets that run in a Web browser, need a special environment to run. The Java Runtime Environment (JRE) packages provides such an environment and includes a Java Virtual Machine (JVM) to translate Java code into a form that's executable by the host machine.

Sun has made available JREs for Linux, which allow you to run standalone code as well as Web applets. Since Java wasn't open sourced until recently, free software enthusiasts depended on the free (as in freedom) GNU Compiler for Java (GCJ) to compile their Java code. GCJ has a detailed manual and several tutorials for compiling and debugging Java programs.

To allow developers to add dynamic content to a Web site, Sun developed the Java Servlet API. Servlets are scripts like PHP. To generate these servlets Sun wrote the JavaServer Pages (JSP) specification. To run these servlets, the Apache foundation developed Apache Tomcat. Tomcat is a runtime environment for Web applications in Java.

Application servers and frameworks

Depending on the language you're developing on Linux offers several application servers and Web frameworks for quick deployment and control. An application server is a centralized piece of software responsible for delivering Web applications to client computers or devices.

JBoss is a cross-platform Java based application server. To help developers get started using JBoss, the project has loads of documentation in the wiki. You can also get help on the forum board and several mailing lists.

Another popular application server is Zope, written in Python. Zope has several components available that can be plugged into the application server to extend its Web site building capability. Zope includes its own Web server but can also be used with the Apache Web server. Another good thing about Zope is that it can be managed from a Web browser. Lots of documentation is available including HOWTOs and a free Zope book.

Web developers also rely on Web application frameworks to assist them in the process of creating Web sites. A Web application framework provides libraries for several common tasks like accessing databases, managing sessions, etc. Using frameworks a Web developer can save a lot of time since many frameworks also encourage code reuse.

Ruby on Rails (RoR) is a Web application framework written in Ruby. RoR helps developers in reusing code and avoiding unnecessary repetition. The Ruby Web site has lots of documentation laced with examples. The RoR Web site also hosts several screencasts that demo its Web site creation speed. For example, there's a demo that creates a Weblog from scratch in 15 minutes.

Django is another Web application framework that's gaining in popularity. Django is written in Python and bundles a light-weight Web server for development and testing, a templating system, tools for generating syndication feeds and sitemaps, and several other components. Django can run under many Web servers including Apache with the mod_python module and supports MySQL, PostgreSQL and SQLite databases. Django has an under development book available online for free.

Then there's the Zend framework based on PHP. It provides several coponents and modules for developing PHP based applications. The modules in the Zend framework can do authentication, manage sessions, handle internationalization, and use several PHP core and Web services introduced in PHP 5. The Zend programmer's manual covers these modules and their usage in detail.

Web development apps

If you are putting together a simple Web page or are new to writing Web scripts, you can choose from several "what you see is what you get" (WYSIWYG) programs for HTML. Here's a brief look at some of them, which we've also covered in detail.

Quanta Plus is a Web development environment based on KDE, but it works well under GNOME and other desktop environments too. Quanta features a set of buttons for HTML tags that you'd use often, and wizards for creating forms, tables, and other items.

Depending on what type of page you're creating, Quanta offers several default templates. These templates are skeleton structures of an HTML document, PHP script, and other document types supported by Quanta. Quanta can access files remotely using FTP, SSH, SMB, NFS, WebDAV, and other protocols.

If you want to maintain older versions of the projects you've created with Quanta, it can hook up with Cervisia. Cervisia is a frontend to Concurrent Versions System (CVS), a popular revision control program. To compare and review changes in two versions of a Web page created with Quanta, it can also work with Kompare, a frontend to the diff utility which compares two files and outputs differences between the two.

Another popular choice is the Bluefish editor, which can be used for writing HTML pages or scripts in many languages. It supports PHP, Perl, Python, C, SQL, and several others. You can edit multiple documents in Bluefish at a time, each document in its own tab. Bluefish also includes several toolbars and a function browser for PHP, Python, CSS, and formatting HTML. The function browser helps you find various tags and insert them into the document. If the tag requires attributes, Bluefish will pop up a dialog with the possible attributes so you can fill them in.

You also get wizards for creating tables, frames, forms, and a user customizable 'Quick Bar' that allows users to add their most frequently used buttons. Bluefish can also generates a page of thumbnails from a directory of pictures and links the images to the thumbnails. It can run in both GNOME and KDE.


If you've got Web development on your mind, there's no better development platform than Linux. There are several choices of Web scripting languages to choose from. Select the language depending on the type of application you project. If you are new to Web scripting every language has lots of well-categorized documentation that steps you through the various stages of learning.

You still get several choices, even if you want to deploy applications written in languages not native to Linux. .Net and Java are two examples of popular languages that can be written and hosted using Linux as a platform. Several languages also have Web frameworks that speed up the process of Web site creation. Also available are application servers that assist in putting together the various components required in a Web site. Finally if you need help with some HTML, you've got options there as well.


  • Web Development
  • Linux