2016-08-19 171 views
0

我想在共享主機上部署laravel 5.2。Laravel 5共享主機部署問題

我將laravel核心應用程序文件夾安裝在public_html文件夾(/../public_html或/ home/username)上面的一個級別。

我提取了laravel核心公用文件夾(public)中的文件,並將index.php文件指向上面的根(/../laravel-app/bootstrap/autoload.php和/)的laravel核心應用程序文件夾。 ./laravel-app/bootstrap/app.php)。

網站主頁正在工作,但網頁鏈接正在返回一個404,它不會拉入任何CSS或JS。

關於如何解決這個問題的任何想法?

注意要點:我在PHP 版本5.6 我laravel應用程序內改變的文件權限/存儲到777 我刪除了文件夾中的public_html服務器 htaccess的FIL就是Apache

+0

你使用'資產() '在你的代碼中鏈接資源? (css,js,img ...) –

+0

爲什麼你刪除.htaccess?這個文件對於路由很重要。當你沒有正確的.htaccess,那麼鏈接不會發送到Laravel index.php,所以它試圖訪問文件夾/文件,這不存在(所以你得到404) –

+0

好的。那麼如何獲得一個新的.htaccess文件? – Chigoziri

回答

2

好友只要按照這個教程,我試了一下,它工作得很好!

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

順便說一句,你甚至都不需要這句話後半句

如果沒有您的服務器上已經安裝的作曲家,你可以輕鬆地搶項目目錄。

在我來說,我做了以下內容: 配售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文件,圖標和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 <[email protected]> 
*/ 

/* 
|-------------------------------------------------------------------------- 
| 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); 
+0

如何運行壓縮命令?我沒有通過SSH訪問服務器。另一件事。我做了教程中列出的所有內容(據我所知,仍然出現錯誤)。但是,我沒有.htaccess文件(我錯誤地刪除了它)。 – Chigoziri

+0

上傳本地版本的'.htaccess',並且關於您不需要的作曲家命令,約定會說:作曲家更新只能在本地運行,在這種情況下只能作曲。鎖是什麼將被改變,在你的情況下,你也必須上傳供應商文件夾,不要忽略它:) –

+0

這就是問題所在。我錯誤地刪除了它(.htaccess文件)。我該怎麼辦? – Chigoziri