> For the complete documentation index, see [llms.txt](https://kanneg881.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kanneg881.gitbook.io/workspace/zuo-ye-xi-tong/mac-os/jia-zhan-mamp/apache.md).

# Apache

## 說明

Apache 伺服器，mac os 原本就有安裝\
不過版本可能不是最新的

## 安裝

以下為安裝步驟

1. 停用 mac 原生的 Apache
2. 安裝 Apache

### 停用 mac 原生的 Apache

暫停原本 mac 的 apache\
`$ sudo apachectl stop`

關閉自動開啟\
`$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null`

### 安裝 Apache

使用 brew 安裝

更新 brew\
`$ brew update`

安裝 httpd\
`$ brew install httpd`

啟動 Apache 服務\
`$ sudo brew services start httpd`

重新啟動 Apache 服務\
`$ brew services restart httpd`

重啟 apache\
`$ sudo apachectl -k restart`

## Apache 設定

編輯 `/usr/local/etc/httpd/httpd.conf` 檔案

將 `Listen 8080` \
改成 `Listen 80`

將 `DocumentRoot "/usr/local/var/www"`\
改成家目錄底下的 www 資料夾\
`DocumentRoot "/Users/yourName/www"`

將 `<Directory "/usr/local/var/www">`\
改成家目錄底下的 www 資料夾\
`<Directory "/Users/yourName/www">`

移除註解\
`LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so`

移除註解並改成\
`ServerName localhost`

移除註解\
`Include /usr/local/etc/httpd/extra/httpd-vhosts.conf`

重啟 apache\
`$ sudo apachectl -k restart`

## 設定 Virtual Host

原本應該有兩個範例，可以把它們註解，保留以下這個

{% code title="/usr/local/etc/httpd/extra/httpd-vhosts.conf" %}

```
<VirtualHost *:80>
  ServerAdmin yourMail@mail.com
  DocumentRoot "/Users/yourName/www"

  <Directory "/Users/yourName/www">
      Options FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>
</VirtualHost>
```

{% endcode %}

## Apache 指令

`sudo apachectl start`\
開啟 apache

`sudo apachectl stop`\
關閉 apache

`sudo apachectl -k restart`\
重啟 apache

## 參考

{% embed url="<https://www.ioa.tw/macOS/Apache.html>" %}

裡面還有其他 apache 相關設定的教學\
作者這篇內容皆參考此篇文章而寫的


---

# 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://kanneg881.gitbook.io/workspace/zuo-ye-xi-tong/mac-os/jia-zhan-mamp/apache.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.
