Laravel 5.6如何在共享主机上通过cPanel进行托管

3

如何在共享主机上通过cpanel托管一个 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

代码片段的意义是什么? - Kurund Jalmi
7个回答

3
您有两种可用的方法,其中一种需要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);

我刚刚尝试了SSH方法,但返回了“ln: failed to create symbolic link ‘public_html/public’: No such file or directory”错误。 - Hiroki
@Hiroki 确保你先删除 public_html,然后执行 ln -s ~/laravel/public ~/public_html - ollieread

0
如果您的共享主机团队非常支持您,那么有一个简单的方法:将文件上传到public_html文件夹中。如果您没有SSH访问服务器的权限,请联系您的托管团队,并要求他们将您的域名指向public_html/public文件夹作为根文件夹。然后请他们通过SSH执行以下命令。
composer install

如果您想提高性能,请向他们提供以下文章中列出的四个命令。

https://www.techalyst.com/links/read/112/boosting-laravel-performance-in-production-server


0

Laravel 5.6 需要 PHP 7

首先检查您的共享主机是否支持 Cpanel(PHP Selector)中的 PHP 7,如果是,但您有其他项目使用 PHP 5,并且您不想更改默认的 PHP 版本,则可以在 .htaccess 文件中使用以下内容:

例如:public_html/abc/.htaccess

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

然后 PHP 7 就可以工作了,你可以在共享主机上使用 Laravel 5.6 进行开发。


0
laravel -> all laravel file

public_html -> move all folder & file on *public* file laravel to *public_html*

change your index.php on public html
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';

别忘了将你的PHP版本更改为7.2


0

在谷歌上搜索后,我发现您需要获取public文件夹的内容,该文件夹中有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中定义函数,然后点击链接来执行此操作。


0

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

  1. 在托管上创建一个子域并将其映射到文件夹,例如:"abc"
  2. 在文件夹 "abc" 中上传 Laravel 项目 zip 文件(包括 vendor 文件夹),然后解压缩它
  3. 将子域映射到 Laravel 的 public 文件夹,即 "abc/public"
  4. 创建数据库和用户,并将该用户分配给具有所有权限的数据库
  5. 将 DB 转储导入到上面创建的数据库中
  6. 在 Laravel 的 .env 文件中添加 DB 用户名/密码

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


-2

嗯,共享主机不支持php 7,而laravel 5.6依赖于它。你们有找到解决方法吗?我在bluehost上被困在laravel 4.x上已经几个月了。


共享主机支持您想要的所有配置。 - Nasz Njoka Sr.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接