ph-bookshelf-wiki/web-server.md

59 lines
2.1 KiB
Markdown
Raw Normal View History

2023-01-29 10:24:15 +08:00
# Web Server
[Apache]: https://httpd.apache.org/
[.htaccess]: https://httpd.apache.org/docs/2.4/howto/htaccess.html
[mod_rewrite]: https://httpd.apache.org/docs/current/mod/mod_rewrite.html
ph-Bookshelf 原始版本是在 [Apache Web Server][Apache] 环境下开发的,并有用到 [Apache] 的 [.htaccess]。
你也可以在其它的环境下使用 **ph-Bookshelf**,只需要一些简单的路径重写设置。
2023-03-27 19:16:12 +08:00
## 对于你自己管理的的 Apache 服务器
2023-01-29 10:24:15 +08:00
要想在 [Apache] 中使用 **ph-Bookshelf**,你只需要确认一些简单的设置:
确认 [mod_rewrite] 已经打开。这一般可以通过以下简单的命令确认:
2023-03-27 19:16:12 +08:00
```shell-session
2023-01-29 10:24:15 +08:00
# a2enmod rewrite
```
2023-03-27 19:16:12 +08:00
> 如果你使用的是旧版 Apache<small>一般存在于会被叫做 httpd 的 apache</small>module 配置或许会在服务器里,这时候,大概你的 Apache 的配置文件(通常为 `/etc/apache2/httpd.conf`{.lang-url} 或者 `/etc/httpd/httpd.conf`{.lang-url}),找到以下行并取消注释它:
2023-01-29 10:24:15 +08:00
>
2023-03-27 19:16:12 +08:00
> ```apacheconf
2023-01-29 10:24:15 +08:00
> # uncomment this line
> LoadModule rewrite_module libexec/apache2/mod_rewrite.so
> ```
然后,为你的 ph-Bookshelf 目录配置允许路径重写:
2023-03-27 19:16:12 +08:00
```apacheconf
2023-01-29 10:24:15 +08:00
<Directory /path/to/your/ph-Bookshelf>
AllowOverride All
</Directory>
```
至此,你已经完成了 ph-Bookshelf 需要的所有配置。
你无需在 [Apache] 配置文件中配置路径重写规则,它已经存在在了 ph-Bookshelf 项目根目录下的 .htaccess 当中。
2023-03-27 19:16:12 +08:00
## 对于 Nginx 或其它各种各样的 Web 服务器
一般的 Web 服务器都支持 URL 重写,但它们可能有自己的配置方式。
你可以参考 ph-bookshelf 项目下的 `.htaccess` 文件,在你的 Web 服务器配置上面自己配置 URL 重写规则。
> 作为参考,这是 ph-bookshelf 在 Nginx 下的 URL 重写规则:
>
> ```nginx
> location / {
> rewrite ^(.*)$ /index.php?p=$0;
> }
> ```
>
> 在 nginx 中,将这一部分添加到你的 `server {}`{.lang-nginx} 块中就可以完成配置。
## 对于使用 php 网站托管服务的用户
如果你是使用 php 站点托管,请询问你的托管服务商是否支持 [Apache] [.htaccess] 的使用。