ラボ > PHP:GoogleAPI、Google関連OS:Linux

GoogleAPIを実行すると「Could not resolve host」が出てきた

作成日:2019-03-13, 更新日:2023-04-06

経緯

1.新しいサーバ環境に「GoogleClientからGoogleAPI(翻訳API)を使う」っていうプログラムを置いて実行。
2.エラーが出てきた

Fatal error: Uncaught Google\Cloud\Core\Exception\ServiceException: cURL error 6: Could not resolve host: translation.googleapis.com;
Name or service not known (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in 〇〇〇

「cURL error 6: Could not resolve host」で調べる

・「/etc/resolv.conf」のDNS設定がおかしい
→そんなコト言われても知らん。別の理由を探してみた。

「cURL error 6: Could not resolve host: translation.googleapis.com」で調べる

・「apacheの再起動が必要」って感じのコトを言っている

▼参考:「cURL error 6: Could not resolve host: www.googleapis.com」の「irasmaster commented on 20 Apr 2017」の部分

Puppet updated libc, after what apt should restart dependant services, including php-fpm, but it didn't. 
So solution was the script to restart PHP after every package update.

→「restart PHP after every package update」とあるので「apache再起動でいいんじゃないの?」と推測

対応

・apacheを再起動
→「service httpd status」を実行するも・・・よくわからん。
→「/etc/init.d/httpd status」を実行しようとしたら・・・「/etc/init.d/」の中に「httpd」がいないということに気付いた。

ひとまず挫折→サーバ管理者に上記内容を記載して丸投げして完了
※PHP側でのUNIXソケットの設定か何かが問題あったそうだ。