如何将 Laravel 5.5 应用部署到 Godaddy cPanel 共享主机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49142045/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:28:46  来源:igfitidea点击:

How to deploy Laravel 5.5 app to Godaddy cPanel shared hosting

phplaravellaravel-5cpanel

提问by mdailey77

I'm relatively new to Laravel. I'm confused on what is the proper way to deploy a Laravel 5.5 app to a Godaddy cPanel shared hosting. I've read multiple posts on the subject and they give conflicting advice.

我对 Laravel 比较陌生。我对将 Laravel 5.5 应用程序部署到 Godaddy cPanel 共享主机的正确方法感到困惑。我已经阅读了多篇关于这个主题的帖子,他们给出了相互矛盾的建议。

Part of what I'm not clear on is do I copy all my files to the server and then run the following composer commands?:

我不清楚的部分是我是否将所有文件复制到服务器,然后运行以下 composer 命令?:

composer install --optimize-autoloaderand php artisan config:cache

composer install --optimize-autoloaderphp artisan config:cache

I get the part where I should create a folder on the server outside of the public_html folder, placing all of the app files there except what is in the app's public subfolder.

我得到了应该在 public_html 文件夹之外的服务器上创建一个文件夹的部分,将所有应用程序文件放在那里,除了应用程序的公共子文件夹中的内容。

If I want to run the app from a subfolder how would I do that? For example, www.mysite.com/laravelapp

如果我想从子文件夹运行应用程序,我该怎么做?例如,www.mysite.com/laravelapp

The examples I found where for only running it from the public_html folder itself. Would it just involve changing the file paths in the www/index.php?

我找到的示例仅从 public_html 文件夹本身运行它。它是否只涉及更改 www/index.php 中的文件路径?

回答by mdailey77

I figured out how to deploy Laravel on a Godaddy shared hosting plan after reading more posts about the subject. Here are the steps I took:

在阅读了有关该主题的更多帖子后,我想出了如何在 Godaddy 共享托管计划上部署 Laravel。以下是我采取的步骤:

  1. Created a new folder outside the public_html folder and uploaded all of the app files to that folder except the vendor folder.
  2. Using SSH access, I ran the command curl -sS https://getcomposer.org/installer | phpin the newly created app folder on the server.
  3. I removed the public folder from the Laravel app folder, placed it inside the public_html folder and renamed it to the name of my project.
  4. I modified the file paths in the index.php in the project folder so they pointed to the laravel app folder like so:

    require __DIR__.'/../../laravel/bootstrap/autoload.php';

    $app = require_once __DIR__.'/../../laravel/bootstrap/app.php';

  5. I installed the dependencies by running the command in SSH: php composer.phar install, then adding the necessary cache by running: php artisan config:cache

  1. 在 public_html 文件夹之外创建了一个新文件夹,并将除供应商文件夹之外的所有应用程序文件上传到该文件夹​​。
  2. 使用 SSH 访问,我curl -sS https://getcomposer.org/installer | php在服务器上新创建的应用程序文件夹中运行命令。
  3. 我从 Laravel 应用程序文件夹中删除了公共文件夹,将其放在 public_html 文件夹中,并将其重命名为我的项目名称。
  4. 我修改了项目文件夹中 index.php 中的文件路径,因此它们指向 laravel 应用程序文件夹,如下所示:

    require __DIR__.'/../../laravel/bootstrap/autoload.php';

    $app = require_once __DIR__.'/../../laravel/bootstrap/app.php';

  5. 我通过在 SSH: 中运行命令来安装依赖项php composer.phar install,然后通过运行添加必要的缓存:php artisan config:cache

That was it. I did it using Godaddy cPanel shared hosting. Before attempting this make sure the PHP version is set to 7.1. I wanted to post my steps because I found some of the tutorials on this subject either were confusing, gave conflicting advice or didn't provide all the necessary steps.

就是这样。我使用 Godaddy cPanel 共享主机做到了。在尝试之前,请确保 PHP 版本设置为 7.1。我想发布我的步骤,因为我发现关于这个主题的一些教程要么令人困惑,要么给出了相互矛盾的建议,要么没有提供所有必要的步骤。

回答by Theodore R. Smith

The biggest problem you have is that GoDaddy's latest supported version of PHP is v5.6. Laravel v5.5 and later all require PHP v7.0 or higher.Apparently, they added PHP 7 support in late 2017.

您遇到的最大问题是 GoDaddy 支持的最新 PHP 版本是 v5.6。Laravel v5.5 及更高版本都需要 PHP v7.0 或更高版本。显然,他们在 2017 年底添加了 PHP 7 支持。

I'd stillhighly recommend shifting to a much more reputable host like (closest comparison) BlueHost.com or DigitalOcean.com.

仍然强烈建议转移到更有信誉的主机,如(最接近的比较)BlueHost.com 或 DigitalOcean.com。



The second biggest problem you have is that GoDaddy won't let you actually run the artisancommand, which Laravel really needs. It means 1. needing to apply database creation and migrations manually and 2. running all the artisan commands locally and uploading the entire project, in situ.

您遇到的第二大问题是 GoDaddy 不会让您实际运行artisanLaravel 真正需要的命令。这意味着 1. 需要手动应用数据库创建和迁移 2. 在本地运行所有 artisan 命令并原位上传整个项目。

The third biggest problem is that composerdoesn't run on GoDaddy, meaning you'll need to upload all the vendordirectories, too.

第三大问题是composer它不能在 GoDaddy 上运行,这意味着您还需要上传所有vendor目录。



Addendum: Here is a guide for how to deploy Laravel on shared hosts: https://www.youtube.com/watch?v=6g8G3YQtQt4

附录:这是如何在共享主机上部署 Laravel 的指南:https: //www.youtube.com/watch?v=6g8G3YQtQt4

回答by iohan sandoval

I do the followings steps in a shared hosting:

我在共享主机中执行以下步骤:

  1. compress the laravel proyect
  2. upload the new file .zip
  3. uncompress the project
  4. move all the project to the home directory, normally to public_html
  5. go to public folder and move index.php to public_html
  6. edit index.php in line 24 and 38 for laravel 5.8
  1. 压缩 Laravel 项目
  2. 上传新文件 .zip
  3. 解压项目
  4. 将所有项目移动到主目录,通常到 public_html
  5. 转到公共文件夹并将 index.php 移动到 public_html
  6. 为 laravel 5.8 编辑第 24 和 38 行中的 index.php

line 24

第 24 行

require __DIR__.'/vendor/autoload.php';

line 38

第 38 行

require_once __DIR__.'/bootstrap/app.php';

this work for me in godaddy and inmotion

这在 Godaddy 和 inmotion 中对我来说有效