# Server

### What is a server?

A computer that provides services or resources. The programs on that computer makes them servers, jusk like your laptop could be a DB server if you install MySQL and let other computers access into.

<figure><img src="/files/qV65nly3y5lgMXnVPeXB" alt=""><figcaption></figcaption></figure>

### Apache Web Server

<details>

<summary>Install</summary>

```sh
# install apache
yum install httpd

# start apache web server service
service httpd start
service httpd status
```

</details>

<details>

<summary>Logs</summary>

```bash
# view access & error logs
cat /var/log/httpd/access_log
cat /var/log/httpd/error_log
```

</details>

<details>

<summary>Port</summary>

* the default port is 80

</details>

<details>

<summary>Config file: httpd.conf</summary>

`httpd.conf` is a config file used by Apache web server to control how the server responds to incomming requests. The file specifies things like which ports the server should listen on, where the web applications are located, which modules are loaded, and how security should be enforced.

After configuration, remmember restart httpd service to make it work.

#### Apache config file

```bash
# view configuration file
vim /etc/httpd/conf/httpd.conf
```

#### Document root

`DocumentRoot` in httpd.conf specify where to look at first.

```apacheconf
DocumentRoot "/var/www/html"
```

#### Host

{% code title="/etc/hosts" %}

```apacheconf
# multiple domains point to the same IP address
127.0.0.1 localhost
127.0.0.1 www.example.com
127.0.0.1 www.oranges.com
```

{% endcode %}

#### Virtual host

Multiple web site can be hosted in the same server if you configure `virutal hosts` in `httpd.conf`

```apacheconf
<VirutalHost *:80>
    ServerName www.organces.com
    DocumentRoot /var/www/oranges
</VirutalHost>
```

#### Include another conf file

```apacheconf
Include conf/houses.conf
```

</details>

### Nginx web server

```bash
# install Nginx
sudo apt-get install -y nginx

# confirm Nginx is running
ps auwx | grep nginx
```

### Commands

```sh
# check server timezone
# EST
date +%Z
timedatectl

# change timezone to America/New_York
sudo timedatectl set-timezone America/New_York

# update OS
sudo apt-get update
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mamawhocode.gitbook.io/devops/pre-requisite/server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
