在Apache环境下部署ThinkPHP项目时,需特别注意DocumentRoot参数的设置。这个参数值必须指向包含入口文件index.php的公共目录,通常为项目中的public文件夹。
配置文件 | 关键参数 | 示例值 |
---|---|---|
httpd.conf | DocumentRoot | /var/www/project/public |
.htaccess | DirectoryIndex | index.php index.html |
通过修改route.php配置文件可实现智能路由识别。建议添加默认路由规则:Route::get('/', 'index/index'); 这样既能直接访问域名时自动跳转指定控制器,又不影响其他路由的正常解析。
// application/route.phpuse think\Route;Route::get('/', 'index/index');
不同服务器环境需采用差异化配置策略: