Laravel 不显示 index.php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21386249/
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 not showing index.php
提问by php12345
I'm new in Laravel, I made virtual host http://example.comand installed Laravel in folder of this domain but when I try to access this domain I get this
我是 Laravel 的新手,我创建了虚拟主机http://example.com并将 Laravel 安装在该域的文件夹中,但是当我尝试访问该域时,我得到了这个
回答by The Alpha
This is your VirtualHost
setup
这是你的VirtualHost
设置
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/example" ## <-- pointed to wrong folder
ServerName example.com
ServerAlias www.example.com
ErrorLog "logs/www.example.com.domain-error.log"
</VirtualHost>
You didn't point it to the public
folder. It should be (These are minimum requirements)
您没有将其指向public
文件夹。应该是(这些是最低要求)
<VirtualHost *.80>
DocumentRoot "C:/xampp/htdocs/example/public"
ServerName example.com
</VirtualHost>
You should point it to the public
folder because index.php
is inside public
folder.
您应该将其指向public
文件夹,因为index.php
它在public
文件夹内。
I use this kind of setup
我使用这种设置
<VirtualHost laravel4.dev>
DocumentRoot "D:/xampp/htdocs/laravel4/public"
ServerName laravel4.dev
</VirtualHost>
Corresponding setup in windows/system32/drivers/etc/host
file is
windows/system32/drivers/etc/host
文件中对应的设置是
127.0.0.2 ci.dev
127.0.0.3 laravel4.dev ## <-- This is for current vHost
127.0.0.4 symcom.dev
So, I can navigate to my site on local host using http://laravel4.dev
(dev
for development)
因此,我可以使用http://laravel4.dev
(dev
用于开发)在本地主机上导航到我的站点
回答by Steve Bauman
That's exactly what you should be seeing. When you click the 'public' folder do you see a 'You have arrived.', with the laravel logo? If so, then you've correctly installed laravel.
这正是你应该看到的。当您单击“公共”文件夹时,您是否会看到带有 Laravel 徽标的“您已到达。”?如果是这样,那么你已经正确安装了 laravel。
The 'public' folder, is the main folder in which the actual public has access to your website when you put it on a server. You'll want to do one of two things here:
“public”文件夹是当您将网站放在服务器上时,实际公众可以访问您网站的主要文件夹。你会想要在这里做两件事之一:
The simple (but insecure) way:
简单(但不安全)的方式:
Add a .htaccess file to the root of your web folder containing this text:
将 .htaccess 文件添加到包含以下文本的 Web 文件夹的根目录:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
This will make all requests go to www.example.com/public, but only show www.example.com in the URL.
这将使所有请求转到 www.example.com/public,但仅在 URL 中显示 www.example.com。
The harder (but correct) way:
更难(但正确)的方法:
This completely depends on which provider you will be hosting your website on, but on Godaddy and others, you have the option of selecting the root folder of your website. In this case you'd select the 'public' folder to be the root. I cannot give you a tutorial on that because this option ranges on availability on every hosting provider.
这完全取决于您将在哪个提供商上托管您的网站,但在 Godaddy 和其他网站上,您可以选择网站的根文件夹。在这种情况下,您将选择“公共”文件夹作为根目录。我无法为您提供相关教程,因为此选项适用于每个托管服务提供商的可用性。
EDIT: I should add just in case. When you add content to your site, such as CSS/images/files and everything the public will have access to, make sure you put them in the public folder.
编辑:我应该添加以防万一。当您向站点添加内容时,例如 CSS/图像/文件以及公众可以访问的所有内容,请确保将它们放在公共文件夹中。
回答by ptantiku
You VirtualHost configuration needs to point DirectoryRoot
further into public/
directory, so it can use its .htaccess
and index.php
inside that directory.
您的 VirtualHost 配置需要DirectoryRoot
进一步指向public/
目录,以便它可以在该目录中使用它的.htaccess
和index.php
。