A server for hosting websites has many layers. First is the web server software that deals with connecting to the internet, listening for requests for a website, and running some program to fulfill its request. The program has to know from the server what’s being requested, and typically middleware delivers the message. Then, the program might need to load or store some data from a database. In this case, middleware would also probably be used between the program and the database.
The Apache HTTP server is an example of a system organized like this. There are two sets of layers involved- the topmost layer is the Apache server, and the bottom of the first layer is PHP. The middleware between the two is a module for Apache called mod_php; when Apache receives a request for a dynamic page, it can delegate the generation of this page to a PHP program. When the PHP program finishes, it’s able to return some HTML back to Apache through mod_php. The second layer is between PHP and the MySQL database. In order for PHP to make requests and communicate with the database, it uses an extension called php_mysqli, which is another example of middleware.
Each of these middlewares are bound by API’s defined by Apache’s module system and PHP’s extension system, respectively. Apache also has to conform to the Hypertext Transfer Protocol (HTTP), so the modules cannot do anything that would violate HTTP when interacting with Apache.
One major benefit of having middleware in these cases is that it allows each of these systems to be easily expandable and some parts to be interpolable. What this means is that if you want to use a different language with Apache such as Python or Perl, then you only need to use different middleware that is compatible with Apache. This is much better than having to create a new web server whenever you want to use a different language.
The middleware layer is somewhat established. There are a few modules commonly used at the Apache module layer- for instance, “mod_rewrite” and “mod_php.” Updates to these modules are released to fix bugs and occasionally to add new features. However, because the software is licensed as open source, anyone can create new modules to suit their needs. This makes the middleware layer static because it has some facets that are usually used, but also volatile because it is open source.