简体   繁体   中英

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.

My example is based on: 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. 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.

Error in /var/log/apache2

PHP fatal error Uncaught Google Cloud Exception

I guessed it was a permissions issue with Apache vs my userid. I thought Apache might be having difficulty accessing the Bigquery php client files, due to directory permissions.

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

 GOOGLE_APPLICATION_CREDENTIALS="/bigquery/project1/accountdetails-xxxxxxxxxxxx.json"

It was visible when logged in as userx

 echo $GOOGLE_APPLICATION_CREDENTIALS

Then I came across 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 also needs to be configured to work (Ubuntu 18.10, nginx 1.14.)

from https://medium.com/@tomahock/passing-system-environment-variables-to-php-fpm-when-using-nginx-a70045370fad

/etc/php/7.2/fpm/pool.d$

edited www.conf

uncomment 
;clear_env = no

added line

env[GOOGLE_APPLICATION_CREDENTIALS] = /bigquery/project1/accountdetails-xxxxxxxxxxxx.json

restarted nginx and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM