Google API PHP客户端遇到麻烦

时间:2016-07-28 23:43:17

标签: php google-api digital-ocean

我已经尝试了一切,但似乎无法简单地让它发挥作用。

我在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 Panel,普通的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文件夹中。我极力寻求帮助,任何见解都是有帮助的。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我很好地解决了这个问题!

因此,当我使用Sentora时,我在Google上搜索了“open_basedir Sentora”,并发现:http://forums.sentora.org/showthread.php?tid=1674

我制作了一个自定义虚拟主机条目:

  • 管理员>模块管理员(在Sentora CP上)。
  • Apache Config(这是第一个选项)。
  • 向下滚动到页面末尾,在“覆盖虚拟”下 主机设置我选择了我想要的网站。
  • 现在在文本区域输入:自定义条目我输入以下内容:

    php_admin_value open_basedir none

现在Google Script工作正常!感谢@ Unix-One的回答,我走在正确的轨道上。