💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Web 服务器 典型地使用前端控制器将 web 服务器接收到的 HTTP 请求汇集到一个单独的 PHP 文件。下面的文档说明了如何通知你的 web 服务器将接收到的 HTTP 请求发送到 PHP 前端控制器文件。 ## PHP built-in server Run the following command in terminal to start localhost web server, assuming `./public/` is public-accessible directory with `index.php` file: ``` php -S localhost:8080 -t ./public/ ``` ## Apache 配置 确保 `.htaccess` 和 `index.php` 这两个文件位于同一个可公开访问的目录中。这个 `.htaccess` 文件应当包含以下代码: ``` RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [QSA,L] ``` 为了保证 `.htaccess` 的重写(rewrite)规则能正常生效,务必确保你的 Apache 虚拟主机开启了 `AllowOverride` 选项。 ``` AllowOverride All ``` ## Nginx 配置 这是一个例子,在 Nginx 虚拟主机上针对域名 `example.com` 的配置。它监听80端口上的入境(inbound)HTTP 连接。它假定一个PHP-FPM服务器在端口9000上运行。你需要将 `server_name`, `error_log`, `access_log`, 和 `root` 这些指令修改成你自己的值。其中 `root` 指令是你的应用程序公共文件根目录的路径;你的 Slim 应用的 `index.php` 前端控制器文件应该放在这个目录中。 ``` server { listen 80; server_name example.com; index index.php; error_log /path/to/example.error.log; access_log /path/to/example.access.log; root /path/to/public; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; } } ``` ## HipHop Virtual Machine Your HipHop Virtual Machine configuration file should contain this code (along with other settings you may need). Be sure you change the `SourceRoot` setting to point to your Slim app’s document root directory. ``` Server { SourceRoot = /path/to/public/directory } ServerVariables { SCRIPT_NAME = /index.php } VirtualHost { * { Pattern = .* RewriteRules { * { pattern = ^(.*)$ to = index.php/$1 qsa = true } } } } ``` ## IIS 务必确保 `Web.config` 和 `index.php` 这两个文件位于同一个可公开访问的目录中。 这个 `Web.config` 文件必须包含以下代码: ``` <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="slim" patternSyntax="Wildcard"> <match url="*" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration> ``` ## lighttpd Your lighttpd configuration file should contain this code (along with other settings you may need). This code requires lighttpd &gt;= 1.4.24. ``` url.rewrite-if-not-file = ("(.*)" => "/index.php/$0") ``` This assumes that Slim’s `index.php` is in the root folder of your project (www root).