
ThinkPHP6在虚拟主机上的部署:绕过php think run命令
许多用户在虚拟主机环境下部署ThinkPHP6时,会遇到无法访问的问题,主要原因在于DocumentRoot配置错误以及伪静态规则缺失。本文将指导您如何正确配置,无需使用php think run命令即可正常运行ThinkPHP6项目。
关键问题在于虚拟主机DocumentRoot的指向。ThinkPHP6的DocumentRoot应该指向public目录,而不是public/index.php。
以下为正确的虚拟主机配置示例:
立即学习“PHP免费学习笔记(深入)”;
<code class="apache"><VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/public" <!-- 注意此处指向public目录 -->
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost></code>为了实现伪静态,需要添加以下Rewrite规则:
<code class="apache">RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]</code>
完成以上配置后,您的ThinkPHP6项目应该能够在虚拟主机环境下正常运行,无需再依赖php think run命令。 请根据您的实际路径调整/var/www/public路径。
以上就是ThinkPHP6虚拟主机配置错误导致无法访问?如何正确配置DocumentRoot和伪静态?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号