如何配置Apache Web服务器以部署laravel 5 [英] How to configure apache web server to deploy laravel 5
问题描述
我想在我的本地apache网络服务器上提供Laravel应用程序.但是,我遇到了问题.
I would like to serve my Laravel application on my local apache web server. However, I am having issues.
为了测试我制作的应用程序是否可以在apache服务器上运行,我创建了一个新的非常简单的应用程序,其中包含两条路由.
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.
Route::group(['middleware' => 'web'], function() {
Route::get('/', function() { return view('myview'); });
Route::get('/link', function() { return view('myotherview'); });
});
当我从浏览器输入public
目录时,它可以正常工作,并连接到/
路由.但是,当我提供指向另一条路由(/link
)的链接并尝试输入该路由时,它给我404找不到错误.这是我在myview
视图中提供的到达/link
路线的链接:
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:
<a href="{{ url('/link') }}">Go</a>
当我显示页面源代码时,上面的行呈现为localhost/mylaravelapp/public/link
.
When I show the source of the page, the above line is rendered as localhost/mylaravelapp/public/link
.
我已经在互联网上研究了这个问题,关于启用apache mod_rewrite有一些建议.我也通过输入a2enmod mod_rewrite
来做到这一点.但是,这似乎不起作用,得到相同的结果.我该如何解决这个问题?
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?
我的laravel版本是5.2,apache 2.4.7,我正在使用xubuntu 14.04.
My laravel version is 5.2, apache 2.4.7 and I am using xubuntu 14.04.
推荐答案
这是适用于我的常用配置(与您的OS,Apache和Laravel版本相同).
编辑apache2配置文件(应该在/etc/apache2/sites-available/000-default.conf
下),并添加以下内容:
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:
Alias /yourdir /var/www/html/yourdir/public/
<Directory "/var/www/html/yourdir/public">
AllowOverride All
Order allow,deny
allow from all
</Directory>
其中"yourdir"显然是您在/var/www/html
路径下的文件夹.修改配置文件后,重新启动服务器
Where "yourdir" is obviously your folder under the /var/www/html
path. Restart your server after you modified the config file
sudo service apache2 restart
现在您的public/.htaccess
应该是这样的:
Now your public/.htaccess
should be something like:
RewriteEngine On
RewriteBase /yourdir/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [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]
这篇关于如何配置Apache Web服务器以部署laravel 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!