laravel 5.6 主机到共享主机上的 cpanel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49485507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel 5.6 host to cpanel on shared hosting
提问by Tita Donalbin
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
回答by ollieread
You have two methods available, one requiring ssh access. Under no circumstances do you put your entire Laravel directory into the public_html
directory.
您有两种方法可用,一种需要 ssh 访问。在任何情况下,您都不会将整个 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 ~
- Delete the
public_html
directory - Now you want to upload your Laravel app to
~/laravel
- Now you need to recreate public_html as a symlink
cd ~ && ln -s laravel/public public_html
- 登录您的帐户并转到您的主目录
cd ~
- 删除
public_html
目录 - 现在你想将你的 Laravel 应用上传到
~/laravel
- 现在您需要重新创建 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) - Copy the contents of the
~/laravel/public
directory topublic_html
- Change the path to match your new destination
- 将你的 Laravel 安装上传到类似的地方
~/laravel
(在 public_html 之上) - 将目录内容复制
~/laravel/public
到public_html
- 更改路径以匹配您的新目的地
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 <[email protected]>
*/
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);
回答by Jagjeet Singh
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
工作,你可以Laravel 5.6
在共享主机上工作
回答by Edwin Diradinata
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
回答by Nilkamal Gotarne
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. now we have to change the content of index.php file i.e 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';
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
在谷歌搜索之后,我发现你必须获取包含 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:clear
,php artisan route:clear
您可以使用 ssh 或在 web.php 中定义函数然后点击链接
回答by Akram Wahid
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. And then ask them to execute following command via ssh
如果您的共享主机团队非常支持您,一个简单的方法是将您的文件上传到 public_html 文件夹,然后如果您没有服务器的 ssh 访问权限,请联系您的主机团队并要求他们将您的域名指向 public_html/public 文件夹作为根文件夹。然后让他们通过 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
回答by user3109166
Umm. Shared hosting does NOT support php 7, which larave 5.6 depends on. Have you guys found a workaround. I have been stuck for months with laravel 4.x on bluehost.
嗯。共享主机不支持 php 7,而 larave 5.6 依赖于此。各位大侠有没有找到解决办法。我已经在 bluehost 上使用 laravel 4.x 好几个月了。
回答by Srikanth Gopi
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 的文件夹,并将除 public 文件夹之外的所有文件和文件夹放入其中。
Copy all the files and folders of public directory directly to the public_html root. Your folder structure should look like this
将public目录下的所有文件和文件夹直接复制到public_html根目录下。您的文件夹结构应如下所示
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';
/*