Building a Home Test Server
Tags: todayilearned, security, codenewbie, sideprojects
Published: 2020-12-11 17:23:27

It's time to build a home server!!!! This series will be what I learned while building and configuring a server at home with the intention of making it close to common configuration standards so I can host sites/applications to test attacks on.

> **Note**: Please take this all with a grain of salt. This is not going to be 100% secure and it is only meant for learning purposes.

<hr>

## <a name="TOC">Table of Contents</a>
 - [Overview](#Overview)
 - [What is LAMP?](#LAMP)
 - [Server Options](#ServerOptions)
  - [What is a Server?](#What_is_a_Server)
  - [Web Server vs HTTP Server?](#WebServerVsHTTPServer)
  - [What is Server-less?](#serverless)
  - [Service Vs Process](#ServerVsProcess)
  - [What are Virtual Hosts?](#VH)


<hr>

## <a name="Overview">Overview</a>

To begin with it is important to know what kind of setup you want do build. As few questions you might ask your self are:
 - Do you want a server in your house of use a serverless system?
 - Do you need an Web server, an HTTP server, or maybe an additional Proxy server?
 - Do you need Virtual Hosts to host multiple web sites?

Originally I was thinking of using serverless solution like AWS, or another cloud based service, but opted for building a LAMP stack because I wanted to start with the basics of hosting an in-house server and then build up from there. This process will involve installing the OS, and then the LAMP software stack in it, and then hardening of the server. 

To be begin with, what is a "LAMP" stack and why use it? 

## <a name="LAMP">What is LAMP?</a>
So, what is LAMP? LAMP (__L__inux, __A__pache, __M__ySQL, __P__HP) is an open source software stack where each component contributes essential capabilities to an application. Though almost any OS, HTTP server, Database Manager, and data processing software could be used that suites your need the LAMP stack "has a classic layered architecture, with Linux at the lowest level followed by Apache, MySQL, and PHP. Although PHP is nominally at the top or presentation layer, the PHP component sits inside Apache." <sup>[3](#L3)</sup> Though there have been a few variations of this software stack developed over the years LAMP remains continuously popular for its historically proven record for delivering high-performance web applications.

Some variations of the LAMP stack are where MySQL is replaced by PostgreSQL and renamed LAPP, a Windows OS equivalent stack known as WAMP where Linux is replaced with Windows, or sometimes just by keeping the original acronym of LAMP but changing the meaning to Linux / Apache / Middleware (Perl, PHP, Python, Ruby) / PostgreSQL to be more flexible to developers.
![LAMP](https://res.cloudinary.com/practicaldev/image/fetch/s--ZeaFDoJT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/LAMPP_Architecture.png/500px-LAMPP_Architecture.png)

>"A high-level look at the LAMP stack order of execution shows how the elements interoperate. The process starts when the Apache web server receives requests for web pages from a user’s browser. If the request is for a PHP file, Apache passes the request to PHP, which loads the file and executes the code contained in the file. PHP also communicates with MySQL to fetch any data referenced in the code.<br />
PHP then uses the code in the file and the data from the database to create the HTML that browsers require to display web pages. The LAMP stack is efficient at handling not only static web pages, but also dynamic pages where the content may change each time it is loaded depending on the date, time, user identity and other factors. <br />
After running the file code, PHP then passes the resulting data back to the Apache web server to send to the browser. It can also store this new data in MySQL. And of course, all of these operations are enabled by the Linux operating system running at the base of the stack." <sup>[3](#L3)</sup>


To learn more about how I setup my LAMP stack see each section in this series listed at the top of the page or continue on for information on different server types and possible setups you can look into for yourself.


{[Back to the ToC](#TOC)}




## <a name="ServerOptions">Server Options</a>
Now that what LAMP is is understood there are a few things what are helpful to consider before getting started when picking the type of server for you setup. The rest of this will touch on those things.


### <a name="What_is_a_Server">What is a Server?</a>
A server is a specific piece of computer hardware/software that provide various functionalities, aka "services", to other programs or devices, aka "clients". 
![Servers](https://dev-to-uploads.s3.amazonaws.com/i/eg7hp13juzmawm7fqd3x.jpg)

Though it doesn't sound complicated upfront, there is a lot that goes into it that we don't see. What's more, there are several types of servers that clients interact with during their time on the Internet; such as, database servers, blade server, cloud server, dedicated server, domain name server, file server, mail server, print server, web server, game server, proxy server, http server, standalone server, local network server, and application server to name a few. <sup>[1](#L1), [2](#L2), [31](#L31)</sup>

![server client restaurant analogy](https://www.clipartkey.com/mpngs/m/235-2355365_server-client-restaurant-analogy.png)

Consider the common client/server restaurant example where a waiter ("server") provides various functions ("services") the restaurant patron ("client") on request. The functions that a waiter ("server") can provide can be any range of functions ("services") that they do or don't specifically perform but have access to, such as requesting a drink from the bar "server", requesting a special order from a chef "server", or requesting a bill from a hostess "server". 

The same theory translates into a computer server(s) where you might request an email from a "mail server", a website from an "application server" or "HTTP server" and data for a website from a "database server". The server takes the request from the client (usually a web browser or email program) and becomes responsible for performing the service and returning the information to the client in a timely manner. And, like a restaurant, a computer can host many servers in one space or separate out each server into its own space, or host, to specialize is one service.

![Client-server model](https://paginas.fe.up.pt/~acbrito/laudon/images/fg_08_11.jpg)

When building a server to host something on it's important to consider the types of servers available and what your need is. There are a lot of servers available and you won't need all of them for a website or a file sharing server, but you'll probably need more than one because each server performs for a specific task or service.

In my set up I'm going to be building a traditionally hosted server stack (or a LAMP stack) where everything shares resources of one computer. In comparison, in a large scale production environment it's common to separate out each server into their own computer, or to virtualize each server within one computer, with their own virtual resources to make troubleshooting easier.

{[Back to the ToC](#TOC)}





### <a name="serverless">What is Serverless?</a>
Serverless is a catchy new way to get applications online, but are there really no servers involved? 
-Short answer: no.
-Long answer: "Serverless is a cloud computing execution model where the cloud provider dynamically manages the allocation and provisioning of servers." <sup>[21](#L21)</sup>

In the traditional hosting style, all parts of an application/web site are hosted on one server. It allowed for IT staff to have full access to control, install, and configure software/hardware as needed. But it also means that IT staff are needed to monitor it and physically protect it. 

![server vs Server-less](https://hackernoon.com/hn-images/1*x_v5NRC3TTMt1MaYl1gMUg.jpeg)

In the server-less hosting style, all parts of an application/web site are split up into different, event-driven, "services" and/or "processes" and the responsibility of their management falls on the (cloud) providers that are hosting the specific service you are using. Being event-driven, a serverless application will only start running when there’s a specific condition or input to trigger it. 
According to Amazon AWS:
> "With serverless computing, infrastructure management tasks like capacity provisioning and patching are handled by AWS, so you can focus on only writing code that serves your customers. Serverless services like AWS Lambda come with automatic scaling, built-in high availability, and a pay-for-value billing model... - all without managing any servers." <sup>[22](#L22)</sup>

For my purpose I will be building a traditional hosting style. The server will be physically in my house, connected to my network, and I will need to monitor it, like IT staff would, to ensure it has its security updates and monitor its logs for malicious actions that I will be testing on it.

{[Back to the ToC](#TOC)}







### <a name="WebServerVsHTTPServer">Web Server vs HTTP Server?</a>
When building a server it's important to understand the difference between two commonly mixed up server types: a web server and an application server. Anymore a lot of websites are dynamic applications and not just static websites. It can be confusing what they need to be functional at the server level when the terms "web server" and "app server" are thrown around with out much understanding what the differences really are and the different services that each offer. 

An __HTTP web server__ handles communication between a client/Browser and server. Specifically, it uses the HTTP protocol to receive HTTP requests and respond back with HTML documents, images, redirects, style sheets, scripts, and text content to list a few. But despite all that, it can't handle more complex/dynamic requests such as Java or C++.<sup>[32](#L32)</sup> For dynamic requests a web server will act as an intermediary and pass the request to the best program to handle it and won't provide any functionality beyond an environment for that server-side program to execute and pass back the generated response(s). A HTTP web server works well for static websites that don't process any information, but for processing information an __application server__ is needed. 

![Basic Server Architecture](https://2.bp.blogspot.com/-Va8XK7sSidg/VLcNqMJ968I/AAAAAAAAB5Y/83cPPJVSV3g/s1600/Web%2Band%2BHTTP%2BServers.png)

An __application server__ is a mixed framework of software that can handle more complex/dynamic software processing requests that web servers can't; such as APIs calls, Java applets, or C++ processing. It's generally positioned behind a web server and in front of a SQL database and it handles the business logic to generate dynamic content that web applications or desktop applications run; "that is, it’s code that transforms data to provide the specialized functionality offered by a business, service, or application." <sup>[34](#L34)</sup>

In general, clients/browsers access applications by communicating with a Web server via HTTP and an Application Server has separate listeners for the HTTP, HTTPS, IIOP, and IIOP/SSL protocols. Though each listener has exclusive use of a specific port number this doesn’t mean that web servers can't deliver dynamic content though CGI (Common Gateway Interface) or plugins that act as a intermediary for a process; nor does it mean that an application server can’t serve up a static website. <sup>[33](#L33)</sup> If the dynamic content is generated using java technologies an application server is generally in use. Furthermore, if the dynamic content is generated by PHP or Perl a web server is generally being used.

{[Back to the ToC](#TOC)}






### <a name="ServerVsProcess">Service Vs Process</a>
When researching server hosting the words "service" and "process" gets tossed around, but what is a "service" and what is a "process"?

A __"process"__ is an instance of a running program, application, script, or executable (.exe program file) that can be running in the foreground or background of a system. It's one, or several, string(s) of executable instructions within its own environment, or application environment, that at any given time can be either running, sleeping, or zombie (completed process or process waiting for its' parent process to pick up the return value).

For example, both the Chrome Browser and Notepad++ are a process (applications/executables). However, Chrome is interesting because it separates each tab into its own instance of that process. In contrast, you can have multiple tabs open in Notepad++ but all of them live in one instance of the Notepad++ process.![my task manager](https://dev-to-uploads.s3.amazonaws.com/i/41ysg8x7c3qr3nzy39j1.png) <figcaption>Yes I do have that many instances of Chrome open and wow is it draining on my system, but this is how my ADHD brain tries to function.</figcaption>

A __"service"__, also called a "Daemon" in a Linux environment, is a continuously listening process that runs in the background and provides the service to a client on request. Though a service can have an  associated process with a user interface, they are usually started by the operating system and will run whether or not the associated process is open in the foreground. They don't interact with the desktop, are not interactive, and have no controlling terminal/interface.

For example, the Apache/httpd web server, SSH server, system logger, antiviruses, and your system clock are all services that run in the background even when the user is not logged in. Sure, you can modify settings of these services but they just run and wait for someone to request information from them. 

To see what services and process are running on your system you can:
__On Windows__ Open the task manager. This will give you tabs for viewing running processes (browsers and other programs you are running/interacting with) and services (helpers to the computer or a process).
![task manager](https://dev-to-uploads.s3.amazonaws.com/i/7mry65aahmm9tunakq4h.png)

__On Linux__
To view services run `service --status-all` to view what is currently running.![service list](https://storage.googleapis.com/static.configserverfirewall.com/images/ubuntu/ubuntu-list-service.png)
To view processes run `ps` for a small list of recently called processes or `top` for a continuously updated and more detailed list of running processes.
![ps command](https://cdn.journaldev.com/wp-content/uploads/2019/01/ps-command.png)
![top command](https://i2.wp.com/www.linuxandubuntu.com/wp-content/uploads/2019/06/top-no-args.png?w=759)

{[Back to the ToC](#TOC)}













### <a name="VH">What are Virtual Hosts?</a>
Using "Virtual hosts" has become a common method for hosting multiple web sites on a single server or system. This is done because it allows one server to share its resources and doesn't require services to use the same host name. 
![Apache Server Virtual Hosts](https://blog.e-zest.com/hs-fs/hub/744339/file-3395200519-jpg/blog-files/apache-virtual-host-configuration-2.jpg?width=518&height=371&name=apache-virtual-host-configuration-2.jpg)

There are 3 types of virtual hosts <sup>[5](#L5)</sup>:
- __IP-based__: meaning that you have a different IP address for every web site.
 - For example, 172.20.30.40 and 172.20.30.50 
- __name-based__: meaning that you have multiple names running on each IP address.
 - For example, blog1.example.com and blog2.example.com or example.com and example2.com
- __port__: meaning that you have multiple ports on an IP address for every web site. 
 - For example, 172.20.30.40:8081 and 172.20.30.40:8080

{[Back to the ToC](#TOC)}



<hr>



Ooooooook! Now that that is all covered it;s time to build this thing! Check out my next blog in this series to see how to set it all up.

![Lets do this!](https://media.giphy.com/media/zaezT79s3Ng7C/giphy.gif)


<hr>

Happy Hacking
![Happy Hacking ^_^](https://media.giphy.com/media/l3vRmVv5P01I5NDAA/giphy.gif)

### Resources:
<a name="L1">1.</a> http://www.scomptec.co.id/cs.htm
<a name="L2">2.</a> https://www.chegg.com/homework-help/describe-client-server-architecture-including-fat-thin-clien-chapter-10-problem-5rq-solution-9780538481618-exc
<a name="L3">3.</a> https://www.ibm.com/cloud/learn/lamp-stack-explained
<a name="L31">31.</a> https://en.wikipedia.org/wiki/Server_(computing)
<a name="L21">21.</a> https://hackernoon.com/what-is-serverless-architecture-what-are-its-pros-and-cons-cc4b804022e9
<a name="L22">22.</a> https://aws.amazon.com/serverless/
<a name="L32">32.</a> https://tools.ietf.org/html/rfc2616
<a name="L33">33.</a> https://docs.oracle.com/cd/E19830-01/819-4712/ablat/index.html#:~:text=The%20Application%20Server%20has%20separate,of%20a%20specific%20port%20number.
<a name="L34">34.</a> https://www.nginx.com/resources/glossary/application-server-vs-web-server/







<figcaption>Please Note: If anything that I have stated is incorrect please let me know what and why. I would love to learn more about what I may not fully understand yet.</figcaption>