Wordpress in EC2

The purpose of this document is to explain how to install the a blog in an Amazon EC2 micro instance.

1. Instance creation

    • Create a new micro instance, bind it to the VPC network

    • Add an elastic (public) IP

2. Add a 10G EBS store for the DB. (Root partitions are not persistent.)

    • Elastic Block Store > Volumes > Create volume

    • Name the volume by adding a tag called "Name"

    • Right click the named volume and attach it to the instance (e.g., as /dev/sdf)

    • Log in to the machine and find the new device

  • sudo su -

  • cat /proc/partitions

[ec2-user@ip-10-0-1-101 ~]$ cat /proc/partitions major minor #blocks name 202 1 8388608 xvda1 202 80 10485760 xvdf

  • mkfs.ext4 /dev/xvdf

  • mkdir /mnt/blog

  • mount /dev/xvdf /mnt/blog/

  • mkdir /mnt/blog/html

  • mkdir /mnt/blog/mysql

3. Apache install

  • sudo yum -y install httpd php php-mysql

  • cd /var/www/

  • sudo rmdir html

  • ln -s /mnt/blog/html html

  • vim /var/www/html/test.php

    • # Enter just "<?php phpinfo() ?>"

  • chown

  • service httpd start

    • # Make sure you can see that page at http://10.0.1.101/test.php

  • service httpd stop

  • rm /var/www/html/test.php

  • vim /etc/httpd/conf.d/jgs_blog.conf

<VirtualHost 10.0.1.101:80> ServerName blog.jgs.im ServerAdmin hostmaster@jgs.im DocumentRoot /var/www/html DirectoryIndex index.php <Directory /var/www/html/> AllowOverride All Order Deny,Allow Allow from all </Directory> </VirtualHost>

  • service httpd reload

4. MySQL install on the /mnt/blog

sudo yum -y install mysql55 mysql55-server # Find the datadir for mysql in /etc/my.cnf: /var/lib/mysql cd /var/lib rmdir mysql ln -s /mnt/blog/mysql mysql service mysqld start mysqladmin -u root create jgs_blog /usr/bin/mysql_secure_installation # Secure it as appropriate

5. Database export/import

mysql -u root -p'<password>' -h 127.0.0.1 CREATE USER 'jgs_blog'@'localhost' IDENTIFIED BY '<password>'; GRANT ALL PRIVILEGES ON jgs_blog.* TO 'jgs_blog'@'localhost'; FLUSH PRIVILEGES; select * from mysql.user; # Confirm jgs_blog exists mysqldump --user='root' --password="<password>" --host='physical-db' --single_transaction 'jgs_blog' > /root/jgs_blog_2013-02-16.sql # This dumps the DB from existing host mysql -u root -p'<password>' -h 127.0.0.1 jgs_blog < /home/ec2-user/jgs_blog_2013-02-16.sql # This imports the DB to the new host

6. Import Wordpress php

Existing physical wordpress machine

tmp_dir="/root/tmp/blog" blog_dir="/var/wordpress" mkdir -p ${tmp_dir} cd ${tmp_dir} tar -cvzf blog.tgz ${blog_dir} scp blog.tgz root@blog.jgs.im:/root/

Now on middleman SCP server

scp -i jgs-devleopers.pem blog.tgz ec2-user@web-blog.vpc:/home/ec2-user scp -i jgs-devleopers.pem ec2-user@web-blog.vpc

Now on jgs-blog.vpc

sudo su - cd /home/ec2-user tar -xvzf blog.tgz mv var/wordpress/* /var/www/html cd /var/www/html chown -R apache:apache . chown -R root:root wp-admin/ chown -R root:root wp-includes/ chown -R root:root wp-content/plugins/ vim wp-config.php define('DB_NAME', 'jgs_blog'); define('DB_USER', 'jgs_blog'); define('DB_PASSWORD', '<password>'); define('DB_HOST', '127.0.0.1'); service httpd restart

[Edit]