2016-04-21 48 views
5

因此,我开发了一个功能齐全的Laravel 5应用程序,并将其部署到我的客户服务器上,运行Apache2,PHP5和MySQL。该应用程序按预期工作,并且URL被正确地重写。 我现在需要简单地将我的应用程序克隆到另一台服务器,该服务器运行的是完全相同的堆栈。问题是我需要将我的应用放在子文件夹中,以便可以通过匹配模式domain2.com/movedApp的URL访问它。在服务器子文件夹中移动Laravel 5应用程序

换句话说: 首先服务器响应:

domain1.com/my/routes 

二服务器需要回应:

domain2/movedApp/my/routes 

我想完全照搬了虚拟主机指令,它的第一台服务器上的工作,在需要的地方添加/movedApp并将RewriteBase添加到.htaccess文件夹中的新文件夹public,但无济于事。

我已经注意到,路由正确地从像URL如下:

domain2.com/movedApp/public/index.php/my/routes 

不过我得到的Apache2的日志资产404错误。

我在此报告我的.htaccess文件位于我工作的Laravel应用程序的public文件夹中。

的.htaccess

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
    </IfModule> 

    RewriteEngine on 

    # Redirect Trailing Slashes... 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^/index.php [L] 

</IfModule> 

我还报告所使用的Web服务器为我的应用程序

default.conf

<VirtualHost *:80> 
     ServerAdmin [email protected] 

     DocumentRoot /var/www/galmaster/public 
     <Directory /> 
       Options FollowSymLinks 
       AllowOverride None 
     </Directory> 
     <Directory /var/www/galmaster/public> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride All 
       Order allow,deny 
       allow from all 
     </Directory> 

     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
     <Directory "/usr/lib/cgi-bin"> 
       AllowOverride None 
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
       Order allow,deny 
       Allow from all 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel warn 

     CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 
+0

你有什么成功吗? – urfusion

+0

是的,我其实有。一有空余时间,我会尽快公布细节。我设法用两个'.htaccess'文件来解决这个问题。 – ibanjo

+0

我发布了一个解答我自己的问题的答案。也许我的解决方案也适合你。 – ibanjo

回答

1

配置文件所以,我一直在使用VirtualHost进行大量的调整,但是我发现的最好的解决方案根本不涉及它们,而且就在这里。

首先要做的就是配置.htaccess文件既应用程序的根文件夹及其公共文件夹。 我发现了一个简单的工作.htaccess文件中this answer,这是我到这里报到:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteRule ^(.*)$ public/$1 [L] 
</IfModule> 

默认.htaccess正常工作,而是为public文件夹。

最后一步是在routes.php正确配置您的路线。解决方法对我来说是相当粗糙的,也许人们可以找到一些更精致的解决方案,但仍然是这样。

// Get base (root) route 
$base_route = basename(base_path()); 

Route::get($base_route, function() { 
    return view('welcome'); 
}); 

Route::get($base_route.'/myRoute', function() { 
    return view('myRoute'); 
}); 

所以基本上你需要在你的应用程序的每一条路线上预先加上$base_route。希望这可以帮助。

+0

我正在尝试您的解决方案,但牵连改变Laravel身份验证,这是很痛苦的。 –

+1

我实际上并不记得不得不摆弄身份验证。你遇到什么问题? – ibanjo

+0

登录前后重定向(例如,生成oauth2令牌)发送到错误的路径,因为我无法编辑auth中间件。 –

相关问题