2016-08-19 111 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