我在
/home/tr/api
下构建了一个PHP Slim应用程序。一切都很好,如果我通过 symfony server:start
启动服务器并通过 localhost:8000
访问它。
我创建了一个虚拟主机文件:
<VirtualHost *:80>
ServerName api
ServerAdmin [email protected]
DocumentRoot /home/tr/api/public
<Directory />
AllowOverride all
</Directory>
<Directory /home/tr/api/public>
Options FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/api.error.log
CustomLog ${APACHE_LOG_DIR}/api.access.log combined
</VirtualHost>
并在
.htaccess
下创建了一个/home/tr/api/public
文件,如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
当然,我在hosts文件中将
api
映射到了127.0.0.1
。
然后我尝试在浏览器中访问该网站,但它给我“禁止:您无权访问此资源。服务器无法读取 htaccess 文件,拒绝访问以确保安全”。
我查看了日志文件,发现以下行令人困惑:
[Sun Dec 24 19:30:34.753938 2023] [core:crit] [pid 681] (13)Permission denied: [client 127.0.0.1:54368] AH00529: /home/tr/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/tr/' is executable
这非常令人困惑,因为服务器似乎试图在 /home/tr 中查找 .htaccess 文件,而不是我的虚拟主机配置文件中指定的
/home/tr/api/public
。
我在这里遗漏了什么吗?
这是与我的虚拟盒子相关的权限问题。将
755
设置为我的 /home/tr/
后,现在工作正常了。