GoogleAPIPHP客户端麻烦

Google API PHP client trouble

我已经尝试了所有方法,但似乎无法简单地让它工作。

我在 bluehost 主机上愉快地使用这些脚本,直到我决定转移到数字海洋。

https://github.com/google/google-api-php-client/tree/1.1.4

https://github.com/asimlqt/php-google-spreadsheet-client/tree/2.3.5

我构建了一个自定义函数来读取电子表格并将其用作需要能够自己编辑网站文本的客户的数据库。

我拿了一个 Digital Ocean Ubuntu 14.04 服务器,在上面安装了 Sentora 面板,正常的 PHP 代码可以工作,但是这个 Google API 脚本正在抛出这个错误。

[Fri Jul 29 05:21:24.569294 2016] [:error] [pid 2429] [client 14.139.122.50:53019] PHP Warning:  file_exists(): open_basedir restriction in effect. File(/tmp/Google_Client/5f/5fa67135f8773ebac807e4dda0aa1084) is not within the allowed path(s): (/var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in:/var/sentora/temp/) in /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php on line 52
[Fri Jul 29 05:21:25.985927 2016] [:error] [pid 2429] [client 14.139.122.50:53019] PHP Warning:  is_dir(): open_basedir restriction in effect. File(/tmp/Google_Client/5f) is not within the allowed path(s): (/var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in:/var/sentora/temp/) in /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php on line 148
[Fri Jul 29 05:21:25.986025 2016] [:error] [pid 2429] [client 14.139.122.50:53019] PHP Warning:  mkdir(): open_basedir restriction in effect. File(/tmp/Google_Client/5f) is not within the allowed path(s): (/var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in:/var/sentora/temp/) in /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php on line 149
[Fri Jul 29 05:21:25.986373 2016] [:error] [pid 2429] [client 14.139.122.50:53019] PHP Fatal error:  Uncaught exception 'Google_Cache_Exception' with message 'Could not create storage directory: /tmp/Google_Client/5f' in /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php:154\nStack trace:\n#0 /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php(139): Google_Cache_File->getCacheDir('ff3dffdeef0acdf...', true)\n#1 /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php(134): Google_Cache_File->getCacheFile('ff3dffdeef0acdf...', true)\n#2 /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php(95): Google_Cache_File->getWriteableCacheFile('ff3dffdeef0acdf...')\n#3 /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Auth/OAuth2.php(315): Google_Cache_File->set('ff3dffdeef0acdf...', '{"access_token"...')\n#4 /var/sentora/hostda in /var/sentora/hostdata/zadmin/public_html/test2_ipleaders_in/process/google/google-api-php/src/Google/Cache/File.php on line 154

这是我收到的错误日志。我已经检查了文件权限,并在许多地方将其保留为 777,尤其是在错误日志中提到的 tmp 文件夹中。我拼命寻求帮助,任何见解都是有帮助的。

正如错误消息所说,似乎 php's open_basedir 设置阻止脚本从 /tmp 路径读取文件。如果您能够更改该设置,您可能需要与您的托管服务提供商核实,或者,将 application/library 设置中的临时路径更改为您有权访问的目录。

我完美解决了这个问题!

所以当我使用 Sentora 时,我在 Google 上搜索 'open_basedir Sentora',并找到了这个:http://forums.sentora.org/showthread.php?tid=1674

我创建了一个自定义虚拟主机条目:

  • 管理 > 模块管理(在 Sentora CP 上)。
  • Apache Config(这是第一个选项)。
  • 向下滚动到页面末尾并在覆盖虚拟 Host Setting 我选择我想要的网站
  • 现在在文本区域输入:Custom Entry 我输入了以下内容:

    php_admin_value open_basedir none

现在 Google 脚本运行良好!感谢@Unix-One 的回答,我走在了正确的轨道上。