【问题标题】:Deploying Laravel app to Google App Engine将 Laravel 应用部署到 Google App Engine
【发布时间】:2020-11-13 05:21:41
【问题描述】:

我正在尝试将我的 Laravel 7.29.3 应用部署到 Google App Engine 标准环境。我已按照此处https://cloud.google.com/community/tutorials/run-laravel-on-appengine-standard 的指导进行操作。但是,当我查看我的部署时,我得到一个 View[Welcome] not found 错误。我的 app.yaml 文件如下所示:

runtime: php72

env_variables:
  ## Put production environment variables here.
  APP_KEY: YOUR_APP_KEY
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  SESSION_DRIVER: cookie

它是一个非常简单的 yaml 文件,因为我只使用欢迎视图和到联系页面的路由。请注意,我在这个版本中没有使用任何数据库。请在下面查看我的路由:

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::post('contact', 'ContactFormController@ContactForm');

我也在这里查看了这个问题:View [welcome] not found 但我仍然遇到同样的错误。根据我对@sllopis 评论的理解,我需要将 welcome.blade.php 文件放在 layouts 文件夹中。我已经这样做了,但仍然得到同样的错误。任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 它不会进入 layouts 文件夹,如果是这种情况,您必须将该视图引用为 layouts.welcome
  • 我知道这很简单,但我在您的 app.yaml 中看不到它。你确定你从提到的教程的第 2 点替换了YOUR_APP_KEY 吗?请不要发布它,只需检查并确认
  • @lagbox,你认为它会去哪里?
  • @vitooh,是的,我已将应用程序密钥放入我的 yaml 文件中。

标签: php laravel google-app-engine


【解决方案1】:

我找到了解决方案。首先,您可以将处理程序添加到您的 app.yaml 文件中。它应该如下所示:

runtime: php72

handlers:
- url: /(.*\.(gif|png|jpg|css|js))$
  static_files: public/\1
  upload: public/.*\.(gif|png|jpg|css|js)$

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

env_variables:
  ## Put production environment variables here.
  APP_KEY: YOUR_APP_KEY
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  SESSION_DRIVER: cookie

来源:https://stackoverflow.com/a/57822141/2251229

然后您可以更新您的 config/filesystems.php 文件。您可以按照下面提供的示例添加新的文件系统。

'gcs' => [
    'driver' => 'gcs',
    'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
    'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
    'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
    'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket
    'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below
    'visibility' => 'public', // optional: public|private
],

然后像这样更新你的默认文件系统:

'default' => env('FILESYSTEM_DRIVER', 'gcs'),

使用以下命令安装 Laravel Google Cloud Storage 包:

composer require superbalist/laravel-google-cloud-storage

来源:https://stackoverflow.com/a/57177913/2251229

从这里你可以做你的gcloud app deploygcloud app browse。如果您遇到更多错误,请执行php artisan config:clear。这应该会清除所有缓存的配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-04
    • 2015-11-13
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 2011-07-28
    相关资源
    最近更新 更多