WordPress Jetpack Can not resolve your domain A record(xml-rpc.php)

公司行銷部門的同事前兩天突然敲我,問我說要怎麼在 WordPress 裝上 Jetpack 然後跟 wordpress.com 帳號做連結,原本心裡想說雖然沒裝過 Automattic 出品的 Jetpack,不過裝個 WordPress 插件好像也不會難倒我,自信的登入後臺之後才發現不是這麼一回事…。

看到行銷部門的同事已經把 Jetpack 裝好了,按下 連結 Jetpack 按鈕後,Jetpack 頁面出現了 錯誤詳細信息:

重點是:後面就沒有任何訊息了… ,後來上網找了一下資料,發現 Jetpack 有一個 debug 模式。

在 WordPress 網址後面加上:

wp-admin/admin.php?page=jetpack-debugger

There seems to be a problem with your site’s ability to communicate with Jetpack! It looks like your site can not communicate properly with Jetpack.

看到一堆錯誤訊息,找到一段可能比較像是錯誤提示的:

1
[body] => {"error":"Can not resolve your domain \"A record\"","error_description":"We were unable to resolve the A record for your domain. It is likely that you have recently registered your domain name. It takes several hours for new or transferred domain names to start working, so please come check back later. If you're still having the same error after 48 hours, please contact your web hosting provider."}

然後一直朝著 Can not resolve your domain A record 去找問題,發現網路上很多人問了同樣的問題,只是官方人員都建議點 support 回報問題 =口=

突然發現另外一條路,Jetpack 官方有提供一個 Debug 的網站

Jetpack for WordPress

輸入網址後顯示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Debug XML-RPC is not responding correctly ( 500 )

It looks like XML-RPC is not responding correctly. Please make sure XML-RPC is turned on for your site and is set up to respond to all content types. You can test this yourself by running the following command from the command line:

curl -A 'Jetpack by WordPress.com' -d '<methodCall><methodName>demo.sayHello</methodName></methodCall>' https://blog.***.com/xmlrpc.php
The answer should be:

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<string>Hello!</string>
</value>
</param>
</params>
</methodResponse>

在 Linux 下面輸入

1
curl -A 'Jetpack by WordPress.com' -d '<methodCall><methodName>demo.sayHello</methodName></methodCall>' https://blog.***.com/xmlrpc.php

發現回傳值是空白

加上 -is -H 看一下 Server 的回傳結果

1
2
3
4
5
6
HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Sun, 04 Dec 2016 06:47:03 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive

接著去翻一下 Nginx 的 error_log,感覺發現曙光

1
2
3
4
5
6
7
8
9
2016/12/03 17:00:42 [error] 1126#1126: *10914 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function xml_parser_create() in /var/www/***/blog/wp-includes/class-IXR.php:264
Stack trace:
#0 /var/www/***/blog/wp-includes/class-IXR.php(464): IXR_Message->parse()
#1 /var/www/***/blog/wp-includes/class-IXR.php(432): IXR_Server->serve('<?xml version="...')
#2 /var/www/***/blog/wp-includes/class-IXR.php(440): IXR_Server->__construct(Array, false, false)
#3 /var/www/***/blog/wp-includes/class-wp-xmlrpc-server.php(197): IXR_Server->IXR_Server(Array)
#4 /var/www/***/blog/xmlrpc.php(84): wp_xmlrpc_server->serve_request()
#5 {main}
thrown in /var/www/***/blog/wp-includes/class-IXR.php on line 264" while reading response header from upstream, client: 192.3.83.64, server: blog.***.com, request: "POST /xmlrpc.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "blog.***.com", referrer: "https://blog.***.com/"

其中的 Call to undefined function xml_parser_create() 感覺跟目的解答有 87% 像。

1
sudo apt-get install php7.0-xml
1
sudo systemctl restart php7.0-fpm.service

在用 curl 測試一次

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Sun, 04 Dec 2016 07:04:29 +0000
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<string>Hello!</string>
</value>
</param>
</params>
</methodResponse>

進後臺錯誤訊息也不見了!

感覺被沒裝 PHP 套件雷了好多次,真的有點考慮

1
sudo apt-get install php7.0-*
1
2
Need to get 55.0 MB of archives.
After this operation, 214 MB of additional disk space will be used.

好像也還可以接受(?)