If you’re like most people, you’ve probably don’t spend much time thinking about where websites come from.
After all, if you were born in the 90’s or later, the web has always just been there.
And even if you're older, you've probably accepted the internet as an essential part of your life by now.
Most people certainly don’t think of a website as data...
...and they probably don’t think of web servers, ever.
But web servers are the reason that data ends up as perfectly-placed pixels on your iPhone. Without them, there wouldn’t be any websites as we know them.
So, in this article, we’re going to talk about web servers.
What is a web server? How do they work? And which ones are most popular?
And then we’ll guide you to some resources you can use if you’re looking to set up a web server for yourself on your VPS.
What is a web server?
A web server is a computer running software that accepts and respond to World Wide Web client requests. The computer (server) stores all the info needed for a website, and the software processes requests and sends the requested document to the website’s visitors using Internet protocols.
Web servers use the HTTP (Hypertext Transfer Protocol) protocol to serve files and web pages in response to a request from a user via an HTTP client (usually a web browser like Google Chrome or Safari).
The web server typically runs all the time to serve a client’s request in various outputs like HTML, XHTML, and XML, which are otherwise known as web pages. Before serving web pages to the client, it needs to collect some other resources, like CSS or JavaScriptfiles, images and fonts.
How does a web server work?
Let’s talk about how a web server works. But before we talk about how a web server works, we need to understand the term URL.
What is a URL?
A URL (Uniform Resource Locator) is a unique address for a file that’s stored on a web server.
The file may be an HTML file, a CSS file, an image file, or any other file related to a web page, and is referred to as a resource for a web server.
A URL has the following elements:
- The protocol (http/https) used to access a resource. Want to know more about HTTPS?
- An IP address or domain name to identify the web server.
- A port number on which the web server is running. The default port number is 80, and in that case, there’s no need to include the port number in the URL.
- The path where the resource (file) is located in the web server.
When you type a URL into your web browser, the server listed in the URL responds with the requested page.
What does the web server do?
In the background, web browser breaks the URL in the three parts: the protocol, the IP address or domain name, and the resource path in the web server.
The web browser contacts the web server indicated in the URL using HTTP/HTTPS protocol to request the web page.
The web server then finds the requested document and all the necessary files and sends them back to the web browser via HTTP. If the web server can’t find the requested page or document, it returns a 404 status code instead.
And that’s it— that’s how a web server works to serve you “the internet.”
Apache & Nginx: The most popular web servers
The 2 most popular web servers are open source software— which means that they are free to download, install and use to power your websites.
The most widely used web server is the Apache Web Server, which powers about 44% of all websites. Not far behind it, though, is Nginx (pronounced engine-X) which has made big gains in the past few years.
Each of these options are generally deployed in a software stack built on the Linux operating system— the LAMP stack (Adobe) or the LEMP stack (nginx).
Set up a web server on your VPS: LAMP vs LEMP
Both of these software stacks are built on the Linux operating system and are comprised of the OS (Linux), a web server software, a database software, and a programming language.
What is a LAMP stack?
A LAMP stack is a framework for developing a web application or dynamic websites using Linux as the operating system, Apache as the Web server, MySQL/MariaDB as the database and PHP as the scripting language.
The P was traditionally meant to stand for PHP, but depending on requirements for a particular application, sometimes Perl or Python is substituted for PHP.
Each component of a LAMP stack is open source and freely available to anyone who wishes to use this stack to develop and deploy their web application or a dynamic website.
Let’s walk through each component of a LAMP stack.
Linux
Linux is a highly reliable and secure operating system preferred all over the world by universities, government organizations, small and large business organizations, and even for personal use.
There are a wide variety of Linux distributions available to choose from—Red Hat, CentOS, Ubuntu, and Debian, to name a few.
Apache
Apache is a free web server software distributed by the Apache Software Foundation and is widely used in all Linux distributions.
Apache is an HTTP server that is fast and secure. It's so popular because you can deploy Apache to everything from small static websites to large web applications with thousands or even millions of daily users.
MySQL/MariaDB
MySQL is a free, relational database management system licensed under GNU GPL. It is not fully open source but instead released by Oracle under a dual GPL and commercial license.
If you want a 100% open-source database management system, then choose MariaDB, which was forked by some developers of MySQL due to concerns over its acquisition by Oracle Corporation. The MariaDB foundation distributes MariaDB and guarantees it will remain open source.
PHP/Perl/Python
PHP, Perl, and Python are object-oriented, server-side scripting languages. Any logic you put in these languages run inside the web server and the results can be embedded into an HTML page before sending it to the web browser.
PHP is widely popular among developers due to its natural learning curve and availability of ready-made extensions—many free and open source web development frameworks like Laravel, Symphony, Zend framework are written in PHP.
Plus, the most popular content management systems (CMS), like WordPress, Drupal, and Joomla are all based on PHP.
What is a LEMP stack?
LEMP stack is a variation on the LAMP stack that is growing in popularity.
In a LEMP stack, you replace Apache with Nginx, which is represented by the letter E (to keep our acronyms nice and simple).
Nginx is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, and it can also act as a load balancer. The LEMP stack very popular and has been gaining ground on LEMP over the past few years.
LAMP or LEMP— which is better?
There’s no clear “winner” between LAMP and LEMP and it often comes down to your specific use case.
The Nginx system is event-driven where the Apache system is process-driven. That means Nginx leaves a smaller impression in the system, allowing it to handle a higher load of HTTP requests.
And that’s lead to an increase in the use of the LEMP stack among developers.
The LAMP stack, however, is still more common and perhaps a bit easier to get running. It may even be preferable for some simple WordPress installations running on limited resources.
For a full breakdown of the two options, check out our comparison article on Apache vs Nginx.
Getting started with web servers:
Okay…
Now that you know you know what a web server is, it’s time to get started building your own little home on the internet!
If you’re ready to get started self-hosting your website, we’ve got some great resources to get you started: