php-docs-samples: Exception: The /workspace/bootstrap/cache directory must be present and writable.
Related
Split from #852
Steps
-
Create a Laravel 6 project based on this tutorial.
-
Create GAE configuration files:
2.a. Create a .cloudignore
file:
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
# PHP Composer dependencies:
/vendor/
# Ignore .env file for local development
.env
.env.example
2.b. Create an api/app-staging.yaml
file (some variable have been removed for security purposes):
service: staging
runtime: php73
runtime_config:
document_root: public
env_variables:
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_DEBUG: true
LOG_CHANNEL: stack
BROADCAST_DRIVER: log
CACHE_DRIVER: file
QUEUE_CONNECTION: sync
SESSION_DRIVER: cookie
SESSION_LIFETIME: 120
2.c. Create a cloudbuild-staging.yaml
file based on Automate App Engine deployments with Cloud Build:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "app-staging.yaml"]
timeout: "1600s"
dir: "api"
env:
- COMMIT_SHA=$COMMIT_SHA
-
Deploy directly from your local machine.
gcloud app deploy app-staging.yaml
This should build and deploy successfully, and the deployed website should load.
-
Add a build trigger for the
staging
branch that triggers a build using thecloudbuild-staging.yaml
configuration. -
Commit and push your changes the the trigger branch (
staging
). -
Visit the deployed website.
Expected
The website loads.
Actual
Exception
The /workspace/bootstrap/cache directory must be present and writable.

Environment
macOS Catalina 10.15.6 Laravel Framework 6.18.25 PHP 7.4.7 (local) PHP 7.3 (Google App Engine Image)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 19 (6 by maintainers)
This issue was fixed for me by adding the the following line to the post-autoload-dump in composer.json:
"mkdir -p ./bootstrap/cache/",
The default included
.gitignore
file in the./bootstrap/cache
folder probably prevents the directory from being created when the repository is being transferred/pulled into the build container.The
@php artisan package:discover --ansi
command in the composer.json needs this directory to be present to write the packages.php and services.php after installing all the packages.When deploying from your local machine this directory (including files) will be uploaded and therefore no error is raised.
Relevant composer.json part:
I was stuck with this error for a while, and what solved the issue on my end was adding the following to the composer.json file:
and
It seems that when I had “php artisan clear-compiled” under “post-install-cmd”, I would again experience the workspace/bootstrap/cache error. Not quite sure if the changes to both script sections are required, but “php artisan cache:clear” seemed important to get the application to work on my end. It is also noted/recommended in the app engine flex example here https://cloud.google.com/community/tutorials/run-laravel-on-appengine-flexible
I hope this can help someone
I believe your issue here is you are using
CACHE_DRIVER: file
. The filesystem on App Engine is not letting you write to/workspace/bootstrap/cache
because that part of the App Engine filesystem is immuttable.Try either changing the cache driver to
database
(instructions in that tutorial), or make sure you’ve modifiedbootstrap/app.php
by adding the following block of code before the return statement. This will allow you to set the storage path to /tmp for caching in production.The above instructions are in the tutorial mentioned. If this doesn’t work, it’s possible the logic has changed for newer versions of Laravel.
Between the fixes mentioned here, and the soon-to-be-published update for Laravel 8, I think we can close this issue.
In addition I can confirm that
--no-cache
seems to be needed.