简体   繁体   English

bigquery php 客户端不适用于 Apache 网页(Ubuntu 18.10 服务器)

[英]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.

相关问题 PHP 在 Ubuntu Apache 服务器上不工作 - PHP is not working on Ubuntu Apache server 如何在 PHP 7.0 Ubuntu 18.10 中启用 SoapClient - How To Enable SoapClient in PHP 7.0 Ubuntu 18.10 PHP API 不适用于 apache2 Ubuntu 服务器上的 Django | 谷歌云 - PHP API is not working With Django on apache2 Ubuntu server | Google Cloud Ubuntu 服务器上的 Apache 2.4.6:客户端被服务器配置拒绝 (PHP FPM) [加载 PHP 文件时] - Apache 2.4.6 on Ubuntu Server: Client denied by server configuration (PHP FPM) [While loading PHP file] 我在Java中将表单发布到PHP,但在Ubuntu 18.10中没有响应 - I post a form to PHP in java, but no response in Ubuntu 18.10 Apache 服务器不工作(ubuntu 16.04,灯服务器) - Apache server no working (ubuntu 16.04, lamp server) BigQuery + PHP客户端中的令牌分页不起作用 - Pagination with token in BigQuery + PHP client not working apache2 web-server的Ubuntu 12.04 php,mysql-server和phpmyadmin安装错误 - Ubuntu 12.04 php, mysql-server and phpmyadmin installation error with apache2 web-server Apache MINA服务器和PHP客户端 - Apache MINA Server and PHP Client 配置Varnish之后如何将网页缓存2分钟。 (Ubuntu 14.04,Apache,PHP) - After configuring Varnish how to cache the Web Page for 2 Minutes. (Ubuntu 14.04,Apache,PHP)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM