Laravel on App Engine Standard: The /srv/bootstrap/cache directory must be present and writable
Asked Answered
B

4

13

I've been struggling with the Google App Engine Standard environment for a day now.

The error is as follows:

PHP Notice: Exception: The /srv/bootstrap/cache directory must be present and writable. in /srv/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php:168

I know that the /tmp folder is the only writable folder for the App Engine Standard environment. Therefore, my app.yaml have the following additional env_variables:

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

...my bootstrap/app.php contains this line:

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

...and my composer.json has these scripts to account for the change in configuration:

        "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"
        ]

These are my drivers configured in app.yaml:

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

For some reason, I just can't seem to find a way to make the /tmp folder the folder where the cached views and config are put. Actually, I suspect that the ...:clear commands aren't even properly ran at all.

My application is just a blank white page now, regardless of the path. That's fair, as due to the unwritable cache, the views cannot be rendered and stored there.

The above configurations should match the tutorials for installing Laraval on Google App Engine Standard, such as this one: https://cloud.google.com/community/tutorials/run-laravel-on-appengine-standard.

In the cloud console, I've checked whether the /tmp folder exists, which is the case.

Anyways, all help is dearly appreciated. If you need more code snippets, just ask. I'll be happy to provide them.

Borowski answered 7/7, 2019 at 10:26 Comment(1)
Can you go line 168 in /srv/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php file and dump $this->manifestPath property in write method?Wolfenbarger
M
10

I found a simple solution for this problem. The directory where the Laravel application lives on Google App Engine Standard is read-only. So you have to write the cache files to /tmp.

You can change the paths by simple adding this environment variables to your 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
Moneyer answered 23/9, 2019 at 12:52 Comment(2)
do we need to move the files i.e. services.php etc to a folder called /tmp in our app root folder?Knotts
No, I think they are created automaticallyMoneyer
H
1

Your app.yaml and bootstrap/app.php look good. But there is one more thing that you need to do:

If you're on Laravel 6 or above, remove facade/ignition dependency:

composer remove --dev facade/ignition

OR
If you're on Laravel 5 or older, remove beyondcode/laravel-dump-server instead:

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


This is what the community doc that you mentioned has to say about this:

This is a fix for an error which happens as a result of Laravel's caching in bootstrap/cache/services.php.

Community tutorial on setting up Laravel in App Engine Standard Environment.

Healthful answered 19/6, 2020 at 6:57 Comment(0)
S
-1

Before deploying try:

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

For me it was optimize:clear

Shipment answered 30/12, 2019 at 5:29 Comment(0)
X
-2

Could this be related to the fact that in Illuminate\Foundation\Application.php the paths are resolved from $this->bootstrapPath() (which returns an absolute path) when executed normally but seem to be taken as is from the APP_CONFIG_CACHE variable and others when running tests ?

/**
 * 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'));
}

Then give permission

sudo chmod -R 775 bootstrap/cache/

Run the bellow command

 php artisan config:cache
Xylina answered 24/9, 2019 at 11:22 Comment(1)
This does not answer the question with respect to Google Cloud App Engine. You cannot run either command from within that service.Reign

© 2022 - 2024 — McMap. All rights reserved.