Laravel 5共享托管部署问题

时间:2016-08-19 01:57:56

标签: php apache .htaccess laravel laravel-5

我正在尝试在共享主机上部署laravel 5.2。

我将laravel core app文件夹安装在public_html文件夹(/../public_html或/ home / username)上方。

我解析了laravel核心公共文件夹(public)中的文件,并将index.php文件指向laravel core app文件夹上面的一个根目录(/../laravel-app/bootstrap/autoload.php和/ .. /laravel-app/bootstrap/app.php)。

网站主页正在运行,但网页链接返回404并且它不会拉入任何css或js。

关于如何解决此问题的任何想法?

注意事项: 我在php ver 5.6上 我将laravel-app / storage中的文件权限更改为777 我删除了public_html文件夹中的.htaccess文件 服务器是apache

1 个答案:

答案 0 :(得分:2)

Buddy只是按照本教程,我尝试过它并且工作得很好!

https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.5lywcjmnn

是的,你甚至不需要在这句话之后的最后一部分

  

如果您的服务器上尚未安装composer,则可以轻松将其抓取到项目目录中。

就我而言,我做了以下事情: 将laravel项目放在public_html之外作为lara文件夹

然后我有了这个htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

在public_html里面我有.htacess:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^awesome
RewriteRule ^(.*)$ awesome/$1 [L]

其中awesome是包含htacess(列出下来)和index.php,favicon和robots.txt的目录:

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

最终更改在index.php中:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

/* die(__DIR__);  /home/{YOURHOST}/public_html/awesome */
require __DIR__.'/../../lara/bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../../lara/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);