2.6 Web Servers

A web server is, at a fundamental level, nothing more than a computer that responds to HTTP requests. The first web server was hosted on Tim Berners-Lee’s desktop computer; later when you begin PHP development in Chapter 12, you may find yourself turning your own computer into a web server.

Real-world web servers are often more powerful than your own desktop computer, and typically come with additional software and hardware features that make them more reliable and replaceable. And as we saw in Section 1.3.6 (and will learn more about in Chapter 17), real-world websites typically have many web servers configured together in web farms.

Regardless of the physical characteristics of the server, one must choose an application stack to run a website. This application stack will include an operating system, web server software, a database, and a scripting language to process dynamic requests.

Web practitioners often develop an affinity for a particular stack (often without rationale). In part of this textbook, you will be using the LAMP software stack, which refers to the Linux operating system, Apache web server, MySQL database, and PHP scripting language. Since Apache and MySQL also run on Windows and Mac operating systems, variations of the LAMP stack can run on nearly any computer (which is great for students). The Apple OSX MAMP software stack is nearly identical to LAMP, since OSX is a Unix implementation, and includes all the tools available in Linux. The WAMP software stack is another popular variation where Windows operating system is used.

Despite the wide adoption of the LAMP stack, web developers need to be aware of alternate software that could be used to support their websites. Besides the LAMP stack, you will be using the MERN stack in the book, which refers to MongoDB database, Express application framework, the JavaScript React framework, and Node.js as the web server and execution environment. Many corporate intranets instead make use of the Microsoft WISA software stack, which refers to Windows operating system, IIS web server, SQL Server database, and the ASP.NET server-side development technologies. Another web development stack that is growing in popularity is the so-called JAM stack, which refers to JavaScript, APIs, and markup.

2.6.1 Operating Systems

The choice of operating system will constrain what other software can be installed and used on the server. The most common choice for a web server is a Linux-based OS, although there is a large business-focused market that uses Microsoft Windows IIS.

Linux is the preferred choice for technical reasons like the higher average uptime, lower memory requirements, and the ability to remotely administer the machine from the command line, if required. The free cost also makes it an excellent tool for students and professionals alike, looking to save on licensing costs.

Organizations that have already adopted Microsoft solutions across the organization are more likely to use a Windows server OS to host their websites, since they will have in-house Windows administrators familiar with the Microsoft suite of tools.

2.6.2 Web Server Software

If running Linux, the most popular web server software is Apache, which has been ported to run on Windows, Linux, and Mac, making it platform agnostic. Apache is also well suited to textbook discussion since all of its configuration options can be set through text files (although graphical interfaces exist).

The open-source nginx is another web server option whose user base is beginning to approach that of Apache.9 Nginx is especially fast for sites with large numbers of simultaneous users requesting static files. For instance, a busy site with dynamic content might make use of Apache to host its PHP pages, but will use nginx on different servers to handle requests for images, JavaScript, and CSS files.

IIS, the Windows server software, is preferred largely by those using Windows in their enterprises already or who prefer the .NET development framework. The most compelling reason to choose an IIS server is to get access to other Microsoft tools and products, including ASP.NET and SQL Server. Chapter 17 covers web server configuration in great detail.

2.6.3 Database Software

The moment you decide your website will be dynamic, and not just static HTML pages, you will likely need to make use of relational database software capable of running SQL queries, as we will begin doing in Chapter 14.

The open-source DBMS of choice is usually MySQL (though some prefer PostgreSQL or SQLite), whereas the proprietary choice for web DBMS includes Oracle, IBM DB2, and Microsoft SQL Server. All of these database servers are capable of managing large amounts of data, maintaining integrity, responding to many queries, creating indexes, creating triggers, and more. The differences between these servers are real but are not relevant to the scope of projects we will be developing in this text.

With the growth in so-called Big Data, nonrelational (also referred to as No-SQL) databases have garnered an increasing larger share of the web database market. Perhaps the most popular of these is the open-source MongoDB, which is part of the so-called MEAN web stack. Nonrelational databases are particularly powerful when working with large, unstructured data that needs to be spread across multiple servers.

In this book, you will be mainly using MySQL Server, though there will be some exposure to MongoDB as well. If you decide to use a different database, you may need to alter some of the queries.

2.6.4 Scripting Software

Finally (or perhaps firstly if you are starting a project from scratch) is the choice of server-side development language or platform. This development platform will be used to write software that responds to HTTP requests. The choice for a LAMP stack is usually PHP or Python. We have chosen PHP due to its access to low-level HTTP features, object-oriented support, C-like syntax, and its wide proliferation on the web.

Other technologies like ASP.NET are available to those interested in working entirely inside the Microsoft platform. Each technology does have real advantages and disadvantages, but we will not be addressing them here.

We should mention the unique case of Node.js, which is both a JavaScript server-side scripting platform analogous to PHP or ASP.NET and at the same time, it is also web server software analogous to Apache or IIS. Node.js is part of the MEAN web stack, and is especially well suited for high-traffic websites. We will be covering Node.js in more detail in Chapter 13.