Server-side Scripts and Databases

Notes

The focus of this class is client-side web technologies, but since every web application requires both client-side and server-side software you will need to become familiar with server-side software as well. This short list of server-side technologies is far from complete, but it will give you some idea of what kinds of software are used on the server side of a web application.

Web servers

Apache HTTP server is a very popular web server that runs on many different operating systems, including various Unix-style systems and Microsoft Windows. It is free (no charge) and open source software. You can read about it at httpd.apache.org.

IIS (Internet Information Services) is Microsoft's web server. It runs on the Windows operating system. You can read about it at www.iis.net.

Custom web servers are programs that implement the HyperText Transfer Protocol (HTTP). They can be embedded in devices such as printers and routers to provide an easy-to-use remote interface.

Programming languages and environments

CGI (Common Gateway Interface) is a standard that defines how a web server can call external programs that generate web pages. Virtually any programming language can be used with CGI, but a couple of commonly used languages are Perl (especially in the early days of the World-Wide Web) and Python.

When a web server receives a request for a document, it looks at the URL to see if it refers to a static file or to a CGI script. If the URL refers to a script (or program), the web server starts a new process to run the program. The CGI program then uses input from the request to generate a document by writing to its standard output stream. The web server takes the output of the CGI program and returns it to a client.

One advantage of CGI is that it is very flexible. Almost any programming language can be used to write the program, and the program can make use of other programs available on the server.

The flexibility of CGI is also a disadvantage. If the web server and CGI mechanism are not configured correctly, an intruder can use CGI to break into the server. Another diadvantage of CGI is the cost (in terms of CPU time and memory) of creating a new process to run the CGI program.

CGI was once the primary mechanism for server-side programming, but now it has given way to other kinds of programming environments, especially web server modules.

You can read more about CGI at the Wikipedia CGI article: http://en.wikipedia.org/wiki/Common_Gateway_Interface

Web server modules give better performance and require less overhead than CGI. When a web server receives a request for a dynamically generated page from a web server module, it doesn't start a new process. Instead it runs the code for the module as part of the web server process.

PHP was one of the first programming languages to commonly make use of web server modules. You can read about PHP at php.net, with the manual available at http://us3.php.net/manual/en/. You can also use PHP to write CGI scripts, but that is much less common than running PHP as a web server module. PHP code can be embedded in HTML markup in a file, but in many cases it is better to make a clean separation between HTML files and PHP code.

There are also web server modules available for Perl and Python.

Ruby on Rails is a framework that uses the Ruby programming language. Ruby is a "pure" (everything is an object) object-oriented scripting language. Ruby on Rails is advertised as "favoring convention overconfiguration" and makes extensive use of the MVC (Model-View-Controller) paradigm. You can read about Ruby on Rails at www.rubyonrails.org.

Java servlets and JSP are technologies that allow web content to be generated by Java programs. JSP is analogous to using PHP as web server module because it allows Java code to be embedded in HTML files. Java servlets are similar to CGI programs in some respects. However, Java servlets execute inside a Java Virtual Machine (JVM), so a new process isn't created for each request as is the case with CGI.

ASP .NET is Microsoft's web application framework that allows programmers to build web applications using the .NET framework.

Content management systems

Content management systems (CMSs) are used to create, organize, and publish a web site's information. There is a wide range of CMSs available, ranging from free, open source systems to very expensive commercial systems. Some examples of open source CMSs are Joomla (www.jomla.org), Plone (plone.org), and Drupal (drupal.org).

Database systems

Many web sites use a database system to store information. As with CMSs, there is a wide range of systems available ranging from commercial systems to free, open source systems. Examples of commercial systems include Oracle's database systems and Microsoft's SQL Server. MySQL is a popular database system that has both commercial and non-commercial licenses. SQLite (www.sqlite.org) is a free SQL database engine that requires no configuration and requires a small amount of code.

Many database systems currently in use, including all of the ones mentioned above, use a language called SQL (Structured Query Language). You can read about SQL at www.sql.org and www.sqlzoo.net.

Most programming languages and frameworks used for web applications have libraries available for working with database systems and executing SQL queries. Ruby on Rails, in particular, uses a concept called Object-Relational Mapping (ORM) that maps objects in a program to tables in a database, and instance variables in the objects to fields in the database. That concept allows programmers to access the database with a minimal amount of configuration and code.