本地主机 xampp 上禁止 Laravel 访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35245825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Access forbidden on localhost xampp
提问by Shivam
I just got stuck in the very begining. I have installed laravel and when i run php artisan serv command then this(Laravel development server started on http://localhost:8000/) line appears but when i access it through browser(http://localhost:8000/) then the following error gets displayed.
我刚开始就被卡住了。我已经安装了 Laravel,当我运行 php artisan serv 命令时,会出现这个(Laravel 开发服务器在http://localhost:8000/ 上启动)行,但是当我通过浏览器(http://localhost:8000/)访问它时显示以下错误。
Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster. Error 403 localhost Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.2
禁止访问!您无权访问所请求的对象。它要么受读保护,要么无法被服务器读取。如果您认为这是服务器错误,请联系网站管理员。错误 403 本地主机 Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.2
Please help me out. Any help would be greatly appreciated. I am beginner in laravel.
请帮帮我。任何帮助将不胜感激。我是laravel的初学者。
回答by BKF
Follow the steps below to create a virtual host:
按照以下步骤创建虚拟主机:
Change to your XAMPP installation directory (typically, C:\xampp) and open the " httpd-vhosts.conf " and " httpd-xampp.conf " files in the apache\conf\extra\ subdirectory using your favourite text editor. Add these lines into both files with the following directives:
切换到您的 XAMPP 安装目录(通常为 C:\xampp)并使用您喜欢的文本编辑器打开 apache\conf\extra\ 子目录中的“httpd-vhosts.conf”和“httpd-xampp.conf”文件。使用以下指令将这些行添加到两个文件中:
<VirtualHost *:80>
DocumentRoot "C:\Users\Shivam\Desktop\laravel_project\blog"
ServerName blog.dev
<Directory "C:\Users\Shivam\Desktop\laravel_project\blog">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This contains two virtual host configuration blocks:
这包含两个虚拟主机配置块:
The first block is the default or fallback virtual host, which is used for all requests that are not matched by subsequent blocks. The second block sets up a virtual host named wordpress.localhost. The DocumentRoot directive specifies the directory to be used when serving requests for this virtual host (in this case, the WordPress installation directory), while the ServerName directive specifies the custom domain name for the virtual host.
第一个块是默认或回退虚拟主机,用于所有后续块不匹配的请求。第二个块设置一个名为 wordpress.localhost 的虚拟主机。DocumentRoot 指令指定在为该虚拟主机(在本例中为 WordPress 安装目录)提供请求时要使用的目录,而 ServerName 指令指定虚拟主机的自定义域名。
To add more virtual hosts, simply duplicate the second virtual host block and modify the port number, DocumentRoot and ServerName directives as per your requirements. For example, if you want to use SSL with your custom domain name, you can add a new virtual host block for port 443. If you plan to have a large number of virtual hosts with very similar configuration, consider using wildcard-based subdomains with your virtual hosts.
要添加更多虚拟主机,只需复制第二个虚拟主机块并根据您的要求修改端口号、DocumentRoot 和 ServerName 指令。例如,如果您想将 SSL 与您的自定义域名一起使用,您可以为端口 443 添加一个新的虚拟主机块。如果您计划拥有大量配置非常相似的虚拟主机,请考虑使用基于通配符的子域你的虚拟主机。
Restart Apache using the XAMPP control panel for your changes to take effect.
使用 XAMPP 控制面板重新启动 Apache 以使您的更改生效。
At this point, your virtual host is configured. However, if you try browsing to the wordpress.localhost domain, your browser will show a failure notice, since this domain does not exist in reality. To resolve this, it is necessary to map the custom domain to the local IP address. To do this, open the file C:\windows\system32\drivers\etc\hosts and add the following line to it:
此时,您的虚拟主机已配置完毕。但是,如果您尝试浏览 wordpress.localhost 域,您的浏览器将显示失败通知,因为该域实际上不存在。要解决此问题,需要将自定义域映射到本地 IP 地址。为此,请打开文件 C:\windows\system32\drivers\etc\hosts 并向其中添加以下行:
127.0.0.1 blog.dev
This takes care of mapping the wordpress.localhost domain name to the local machine, which always has the IP address 127.0.0.1
这负责将 wordpress.localhost 域名映射到本地机器,它的 IP 地址始终为 127.0.0.1
回答by Roj Vroemen
It seems to me that you already have Apache running on port 8000.
在我看来,您已经在端口 8000 上运行了 Apache。
Try running the serve command like this:
php artisan serve --port=9000
尝试像这样运行 serve 命令:
php artisan serve --port=9000
After it's running navigate to http://localhost:9000
运行后导航到http://localhost:9000