12

我已经在 Google App Engine 标准环境中苦苦挣扎了一天。

错误如下:

PHP 注意:例外:/srv/bootstrap/cache 目录必须存在且可写。在 /srv/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php:168

我知道该/tmp文件夹是 App Engine 标准环境的唯一可写文件夹。因此,我app.yaml有以下附加env_variables

  APP_STORAGE: "/tmp"
  VIEW_COMPILED_PATH: "/tmp"

...我的bootstrap/app.php包含这一行:

$app->useStoragePath(env('APP_STORAGE', base_path() . '/tmp'));

...我composer.json有这些脚本来解释配置的变化:

        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
        ],
        "post-install-cmd": [
            "composer dump-autoload",
            "php artisan config:clear",
            "php artisan cache:clear",
            "php artisan view:clear",
            "php artisan cache:clear",
            "php artisan regenerate:schoolCSS"
        ]

这些是我配置的驱动程序app.yaml

SESSION_DRIVER: database
BROADCAST_DRIVER: log
CACHE_DRIVER: database
QUEUE_DRIVER: sync

出于某种原因,我似乎无法找到一种方法使该/tmp文件夹成为放置缓存视图和配置的文件夹。实际上,我怀疑这些...:clear命令根本没有正确运行。

我的应用程序现在只是一个空白页,无论路径如何。这是公平的,因为由于不可写缓存,视图不能被渲染和存储在那里。

以上配置应与在 Google App Engine Standard 上安装 Laraval 的教程相匹配,例如:https ://cloud.google.com/community/tutorials/run-laravel-on-appengine-standard 。

在云控制台中,我检查了该/tmp文件夹是否存在,是这样的。

无论如何,非常感谢所有帮助。如果您需要更多代码片段,请询问。我很乐意为他们提供。

4

4 回答 4

9

我为这个问题找到了一个简单的解决方案。Laravel 应用程序在 Google App Engine Standard 上的目录是只读的。所以你必须将缓存文件写入/tmp.

您可以通过简单地将此环境变量添加到您的app.yaml

APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
于 2019-09-23T12:52:18.683 回答
1

app.yamlbootstrap/app.php看起来不错。但是,您还需要做一件事:

如果您使用的是 Laravel 6 或更高版本,请删除facade/ignition依赖项:

composer remove --dev facade/ignition

或者
,如果您使用的是 Laravel 5 或更早版本,请beyondcode/laravel-dump-server改为删除:

composer remove --dev beyondcode/laravel-dump-server


这就是您提到的社区文档对此的看法:

这是对由于 Laravel 在 bootstrap/cache/services.php 中的缓存而发生的错误的修复。

在 App Engine 标准环境中设置 Laravel 的社区教程。

于 2020-06-19T06:57:48.660 回答
-1

在部署之前尝试:

php artisan route:clear
php artisan view:clear
php artisan config:clear
php artisan cache:clear
php artisan optimize:clear

对我来说是optimize:clear

于 2019-12-30T05:29:06.103 回答
-2

这是否与以下事实有关其他人在运行测试时?

/**
 * Get the path to the configuration cache file.
 *
 * @return string
 */
public function getCachedConfigPath()
{
    return Env::get('APP_CONFIG_CACHE', $this->bootstrapPath().'/cache/config.php');
}
Replacing it like this seems to do the job on my side.

/**
 * Get the path to the cached services.php file.
 *
 * @return string
 */
public function getCachedServicesPath()
{
    return $this->basePath(Env::get('APP_SERVICES_CACHE', 'bootstrap/cache/services.php'));
}


/**
 * Get the path to the cached packages.php file.
 *
 * @return string
 */
public function getCachedPackagesPath()
{
    return $this->basePath(Env::get('APP_PACKAGES_CACHE', 'bootstrap/cache/packages.php'));
}


/**
 * Get the path to the configuration cache file.
 *
 * @return string
 */
public function getCachedConfigPath()
{
    return $this->basePath(Env::get('APP_CONFIG_CACHE', 'bootstrap/cache/config.php'));
}


/**
 * Get the path to the routes cache file.
 *
 * @return string
 */
public function getCachedRoutesPath()
{
    return $this->basePath(Env::get('APP_ROUTES_CACHE', 'bootstrap/cache/routes.php'));
}

/**
 * Get the path to the events cache file.
 *
 * @return string
 */
public function getCachedEventsPath()
{
    return $this->basePath(Env::get('APP_EVENTS_CACHE', 'bootstrap/cache/events.php'));
}

然后给权限

sudo chmod -R 775 bootstrap/cache/

运行下面的命令

 php artisan config:cache
于 2019-09-24T11:22:52.660 回答