【问题标题】:Taking Laravel-5 project from Localhost to server将 Laravel-5 项目从 Localhost 带到服务器
【发布时间】:2015-12-12 11:23:55
【问题描述】:

我是 laravel 框架的新手。最近我做了一个简单的博客类型的网站。在localhost 中,它运行良好,没有任何问题,如果出现任何问题,我曾经做过composer updatecomposer dump-autoload 等。

但是当我将它迁移到服务器时出现以下错误。这是什么错误,我应该再次运行composer update 吗?如果是,那么我如何在我的服务器上运行它。我对这个问题一无所知,请帮助我。

Warning: require(/home/somedomain/public_html/CMS/app/http/helpers/backend/helpers.php): failed to open stream: No such file or directory in /home/somedomain/public_html/CMS/vendor/composer/autoload_real.php on line 58

而下一个错误是:

Fatal error: require(): Failed opening required '/home/somedomain/public_html/CMS/app/http/helpers/backend/helpers.php' (include_path='/home/somedomain/public_html/CMS/vendor/phpunit/php-text-template:/home/somedomain/public_html/CMS/vendor/phpunit/php-timer:.:/usr/lib/php:/usr/local/lib/php') in /home/somedomain/public_html/CMS/vendor/composer/autoload_real.php on line 58

我在 Laravel5 中做这个项目。如果错误是由index.php 引起的,那么这里是我的index.php

<?php
/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 */

/*
|--------------------------------------------------------------------------
| 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.
|
*/

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

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

我的主项目目录以CMS 文件夹开头。在同一个CMS 目录中,我有一个index.php,在CMS 文件夹中,我有一个appbootstrapconfigdatabasevendor 文件夹等等。当我删除index.php 的所有代码并写入&lt;?php echo "Hello World"; ?&gt; 并转到我的站点somedomain.com 时,我得到"Hello World"`` 作为输出。如何解决此错误?

【问题讨论】:

  • 确保您的目录结构在本地主机和公共服务器上都匹配。并确保您正在移动所有文件。听起来你至少忘记了一个。
  • 确保您的存储文件夹在 chmod 777 中
  • 它是一个可以运行控制台命令的 vps/专用服务器吗?
  • 是的,您应该再次运行 composer update 以安装所有依赖项
  • @vision,不,不是。除非你可以运行 shell 命令

标签: php laravel laravel-5 hosting


【解决方案1】:

我想您需要将基本路径从 localhost 更改为您的域才能使其正常工作。 当我遇到同样的错误时,这对我有用。

【讨论】:

  • 如果可以的话,试着用解释性的“代码”来改进你的答案
【解决方案2】:

您使用哪个服务器?检查您的路径是否在配置文件夹中定义。 还要在正确的文件夹中安装所有依赖项并将它们全部复制到您的服务器。您可以检查此链接以正确安装https://laracasts.com/series/laravel-5-fundamentals。 很可能您丢失了一些文件。尝试重新安装项目。

【讨论】:

    【解决方案3】:

    首先,如果您想在共享主机上运行您的 laravel 项目,这应该是可能的。只需将包括vendor 目录在内的整个项目上传到您的服务器。

    确保您的域指向您的 laravel 项目中的 public 文件夹。
    如果您想在域的子文件夹中访问您的项目(例如http://your-domain.com/your-app/),那么您需要进行一些更改。这是 Laravel 4 的 how to,它也适用于 L5。

    如果错误仍然存​​在,请确保您的文件夹和文件的大小写正确。如果您的localhost 是Windows 机器(大小写没有区别),而您移动到Linux 服务器(区分大小写),您可能会遇到问题。因此,请确保代码中的路径和文件名与服务器上的大小写相同。

    为避免此类问题,我建议使用Laravel Homestead。这是一个用于laravel开发的虚拟机环境。

    【讨论】:

    • 我已修复错误,但我的链接无法正常工作我收到类似这样的 404 错误 在此服务器上找不到请求的 URL /our-history。
    • 请更新您的原始问题,提供详细信息和对问题的良好描述。
    猜你喜欢
    • 2017-08-25
    • 1970-01-01
    • 2016-02-02
    • 2014-03-31
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多