使用laravel在谷歌应用引擎上出错

时间:2014-12-15 22:10:20

标签: php google-app-engine laravel

我尝试将基于laravel的项目部署到gae,但是我在错误日志中出现了一个空白屏幕

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'file_get_contents(/base/data/home/apps/s~random-gae-name/1.380824294377640683/vendor/laravel/framework/src/Illuminate/Exception/resources/plain.html): failed to open stream: No such file or directory' in /base/data/home/apps/s~random-gae-name/1.380824294377640683/vendor/laravel/framework/src/Illuminate/Exception/PlainDisplayer.php:21
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'file_get_conten...', '/base/data/home...', 21, Array)
#1 /base/data/home/apps/s~random-gae-name/1.380824294377640683/vendor/laravel/framework/src/Illuminate/Exception/PlainDisplayer.php(21): file_get_contents('/base/data/home...')
#2 /base/data/home/apps/s~random-gae-name/1.380824294377640683/bootstrap/compiled.php(9292): Illuminate\Exception\PlainDisplayer->display(Object(ErrorException))
#3 /base/data/home/apps/s~random-gae-name/1.380824294377640683/bootstrap/compiled.php(9244): Illuminate\Exception\Handler->displayException(Object( in /base/data/home/apps/s~random-gae-name/1.380824294377640683/vendor/laravel/framework/src/Illuminate/Exception/PlainDisplayer.php on line 21

我不知道这意味着什么。

我的php.ini

; enable function that are disabled by default in the App Engine PHP runtime
google_app_engine.enable_functions = "php_sapi_name, php_uname, getmypid"

; Cloud storage buckets that Laravel needs to include files from. By default
; in production the first bucket declared here will be used for app storage.
google_app_engine.allow_include_gs_buckets = "x"

allow_url_include=1

和我的yaml文件

application: x
module: default
version: 1
runtime: php
api_version: 1

handlers:
- url: /.*
  script: public/index.php


- url: /(.*\.(ico|gif|png|jpg|css|js|html|txt|pdf|mp3|eps|svg|ttf|woff|eot))
  static_files: public/\1
  upload: (.*\.(ico|gif|png|jpg|css|js|html|txt|pdf|mp3|eps|svg|ttf|woff|eot))

1 个答案:

答案 0 :(得分:3)

您似乎需要更改存储桶的存储路径。 App Engine应用程序无法写入本地文件系统,因此您必须覆盖Laravel的Application类方法bindInstallPaths,以允许将Google Cloud Storage用作app/storage/目录。

使用继承的Illuminate\Foundation\Application类,然后覆盖bindInstallPaths方法。

// MyApplicationClass.php file 
class MyApplicationClass extends Illuminate\Foundation\Application 
{
    public function bindInstallPaths(array $paths)
    {
        if (isset($_SERVER['APPLICATION_ID']) && !empty($_SERVER['APPLICATION_ID'])) { 
            if (realpath($paths['app'])) {
                $this->instance('path', realpath($paths['app']));
            }
            elseif (file_exists($paths['app'])) {
                $this->instance('path', $paths['app']);
            }
            else {
                $this->instance('path', FALSE);
            }

            foreach (array_except($paths, array('app')) as $key => $value)
            {
                if (realpath($value)) {
                    $this->instance("path.{$key}", realpath($value));
                }
                elseif (file_exists($value)) {
                    $this->instance("path.{$key}", $value);
                }
                else {
                    $this->instance("path.{$key}", FALSE);
                }
            }
        } else {
            parent::{__FUNCTION__}($paths);
        }
    }
}

然后在bootstrap/start.php中使用此类而不是原始类。

$app = (isset($_SERVER['APPLICATION_ID']) && !empty($_SERVER['APPLICATION_ID'])) 
        ? new MyApplicationClass
        : new Illuminate\Foundation\Application;

最后,您必须更改paths.php文件

中的存储路径
// paths.php file 
$storage_path = (isset($_SERVER['APPLICATION_ID']) && !empty($_SERVER['APPLICATION_ID'])) 
                    ? "gs://" . $your_bucket_name . "/storage"
                    : __DIR__.'/../app/storage';
mkdir($storage_path); 

return array (
    ...
    'storage' => $storage_path,
);

我希望它适合你。