php 如何配置apache web服务器来部署laravel 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35501041/
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
How to configure apache web server to deploy laravel 5
提问by Bora
I would like to serve my Laravel application on my local apache web server. However, I am having issues.
我想在我的本地 apache Web 服务器上为我的 Laravel 应用程序提供服务。但是,我遇到了问题。
To test if the application I made would work on an apache server, I have created a new very simple application which contains two routes.
为了测试我制作的应用程序是否可以在 apache 服务器上运行,我创建了一个新的非常简单的应用程序,其中包含两条路由。
Route::group(['middleware' => 'web'], function() {
Route::get('/', function() { return view('myview'); });
Route::get('/link', function() { return view('myotherview'); });
});
When I enter my public
directory from my browser, it works fine, it connects to the /
route. But when I give a link to the other route (/link
), and try enter that route, it gives me 404 not found the error. Here is the link I give in my myview
view to reaching /link
route:
当我public
从浏览器输入我的目录时,它工作正常,它连接到/
路由。但是,当我提供指向另一条路线 ( /link
)的链接并尝试输入该路线时,它给了我 404 not found 错误。这是我myview
认为到达/link
路线的链接:
<a href="{{ url('/link') }}">Go</a>
When I show the source of the page, the above line is rendered as localhost/mylaravelapp/public/link
.
当我显示页面的源代码时,上面的行呈现为localhost/mylaravelapp/public/link
.
I have researched this issue on the internet and there are a couple of suggestions on enabling apache mod_rewrite. I have also done that by typing a2enmod mod_rewrite
. However this isn't seemed to be working, getting the same result. How can I solve this issue?
我已经在互联网上研究过这个问题,并且有一些关于启用 apache mod_rewrite 的建议。我也通过键入a2enmod mod_rewrite
. 但是,这似乎不起作用,得到了相同的结果。我该如何解决这个问题?
My laravel version is 5.2, apache 2.4.7 and I am using xubuntu 14.04.
我的 Laravel 版本是 5.2,apache 2.4.7,我使用的是 xubuntu 14.04。
回答by Damien Pirsy
This is the usual configuration that works for me (same OS, Apache and Laravel version as you have).
Edit the apache2 config file (it should be under /etc/apache2/sites-available/000-default.conf
), adding this:
这是适用于我的常用配置(与您拥有的操作系统、Apache 和 Laravel 版本相同)。编辑 apache2 配置文件(它应该在 下/etc/apache2/sites-available/000-default.conf
),添加以下内容:
Alias /yourdir /var/www/html/yourdir/public/
<Directory "/var/www/html/yourdir/public">
AllowOverride All
Order allow,deny
allow from all
</Directory>
Where "yourdir" is obviously your folder under the /var/www/html
path. Restart your server after you modified the config file
其中“yourdir”显然是/var/www/html
路径下的文件夹。修改配置文件后重启服务器
sudo service apache2 restart
sudo service apache2 restart
Now your public/.htaccess
should be something like:
现在你public/.htaccess
应该是这样的:
RewriteEngine On
RewriteBase /yourdir/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Authorization Headers
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]