【问题标题】:laravel 5.6 host to cpanel on shared hostinglaravel 5.6 主机到共享主机上的 cpanel
【发布时间】:2018-09-04 05:54:54
【问题描述】:

如何将Laravel 5.6 应用托管到共享主机上的 cpanel。

谁能给个思路

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

【问题讨论】:

  • code sn-p有什么意义?

标签: php jquery laravel


【解决方案1】:

您有两种可用的方法,一种需要 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 确保先删除public_html,然后再删除ln -s ~/laravel/public ~/public_html
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    composer install
    

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

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

    【讨论】:

      【解决方案4】:

      嗯。共享主机不支持 larave 5.6 所依赖的 php 7。各位有没有找到解决办法。我已经在 bluehost 上使用 laravel 4.x 卡住了几个月。

      【讨论】:

      • 共享主机支持你想要的各种配置
      【解决方案5】:

      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 合作

      【讨论】:

        【解决方案6】:
        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

        【讨论】:

          【解决方案7】:

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

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

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

          【讨论】:

            猜你喜欢
            • 2020-01-16
            • 2019-12-08
            • 2017-07-09
            • 1970-01-01
            • 2015-06-17
            • 2020-08-02
            • 2018-05-26
            • 1970-01-01
            • 2018-06-21
            相关资源
            最近更新 更多