简体   繁体   English

laravel 5.6托管共享主机上的cpanel

[英]laravel 5.6 host to cpanel on shared hosting

How can a host a Laravel 5.6 app to cpanel on a shared hosting. 如何在共享主机上托管Laravel 5.6应用程序cpanel。

Can someone give me an idea 有人可以给我一个想法

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

You have two methods available, one requiring ssh access. 您有两种方法可用,一种需要ssh访问。 Under no circumstances do you put your entire Laravel directory into the public_html directory. 在任何情况下,您都不会将整个Laravel目录放入public_html目录中。

SSH Access SSH访问

If you have SSH access you'll want to do the following; 如果您有SSH访问权限,则需要执行以下操作;

  • Log into your account and go to your home directory cd ~ 登录您的帐户并转到您的主目录cd ~
  • Delete the public_html directory 删除public_html目录
  • Now you want to upload your Laravel app to ~/laravel 现在您要将Laravel应用程序上传到~/laravel
  • Now you need to recreate public_html as a symlink cd ~ && ln -s laravel/public public_html 现在你需要重新创建public_html作为符号链接cd ~ && ln -s laravel/public public_html

No SSH Access 没有SSH访问权限

If you don't have SSH access you'll want to do the following; 如果您没有SSH访问权限,则需要执行以下操作;

  • Upload your laravel installation to somewhere like ~/laravel (above the public_html) 将laravel安装上传到~/laravel (public_html上方)
  • Copy the contents of the ~/laravel/public directory to public_html ~/laravel/public目录的内容复制到public_html
  • Change the path to match your new destination 更改路径以匹配新目标

Your new ~/public_html/index.php should look like the following; 您的新~/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);

after googling around i found that you have to take content of public folder which has index.php file and put it in public_html. 谷歌搜索后我发现你必须获取具有index.php文件的公共文件夹的内容并将其放在public_html中。 now we have to change the content of index.php file ie just provide the right link of app.php and autoload.php which would be require __DIR__.'/<project_folder_name>/vendor/autoload.php' and $app = require_once __DIR__.'/<project_folder_name>/bootstrap/app.php'; 现在我们必须更改index.php文件的内容,即只提供app.php和autoload.php的正确链接,这将require __DIR__.'/<project_folder_name>/vendor/autoload.php'$app = require_once __DIR__.'/<project_folder_name>/bootstrap/app.php'; also update your .env file and check it should work if it doesnt you have to clear cache and routes using php artisan cache:clear and php artisan route:clear you can do this using ssh or define the function in web.php and then hitting the link 还要更新你的.env文件并检查它是否应该工作如果你不必清除缓存和路由使用php artisan cache:clearphp artisan route:clear你可以使用ssh或在web.php中定义函数然后点击链接

An easy way if your shared hosting team is very supportive for you, Upload your files to public_html folder, and then incase if you donot have ssh access to server, contact your hosting team and ask them to point your domain name to public_html/public folder as root folder. 如果您的共享托管团队非常支持您,将文件上传到public_html文件夹,然后如果您没有ssh访问服务器,请联系您的托管团队并要求他们将您的域名指向public_html / public folder作为根文件夹。 And then ask them to execute following command via ssh 然后让他们通过ssh执行以下命令

composer install

If you want to boost the peformance, please provide them the four commands listed in the following article. 如果您想提高性能,请向他们提供以下文章中列出的四个命令。

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

Umm. 嗯。 Shared hosting does NOT support php 7, which larave 5.6 depends on. 共享主机不支持php 7,larave 5.6依赖于它。 Have you guys found a workaround. 你们有没有找到解决方法? I have been stuck for months with laravel 4.x on bluehost. 我已经在bluehost上用laravel 4.x卡住了好几个月。

Laravel 5.6 requires PHP 7 . Laravel 5.6需要PHP 7

First check your shared hosting support PHP 7 in Cpanel (PHP Selector), if yes but you have other projects which PHP 5 and you don't want to change default php version, then use this in .htaccess file 首先检查您的共享主机支持PHP 7在Cpanel(PHP选择器),如果是,但你有其他项目PHP 5 ,你不想更改默认的PHP版本,然后在.htaccess文件中使用它

For example: public_html/abc/.htaccess 例如: public_html / abc / .htaccess

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

Then PHP 7 Work and you can work with Laravel 5.6 on shared hosting 然后PHP 7 Work,您可以在共享主机上使用Laravel 5.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';

don't forget to change your php version to 7.2 不要忘记将您的PHP版本更改为7.2

You can try the below structure in your public_html (root) of your shared hosting 您可以在共享主机的public_html(root)中尝试以下结构

Create a folder called laravel and place all the files and folders except public folder in it. 创建一个名为laravel的文件夹,并将除公共文件夹之外的所有文件和文件夹放在其中。

Copy all the files and folders of public directory directly to the public_html root. 将公共目录的所有文件和文件夹直接复制到public_html根目录。 Your folder structure should look like this 您的文件夹结构应如下所示

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)

And edit the index.php to the following 并将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';

/*

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

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