LoginSignup
0
0

More than 3 years have passed since last update.

AWS Cloud9 環境の WordPressでブラウザに表示されなくなった時の解決

Last updated at Posted at 2020-05-06

現象

現在割り当てられているIPを確認する。

$ echo $C9_HOSTNAME
aaa.aaa.aaa.aaa

ブラウザURLの欄に
http://aaa.aaa.aaa.aaa/wordpressのルートディレクトリ名
を入れると、Status Code: 200 を正常に返すが、
応答に時間がかかり正しく表示されない。

AWS Cloud9のWordPress開発を継続して行っていたが、ブラウザで動作確認しようとすると、
「このサイトにアクセスできません 応答時間が長すぎます」とのメッセージが出て表示できなくなった。

開発環境(AWSを使用)

  • WordPress 5.2.2
  • PHP 7.3.15

  • Cloud9 + EC2 instance type: t2.micro

  • httpd Apache/2.4.39 (Amazon)

  • mysql Ver 14.14

原因

コストを抑えるため、EC2インスタンスの停止時間を30分に設定している。
インスタンスが停止から再起動すると、IPアドレスは動的割当のため変更になる。

解決方法

WordpressのDBに設定されているIPアドレスを確認

wp_optionsテーブルのoption_nameカラム、homeとsiteurlに設定がある。

ルートディレクトリ WordPress
DB名 wordpress

$ mysql -u root wordpress -e "select * from wp_options where option_name='siteurl' or option_name='home';";
+-----------+-------------+----------------------------------+----------+
| option_id | option_name | option_value                     | autoload |
+-----------+-------------+----------------------------------+----------+
|         2 | home        | http://xxx.xxx.xxx.xxx/WordPress | yes      |
|         1 | siteurl     | http://xxx.xxx.xxx.xxx/WordPress | yes      |
+-----------+-------------+----------------------------------+----------+

xxx.xxx.xxx.xxx がwordpressに設定されているIP
このxxx.xxx.xxx.xxxを正しいIP(aaa.aaa.aaa.aaa)に更新する

WordPressのwp_optionsテーブルの修正

※ターミナル上から修正

$ mysql -u root wordpress -e "update wp_options set option_value='http://$C9_HOSTNAME/WordPress' where option_name='siteurl'";
$ mysql -u root wordpress -e "update wp_options set option_value='http://$C9_HOSTNAME/WordPress' where option_name='home'";

wp_optionsテーブルの更新できたか確認してみる

$ mysql -u root wordpress -e "select * from wp_options where option_name='siteurl' or option_name='home';";

+-----------+-------------+----------------------------------+----------+
| option_id | option_name | option_value                     | autoload |
+-----------+-------------+----------------------------------+----------+
|         2 | home        | http://aaa.aaa.aaa.aaa/WordPress | yes      |
|         1 | siteurl     | http://aaa.aaa.aaa.aaa/WordPress | yes      |
+-----------+-------------+----------------------------------+----------+

Apacheの再起動

$ sudo service httpd restart

MySQLの再起動

$ sudo /etc/init.d/mysqld restart

表示確認
http://aaa.aaa.aaa.aaa/WordPress

補足

もし、Status Code: 301 Moved Permanently (from disk cache)を返してリダイレクトされていたら、
キャッシュをクリアする。
また、動的IPに起因することなので、静的IPアドレス(Elastic IP アドレス)の利用をするか、開発期間中はEC2インスタンスの環境停止を「Never」に設定するなど、コスト面を踏まえて検討する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0