ThinkPHP6虚拟主机配置错误导致无法访问?如何正确配置DocumentRoot和伪静态?

thinkphp6虚拟主机配置错误导致无法访问?如何正确配置documentroot和伪静态?

ThinkPHP6在虚拟主机上的部署:绕过php think run命令

许多用户在虚拟主机环境下部署ThinkPHP6时,会遇到无法访问的问题,主要原因在于DocumentRoot配置错误以及伪静态规则缺失。本文将指导您如何正确配置,无需使用php think run命令即可正常运行ThinkPHP6项目。

关键问题在于虚拟主机DocumentRoot的指向。ThinkPHP6的DocumentRoot应该指向public目录,而不是public/index.php。

以下为正确的虚拟主机配置示例:

立即学习PHP免费学习笔记(深入)”;

<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>
登录后复制

为了实现伪静态,需要添加以下Rewrite规则:

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
登录后复制

完成以上配置后,您的ThinkPHP6项目应该能够在虚拟主机环境下正常运行,无需再依赖php think run命令。 请根据您的实际路径调整/var/www/public路径。

以上就是ThinkPHP6虚拟主机配置错误导致无法访问?如何正确配置DocumentRoot和伪静态?的详细内容,更多请关注php中文网其它相关文章!

https://www.php.cn/faq/1232644.html

发表回复

Your email address will not be published. Required fields are marked *