> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-38-web-servers/di-38.1-jie-apache-web-fu-wu-qi.md).

# 38.1 Apache Web Server

Apache HTTP Server is one of the most widely used web servers in the world, featuring a modular architecture that enhances website functionality through dynamically loaded extension modules. This section covers compilation and installation via Ports, as well as basic configuration.

## Installing Apache

Install using Ports:

```sh
# cd /usr/ports/www/apache24/
# make install clean
```

Or install using the pkg package manager:

```sh
# pkg install apache24
```

After installation, view the package's documentation to understand the necessary configuration and precautions:

```sh
# pkg info -D apache24
```

## Daemon

To have Apache start automatically at boot, configure it as an enabled service.

Set the Apache service to start at boot:

```sh
# service apache24 enable   # Set Apache HTTP Server 2.4 to start automatically at system boot
```

## Starting Apache

After enabling the auto-start configuration, manually start the Apache service and check its running status.

Start the service:

```sh
# service apache24 start   # Start the Apache HTTP Server 2.4 service
Performing sanity check on apache24 configuration:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 198.18.0.103. Set the 'ServerName' directive globally to suppress this message
Syntax OK
Starting apache24.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 198.18.0.103. Set the 'ServerName' directive globally to suppress this message
```

Check the Apache HTTP Server 2.4 service status:

```sh
# service apache24 status
apache24 is running as pid 2068.
```

After the Apache service starts, verify that the web service is responding to requests correctly by accessing `localhost` or the corresponding IP address:

![Apache FreeBSD](/files/dhetO2VDlsHv9Z8KsulY)

## Appendix: Apache Related File Paths

The following are the main file and directory paths for Apache on FreeBSD, for reference during configuration and maintenance.

Directory structure:

```
/usr/local/
├── etc/
│   └── apache24/
│       ├── httpd.conf          # Apache main configuration file (the active configuration)
│       └── httpd.conf.sample   # Sample configuration file (reference template, not directly used)
└── www/
    └── apache24/
        └── data/               # Website root directory (stores web content, such as index.html)
```

Notes:

* The Apache configuration file is located at **/usr/local/etc/apache24/httpd.conf**
* The Apache sample file is located at **/usr/local/etc/apache24/httpd.conf.sample**
* The Apache website root directory is located at **/usr/local/www/apache24/data/**

## References

* The Apache Software Foundation. Apache HTTP Server Documentation\[EB/OL]. \[2026-04-14]. <https://httpd.apache.org/docs/2.4/>. Official Apache HTTP Server documentation, covering configuration directives, modules, and virtual hosts.
* The Apache Software Foundation. Apache HTTP Server 2.4 Release Notes\[EB/OL]. \[2026-04-14]. <https://httpd.apache.org/docs/2.4/new_features_2_4.html>. New features and changes in Apache 2.4.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://book.bsdcn.org/ask/flat/chapter-38-web-servers/di-38.1-jie-apache-web-fu-wu-qi.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.
