简体   繁体   English

将Laravel-5项目从Localhost移至服务器

[英]Taking Laravel-5 project from Localhost to server

I am new to laravel framework. 我是laravel框架的新手。 Recently I have made a simple blog type website. 最近,我做了一个简单的博客类型的网站。 In localhost it working good without any problems, if any problem arises then I used to do composer update , composer dump-autoload , etc. localhost它运行良好,没有任何问题,如果出现任何问题,那我就可以做composer updatecomposer dump-autoload等。

But when I migrate it to the server got the following error. 但是,当我将其迁移到服务器时,出现以下错误。 What is this error, should I have to run composer update again? 这是什么错误,我是否必须再次运行composer update If yes then how can I run it on my server. 如果是,那么如何在服务器上运行它。 I have no idea on this matter, please help me. 我对此事一无所知,请帮助我。

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

And the next error is: 下一个错误是:

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

I am doing this project in Laravel5. 我正在Laravel5中做这个项目。 If the error was due to index.php then here is my index.php : 如果错误是由于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);

My main project directory is starting with CMS folder. 我的主要项目目录从CMS文件夹开始。 In the same CMS directory I have a index.php and inside the CMS folder I have an app , bootstrap , config , database , vendor folder and many. 在同一个CMS目录中,我有一个index.php ,在CMS文件夹中,我有一个appbootstrapconfigdatabasevendor文件夹等等。 When I remove all code of index.php and write <?php echo "Hello World"; ?> 当我删除index.php所有代码并编写<?php echo "Hello World"; ?> <?php echo "Hello World"; ?> and go to my site somedomain.com I get "Hello World "`` as output. <?php echo "Hello World"; ?>并转到我的网站somedomain.com我得到"Hello World ”作为输出。 How to solve this error? 如何解决这个错误?

First of all, if you like to run your laravel project on a shared host this should be possible. 首先,如果您想在共享主机上运行laravel项目,则应该可以。 Just upload the whole project including the vendor dir to your server. 只需将整个项目(包括vendor目录)上传到您的服务器。

Make sure that your domain points to the public folder inside your laravel project. 请确保您的域名指向public的laravel项目中的文件夹。
If you like to access your project inside a sub folder of your domain (eg http://your-domain.com/your-app/ ) then you need to make some changes. 如果您想在域的子文件夹(例如http://your-domain.com/your-app/ )中访问项目,则需要进行一些更改。 Here is a how to for Laravel 4 which should work for L5 too. 这里有一个如何为Laravel 4应为L5工作了。

If the error still occurs then make sure that your folders and files are in the correct upper/lower case. 如果错误仍然存​​在,请确保您的文件夹和文件使用正确的大写/小写形式。 If your localhost is a windows machine (which makes no difference between upper and lower case) and you move to a linux server (which differentiates upper and lower case) you can run into problems. 如果您的localhost是Windows计算机(大写和小写没有区别),而您转移到Linux服务器(区分大小写),则可能会遇到问题。 Therefore make sure your paths and filenames in your code are in the same upper/lower case as they are on your server. 因此,请确保代码中的路径和文件名与服务器上的大小写相同。

To avoid problems like this I can recommend the use of Laravel Homestead . 为避免此类问题,我建议您使用Laravel Homestead It's a virtual machine environment for laravel development. 这是用于laravel开发的虚拟机环境。

Which server do you use ? 您使用哪个服务器? Check if your path is defined in the config folder. 检查您的路径是否在config文件夹中定义。 Also install all the dependencies in the right folder and copy all of them to your server. 还将所有依赖项安装在正确的文件夹中,然后将所有依赖项复制到您的服务器。 You can check this link for a proper installation https://laracasts.com/series/laravel-5-fundamentals . 您可以检查此链接以进行正确的安装https://laracasts.com/series/laravel-5-fundamentals Most likely you're missing some files. 您很可能会丢失一些文件。 Try reinstalling the project. 尝试重新安装该项目。

I guess you will need to change the base path from localhost to your domain in order for it to work. 我想您需要将基本路径从localhost更改为您的域,以使其工作。 This worked for me though when i got the same error. 这对我有用,但是当我遇到相同的错误时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM