I develop a simple app for GAE on php. In local env all is ok, but after "gcloud app deploy" a have an error about autoload.php - No such file or directory. I use composer only for autoload my classes - not an external dependences. GAE standard, project without billing
What i do locally:
composer install
dev_appserver.py app.test.yaml
and aplication is working perfect.
But after deploy:
PHP Fatal error: require_once(): Failed opening required '/base/data/home/apps/***/vendor/autoload.php' (include_path='.;/base/data/home/apps/***/;/base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/fc2f1b4915ea2bca/sdk') in /base/data/home/apps/***/webhook.php on line 8
Line 8:
require_once __DIR__ . '/vendor/autoload.php';
composer.json
{
"autoload": {
"psr-4": {
"Core\\": "Classes/",
"Telegram\\": "Classes/Telegram",
"PushEvent\\": "Classes/PushEvent"
}
}
}
So now i delete vendor from .gcloudignore - and app is work on GAE, but this thing make me sad :(
You can explicitly tell GAE to run the composer install
or composer dump-autoload
.
{
"scripts": {
"gcp-build": [
"composer install"
]
}
}
Tip1: GAE caches the install files, and sometimes you may want to not use it: gcloud beta app deploy --no-cache]
Tip2: I recommend you to change the document root of the application in app.yaml to not expose the vendor dir to the outside world.
runtime_config:
document_root: public
Directory structure:
src
- OtherFolder //PSR-4
- ClassA.php
public
- index.php
vendor
- autoload.php
- ...
compose.json
app.yaml
The require will have to reference the parent folder
require_once __DIR__ . '/../vendor/autoload.php';
And the composer.json only needs one psr4 entry
{
"autoload": {
"psr-4": {
"MyApp\\": "src/"
}
}
}