メールで画像付き記事をWordPressに投稿できるようにしたときのメモ
WordPressでiPhoneからのメールで画像付き記事を投稿できるようにしたときのメモ。
自宅サーバー(fedora10)ということもあって、すんなりとはいかなかった。
まずはKtai Entryをインストール。
Yuriko.Net » Ktai Entry は Gmail 対応してた
このあたりを参考に新規にgmailのアカウントを取得してPOPすることにする。
が、早速ここでつまる。
管理画面の設定を終え、gmailのサーバーにメッセージを読みにいくも、Bad Gateway。接続できない。
gmailの方の設定(メール転送と POP/IMAP)もしているのになぜだろうかと、ぐぐるも解決法が見つからない。
早速挫折しそうになる。
なにげなく/var/log/messagesを見ると、ここに解決方法が。
May 10 07:50:37 localhost setroubleshoot: SELinux is preventing the http daemon from connecting to network port 995 For complete SELinux messages. run sealert -l c040bfed-f20b-4946-a0db-8664985fefba
ということで以下コマンド実行。
sealert -l c040bfed-f20b-4946-a0db-8664985fefba
以下実行結果。(一部抽出)
Summary: SELinux is preventing the http daemon from connecting to network port 995 Detailed Description: SELinux has denied the http daemon from connecting to 995. An httpd script is trying to do a network connect to a remote port. If you did not setup httpd to network connections, this could signal a intrusion attempt. Allowing Access: If you want httpd to connect to network ports you need to turn on the httpd_can_network_network_connect boolean: "setsebool -P httpd_can_network_connect=1" Fix Command: setsebool -P httpd_can_network_connect=1
httpからの通信が許されていなかったようだ。
ということで言われるがまま以下コマンド実行。
setsebool -P httpd_can_network_connect=1
これでめでたくiPhoneからのメールによる投稿に成功。
しかし、、、画像を添付したメールだと予約投稿が失敗する。
ちなみにgmailのような外部サーバーの場合、Ktai Entryでは予約投稿からの投稿になる。
調べるとまず以下の解決方法が見つかった。
WordPressの予約投稿が失敗する件の解決方法 | Weblogy
ふむふむ。
wget http://yourdomain.com/wordpress/wp-cron.php
確かにこのコマンドが失敗したのでhostsを書き換えてwgetできるようにした。
さて、これで再度、画像付きメールによる投稿を試みるもあえなく失敗。
次に見つけた解決法。
iPhoneから記事を投稿できるようにしてみました | サヴァンに憧れて
確かにGDがインストールされていなかったので、早速インストール。
yum install php-gd /etc/rc.d/init.d/httpd restart
実はapacheを再起動するのを忘れていて、GDが反映されなくて、30分位無駄にしてしまったのは内緒。
さて今度こそうまくいくはずだったんだけどやはり失敗。
添付画像を/wp-content/uploadsディレクトリに持ってこれていないようだ。
/var/log/messagesには以下のメッセージ。
May 10 09:42:09 localhost setroubleshoot: SELinux prevented httpd reading and writing access to http files. For complete SELinux messages. run sealert -l 0e943211-964c-4d7d-90cf-d6b9511e4a53
以下コマンド実行。
sealert -l 0e943211-964c-4d7d-90cf-d6b9511e4a53
以下実行結果。(一部抽出)
Summary: SELinux prevented httpd reading and writing access to http files. Detailed Description: SELinux prevented httpd reading and writing access to http files. Ordinarily httpd is allowed full access to all files labeled with http file context. This machine has a tightened security policy with the httpd_unified turned off, this requires explicit labeling of all files. If a file is a cgi script it needs to be labeled with httpd_TYPE_script_exec_t in order to be executed. If it is read-only content, it needs to be labeled httpd_TYPE_content_t, it is writable content. it needs to be labeled httpd_TYPE_script_rw_t or httpd_TYPE_script_ra_t. You can use the chcon command to change these contexts. Please refer to the man page "man httpd_selinux" or FAQ (http://fedora.redhat.com/docs/selinux-apache-fc3) "TYPE" refers to one of "sys", "user" or "staff" or potentially other script types. Allowing Access: Changing the "httpd_unified" boolean to true will allow this access: "setsebool -P httpd_unified=1" Fix Command: setsebool -P httpd_unified=1
httpdからファイルの読み書きが許されていないようだ。
言われるがまま以下コマンド実行。
setsebool -P httpd_unified=1
これでもまだうまく画像の投稿ができない。もうへとへと。
あれこれ調べて最終的にうまくいったのは以下のコマンド実行後だった。
chcon -t httpd_sys_content_rw_t /var/www/html/blog/wp-content/uploads/2009/05
ふぅ、疲れた。。。