0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

EC2上にwordpressインストール後に「Error establishing a database connection」

Last updated at Posted at 2025-04-06

状況

AWS EC2上に
・Apacheのインストール
・MySQLのインストール
・WordpressのLinux上での初期設定
を終えた状況で
IPにアクセスすると次のような画面になる
image.png
これはWebサーバー(例:WordPressやLaravelなど)からMySQLに接続できていない状態です。

原因と解決

・この状況になっている場合webサーバにアクセスができているためEC2の設定は問題ないことが多いです。
可能性としてはwordpressのconfigの設定を行っていないかまたは間違っていることが挙げられます
EC2に入った状態で以下のコマンドで設定を確認します

nano wordpress/wp-config.php

するとこの表記が見えるはずです

define( 'DB_NAME', 'databese_name_here' );

/** Database username */
define( 'DB_USER', 'usernamr_here' );

/** Database password */
define( 'DB_PASSWORD', 'password_here' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

ここに正しいpassword/username/databesenameが書き込まれているか、間違いがないか確認しましょう。

最後にApacheとmySQLを再起動してエラー修正終了です。

sudo systemctl restart httpd
sudo systemctl restart mysqld
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?