
ThinkPHP6在虚拟主机上的部署:绕过php think run命令
许多用户在虚拟主机环境下部署ThinkPHP6时,会遇到无法访问的问题,主要原因在于DocumentRoot配置错误以及伪静态规则缺失。本文将指导您如何正确配置,无需使用php think run命令即可正常运行ThinkPHP6项目。
关键问题在于虚拟主机DocumentRoot的指向。ThinkPHP6的DocumentRoot应该指向public目录,而不是public/index.php。
以下为正确的虚拟主机配置示例:
立即学习“PHP免费学习笔记(深入)”;
ServerAdmin webmaster@localhost DocumentRoot "/var/www/public" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined Options Indexes FollowSymLinks AllowOverride All Require all granted
为了实现伪静态,需要添加以下Rewrite规则:
RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]
完成以上配置后,您的ThinkPHP6项目应该能够在虚拟主机环境下正常运行,无需再依赖php think run命令。 请根据您的实际路径调整/var/www/public路径。











