[英]bigquery php client not working with Apache web page (Ubuntu 18.10 server)
I have a working Apache 2.4 website that works with Php 7 pages, on an Ubuntu 18.10 server.我在 Ubuntu 18.10 服务器上有一个可使用 Php 7 页面的 Apache 2.4 网站。
My example is based on: https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries#client-libraries-install-php我的示例基于: https : //cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries#client-libraries-install-php
When I run the page as me from the command line当我像我一样从命令行运行页面时
php filex.php
bigquery works and I can see the data. bigquery 有效,我可以看到数据。 When I try and view it from the apache web server the 1st part of the page renders then there is an error and the bigquery part is missing.
当我尝试从 apache 网络服务器查看它时,页面的第一部分呈现然后出现错误并且缺少 bigquery 部分。
Error in /var/log/apache2 /var/log/apache2 中的错误
PHP fatal error Uncaught Google Cloud Exception PHP 致命错误未捕获的 Google Cloud 异常
I guessed it was a permissions issue with Apache vs my userid.我猜这是 Apache 与我的用户 ID 的权限问题。 I thought Apache might be having difficulty accessing the Bigquery php client files, due to directory permissions.
由于目录权限,我认为 Apache 可能难以访问 Bigquery php 客户端文件。
However, the problem was I had not set the environment variable correctly.但是,问题是我没有正确设置环境变量。
I had looked here: https://help.ubuntu.com/community/EnvironmentVariables and set System-wide environment variables /etc/environment我看过这里: https : //help.ubuntu.com/community/EnvironmentVariables并设置系统范围的环境变量 /etc/environment
GOOGLE_APPLICATION_CREDENTIALS="/bigquery/project1/accountdetails-xxxxxxxxxxxx.json"
It was visible when logged in as userx以 userx 身份登录时可见
echo $GOOGLE_APPLICATION_CREDENTIALS
Then I came across https://medium.com/@william.b/setting-dynamic-environmental-variables-in-apache-from-the-os-1d5c1e2e9e6c然后我遇到了https://medium.com/@william.b/setting-dynamic-environmental-variables-in-apache-from-the-os-1d5c1e2e9e6c
which gave me the solution这给了我解决方案
nano /etc/apache2/envvars
I added the line to the bottom of the (mainly empty) script我将这一行添加到(主要是空的)脚本的底部
export GOOGLE_APPLICATION_CREDENTIALS="/bigquery/project1/accountdetails-xxxxxxxxxxxx.json"
I restarted the server.我重新启动了服务器。 Now the web page works as expected.
现在网页按预期工作。
=================== ====================
Nginx nginx
nginx also needs to be configured to work (Ubuntu 18.10, nginx 1.14.)还需要配置 nginx 才能工作(Ubuntu 18.10、nginx 1.14。)
from https://medium.com/@tomahock/passing-system-environment-variables-to-php-fpm-when-using-nginx-a70045370fad来自https://medium.com/@tomahock/passing-system-environment-variables-to-php-fpm-when-using-nginx-a70045370fad
/etc/php/7.2/fpm/pool.d$ /etc/php/7.2/fpm/pool.d$
edited www.conf编辑 www.conf
uncomment
;clear_env = no
added line添加行
env[GOOGLE_APPLICATION_CREDENTIALS] = /bigquery/project1/accountdetails-xxxxxxxxxxxx.json
restarted nginx and it worked.重新启动 nginx 并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.