简体   繁体   English

如何使用 Google 的 credentials.json 文件在 Heroku 上部署 PHP Laravel 应用程序?

[英]How to deploy a PHP Laravel app on Heroku with Google's credentials.json file?

I have a PHP Laravel API, connected with a Google Sheet to retrieve some data.我有一个 PHP Laravel API,与 Google Sheet 连接以检索一些数据。 For authentication as a Google Client, I received a credentials.json file that I put in a storage/app/credentials directory on my local machine, which I added to .gitignore to keep it out of version control.对于作为 Google 客户端的身份验证,我收到了一个credentials.json文件,我将它放在本地机器上的storage/app/credentials目录中,我将其添加到.gitignore以使其不受版本控制。 I Installed Google Auth Library for PHP and set the path to the credentials.json file as a variable called GOOGLE_APPLICATION_CREDENTIALS in the project's .env file.为 PHP安装了Google Auth 库,并将credentials.json文件的路径设置为项目的.env文件中名为GOOGLE_APPLICATION_CREDENTIALS的变量。 So $credential below simply holds the path to the JSON file.所以下面的$credential只是保存了 JSON 文件的路径。

$credential = getenv('GOOGLE_APPLICATION_CREDENTIALS');

$client = new Google_Client();
$client->setApplicationName('Pricing Calculator');
$client->setScopes(Google_Service_Sheets::SPREADSHEETS);
$client->setAuthConfig($credential);
$client->setAccessType('offline');

With this, the API works in my local environment, but on production I keep getting back internal server error 500's.有了这个,API 在我的本地环境中工作,但在生产中,我不断收到内部服务器错误 500。 I added a buildpack https://github.com/elishaterada/heroku-google-application-credentials-buildpack.git to set credentials.json as a GOOGLE_CREDENTIALS Config Var and assigned google-credentials.json to GOOGLE_APPLICATION_CREDENTIALS , but it seems the credentials.json file is still not configured correctly on the Heroku production server.我添加了一个 buildpack https://github.com/elishaterada/heroku-google-application-credentials-buildpack.gitcredentials.json设置为GOOGLE_CREDENTIALS配置变量并将google-credentials.json分配给GOOGLE_APPLICATION_CREDENTIALS ,但似乎凭据.json文件仍未在 Heroku 生产服务器上正确配置。

I have the feeling it should be working already, but it isn't.我感觉它应该已经开始工作了,但事实并非如此。 So I either lack essential knowledge or I missed some obvious mistake.所以我要么缺乏基本知识,要么错过了一些明显的错误。 Both is possible, but anyway... any help or insight would be much appreciated!两者都是可能的,但无论如何......任何帮助或见解将不胜感激!

The Git repo is here: https://github.com/Spesm/pricing-calculator-api Git 存储库在这里: https : //github.com/Spesm/pricing-calculator-api

For documentation purposes, this is related to this comment .出于文档目的,这与此评论有关

It seems that the buildpack used on the linked question is not working.似乎链接问题上使用的 buildpack 不起作用。 The suggested alternative is to use this buildpack instead .建议的替代方法是改用此 buildpack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP 致命错误:在尝试运行 Google 的示例脚本时,vendor/google/apiclient/src/Client.php:982 中不存在文件“credentials.json” - PHP fatal error: file "credentials.json" does not exist in vendor/google/apiclient/src/Client.php:982 when trying to run Google's example script invalidargumentexception credentials.json“不存在 - invalidargumentexception credentials.json" does not exist 如何将带有 mysql 的 php 应用程序部署到 heroku? - how to deploy a php app with mysql to heroku? 在heroku上部署CodeIgniter Php应用程序 - Deploy CodeIgniter Php app on heroku 如何在Heroku上部署Laravel 4 Apps? - How to deploy Laravel 4 Apps on Heroku? 如何将Google帐户凭据应用于我的PHP应用(SSO)? - How can Google account credentials by applied to my PHP app (SSO)? Laravel 部署到 heroku 时缓存文件出现问题 - Laravel problem with cache file when deploy to heroku 无法将 Laravel 应用程序部署到 Heroku - symfony/polyfill-ctype v1.24.0 需要 php >=7.1 - Cannot deploy Laravel App to Heroku - symfony/polyfill-ctype v1.24.0 requires php >=7.1 如何使用Heroku部署Laravel + Vue项目 - How to deploy a Laravel + Vue project with Heroku 如何在没有公共端点的 azure 和 Laravel 8 和 PHP 8 中部署应用服务? - How to Deploy an App Service in azure with Laravel 8 and PHP 8 without public endpoint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM