【问题标题】:How do I set up LAMP without the forbidden message when viewing my site?在查看我的网站时如何设置 LAMP 而不显示禁止消息?
【发布时间】:2026-02-13 17:15:02
【问题描述】:

我使用 Linux Mint 16 + 最新的 LAMP + Laravel。

当我尝试通过“localhost”或“127.0.0.1”查看我的网站时遇到此错误。

Forbidden

You don't have permission to access / on this server.
------------------------------------------------------
Apache/2.4.6 (Ubuntu) Server at 127.0.0.1 Port 80

我的设置如下:

在 /etc/主机名上

NameServer ynwlocalwebserver

在 /etc/hosts 上

127.0.0.1       localhost
127.0.1.1       ynwlocalwebserver

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

我只有一个名为“ynwlocalwebserver.conf”的站点启用它的当前内容是:

NameVirtualHost *:80

<VirtualHost *:80>

  ServerName ynwlocalwebserver
  DocumentRoot /home/ynwmint/ynw/public
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  <Directory /home/ynwmint/ynw/public>
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

<VirtualHost *:80>

  ServerName localhost
  DocumentRoot /home/ynwmint/ynw/public
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  <Directory /home/ynwmint/ynw/public>
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

“/home/ynwmint/ynw/public”中的文件夹 ynw 就是 Laravel 项目。

我把 public 文件夹的 chmod 设置为 777(同时)并在 www-data:www-data 下chown

我做错了什么,或者我还需要检查什么?

谢谢。

【问题讨论】:

    标签: apache2 lamp


    【解决方案1】:

    Apache 2.4 在配置方面有一些小的变化。

    这个:

    ServerName ynwlocalwebserver
    DocumentRoot /home/ynwmint/ynw/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    <Directory /home/ynwmint/ynw/public>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

    应该改成这样:

    <VirtualHost *:80>
    
        ServerName ynwlocalwebserver
        DocumentRoot /home/ynwmint/ynw/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        <Directory /home/ynwmint/ynw/public>
            Options +Indexes +FollowSymlinks + MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    
    </VirtualHost>
    

    此外,为了增加安全性,您可能需要此目录规则:

    <Directory />
        Options FollowSymlinks
        AllowOverride None
    </Directory>
    

    来源:http://httpd.apache.org/docs/2.4/upgrading.html

    【讨论】:

    • “Options +Indexes +FollowSymlinks + MultiViews”有语法错误,但“要求所有授权”修复了它。谢谢。
    最近更新 更多