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.