0
votes

I have a PHP that runs fine on localhost but throws error on the cloud server. On the localhost, the script runs and also fetched the data from datastore.

This is the line thats causing the problem:

require __DIR__ . '/../../vendor/autoload.php';
// this is the line5 of datastore.php

I deploy it using this code: gcloud app deploy --promote --stop-previous-version app.yaml

After deploying to the Google AppEngine, i get this:

Warning: require(/base/data/home/apps/myproject/projectID/dialpad_research/api/../../vendor/autoload.php): failed to open stream: No such file or directory in /base/data/home/apps/myproject/projectID/dialpad_research/api/datastore.php on line 5 Fatal error: require(): Failed opening required '/base/data/home/apps/myproject/projectID/dialpad_research/api/../../vendor/autoload.php' (include_path='.;/base/data/home/apps/myproject/projectID/;/base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/ef537742f8701211/sdk') in /base/data/home/apps/myproject/projectID/dialpad_research/api/datastore.php on line 5

This file is required inside another PHP file too. But even if I try to access this file directly, I still get the same error.

Should I be adding the require code differently?

2
Have you checked the file permissions? - Osakr
It looks like you are using Composer; do you actually do a composer install when you deploy? - jeroen
Yes I did composer install. I did composer install before deploying. Did you mean to do composer install "while" deploying? - ssdesign
That is impossible to tell without knowing how you are deploying exactly; it looks like the files are not there so somewhere in your deploy process you would need to make sure they get added. - jeroen
Using any framework? - BadPiggie

2 Answers

1
votes

The problem was that the vendor folder was not getting uploaded. .gcloudignore file was preventing it. After correcting it, this error is gone.

Thanks everyone from trying.

0
votes

Your require code should look like this. Your vendor folder should normally be at root directory level of your code on the same level as your app.yaml. In which case, your require should look like this:

require 'vendor/autoload.php';

Also, sanity check and make sure the file is actually there in the vendor folder.