laravel 5.6托管共享主机上的cpanel

时间:2018-03-26 06:51:45

标签: php jquery laravel

主持人如何在共享托管上托管Laravel 5.6个应用。

有人可以给我一个想法

require __DIR__.'/../vendor/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__.'/../bootstrap/app.php';

/*
\#########my index.php file

7 个答案:

答案 0 :(得分:2)

您有两种方法可用,一种需要ssh访问。在任何情况下,您都不会将整个Laravel目录放入public_html目录。

SSH访问

如果您有SSH访问权限,则需要执行以下操作;

  • 登录您的帐户并转到您的主目录cd ~
  • 删除public_html目录
  • 现在您要将Laravel应用上传到~/laravel
  • 现在您需要将public_html重新创建为符号链接cd ~ && ln -s laravel/public public_html

无SSH访问

如果您没有SSH访问权限,则需要执行以下操作;

  • 将您的laravel安装上传到~/laravel(在public_html上方)
  • 之类的地方
  • ~/laravel/public目录的内容复制到public_html
  • 更改路径以匹配新目的地

您的新~/public_html/index.php应如下所示;

<?php

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

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| 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 great to relax.
|
*/

require __DIR__.'/../laravel/vendor/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__.'/../laravel/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);

答案 1 :(得分:0)

谷歌搜索后,我发现你必须获取具有index.php文件的公共文件夹的内容并将其放在public_html中。现在我们必须更改index.php文件的内容,即只提供app.php和autoload.php的正确链接,require __DIR__.'/<project_folder_name>/vendor/autoload.php'$app = require_once __DIR__.'/<project_folder_name>/bootstrap/app.php';也会更新你的.env文件并检查它应该是工作如果它不是你必须使用php artisan cache:clearphp artisan route:clear清除缓存和路由,你可以使用ssh或在web.php中定义函数,然后点击链接

答案 2 :(得分:0)

嗯。共享主机不支持larave 5.6所依赖的php 7。你们找到解决方法了吗?我已经在bluehost上使用laravel 4.x停留了几个月。

答案 3 :(得分:0)

Laravel 5.6需要PHP 7

首先在Cpanel(PHP选择器)中检查共享的托管支持PHP 7,如果可以,但是您还有其他PHP 5项目,并且您不想更改默认的php版本,则在其中使用它.htaccess个文件

例如: public_html / abc / .htaccess

RewriteEngine on
AddHandler application/x-httpd-php71 .php

然后PHP 7工作,您就可以在共享主机上使用Laravel 5.6

答案 4 :(得分:0)

max_created = Entity.objects.filter(
    identifier=OuterRef('identifier')
).order_by('-created').values('created')[:1]

Entity.objects.filter(
    created=Subquery(max_created)
)

别忘了将您的php版本更改为7.2

答案 5 :(得分:0)

在共享主机上托管的最简单方法

  1. 在主机上创建一个子域并将其映射到文件夹,例如:“abc”
  2. 在文件夹“abc”中上传 Laravel 项目 zip(带有供应商文件夹)然后解压
  3. 将子域映射到 laravel 的公共文件夹,即“abc/public”。
  4. 创建一个数据库和用户并将该用户分配给具有所有权限的数据库
  5. 在上面创建的数据库中导入数据库转储。
  6. 在 laravel .env 文件中添加数据库用户/密码。

注意:如果您遇到任何由于缓存删除目录 bootstrap/cache 中的文件 config.php。

答案 6 :(得分:-2)

您可以在共享主机

的public_html(root)中尝试以下结构

创建一个名为laravel的文件夹,并将除公共文件夹以外的所有文件和文件夹放在其中。

将公共目录的所有文件和文件夹直接复制到public_html根目录。您的文件夹结构应如下所示

public_html
- Laravel (Folder with all the laravel files and folders except public)
- css (from public folder)
- js (from public folder)
- .htaccess(from public folder)
- index.php (from public folder)
- robots (from public folder)

将index.php编辑为以下

require __DIR__.'/laravel/vendor/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__.'/laravel/bootstrap/app.php';

/*