LoginSignup
0
1

More than 5 years have passed since last update.

AWS上でインスタンスを構築してwordpressを起動するまで

Posted at

About

wordpressをAWS上で立ち上げてみました。

利用技術

  • Terraform
  • Itamae

ソースコードはこちらです https://github.com/tjinjin/wordpress-sandbox

Terraform

main.tf
data "aws_ami" "centos" {
  most_recent = true

  filter {
    name   = "product-code"
    values = ["aw0evgkw8e5c1q413zgy5pjce"]
  }
}

resource "aws_instance" "wp" {
  ami                    = "${data.aws_ami.centos.id}"
  instance_type          = "t2.micro"
  key_name               = "tjinjin-terraform"
  vpc_security_group_ids = ["${aws_security_group.wp.id}"]

  root_block_device {
    delete_on_termination = "true"
  }

  tags {
    Name = "wordpress"
  }
}

resource "aws_security_group" "wp" {
  name        = "wordpress"
  description = "wordpress sg"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["${var.my_ipaddr}"]
  }

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["${var.my_ipaddr}"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags {
    Name    = "wordpress"
    Created = "terraform"
  }
}

output "wordpress_ip" {
  value = "${aws_instance.wp.public_ip}"
}

AMIはcentosの公式のものを使用しています。product-codeはこちらのページから判断しました。 https://wiki.centos.org/Cloud/AWS

Itamae

一部プラグインを使いつつ、他は自分で書きました。もともとchefを使っている人間だったのでhttp_request というresource名を知らなかったため、苦労しましたw

$ itamae ssh --host aws-wordpress roles/wp.rb 

これをすれば適用できます。

残作業

ここまでくればあとはmysqlの設定とwordpress上での設定だけです。

$ cat /var/log/mysqld.log | grep generate
$ mysqladmin -u root password -p
$ mysql -u root -p

mysql> create database wordpress;
mysql> grant all privileges on wordpress.* to wordpress@localhost identified by '<password>';

あとは画面で設定をすれば一応起動するところまで到達できます。

0
1
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
1