Anda di halaman 1dari 34

WordPress on Amazon Web Services from Start to Finish

Presented by Michael Bastos, BSCS Follow me on Github... https://github.com/bastosmichael http://bit.ly/KiFciT

@bastosmichael

http://bit.ly/KiFciT

About Me
Brazilian living in SD, 8 yrs in Marine Corps Started using WordPress in 2009 Work with C++, Java, Perl, PHP (some Ruby), Bachelor of Science in CS. Currently Engineer at Gap Intelligence Run Advanced WordPress Facebook Group

@bastosmichael

http://bit.ly/KiFciT

Plug facebook.com/groups/advancedwp/

@bastosmichael

http://bit.ly/KiFciT

Quick Disclaimer...
If you don't want to maintain your own server environment, don't use AWS... If you don't want to be your own server admin or need constant support from someone, don't use AWS... If you have no idea about anything that I just said, don't use AWS...
I will be very technical...

Other fast alternatives for WordPress: WP Engine, Page.ly, Media Temple, Heroku...

@bastosmichael

http://bit.ly/KiFciT

Sign up for Amazon Web Services


Visit http://aws.amazon.com/console/ You'll need a credit card to register! Make sure you have the following services
EC2 (Elastic Cloud Computing) Route53 (DNS Manager) RDS (Relational Database Service) S3 (Simple Storage)

@bastosmichael

http://bit.ly/KiFciT

Start with the EC2 Console

We will only focus on these 5 areas...

@bastosmichael

http://bit.ly/KiFciT

Step 1) Go and Create a Key Pair

Make sure to give it a name...

@bastosmichael

http://bit.ly/KiFciT

You will then Download your Key


Make sure to put your Key Pair in the place where your terminal window begins You'll handle *.pem files differently on a Mac and Linux Machine than you will on Windows

Where to place your Key Pair *.pem (Linux & Mac Desktops)
Linux Desktop user's should place file in home directory or it's .ssh folder. I.E. "/home/your_user_name" or "/home/your_user_name/.ssh" To get to your .ssh folder in command line type "cd ~/.ssh" Mac user's should place file in home directory's .ssh folder as well . I.E. "/Users/your_user_name/.ssh"

@bastosmichael

http://bit.ly/KiFciT

Where to place your Key (Windows)


Download PuTTY & PuTTYGen to your Desktop - http://bit.ly/KiprZ8

@bastosmichael

http://bit.ly/KiFciT

Open the PuTTYGen.exe program


Your screen should look like the image. Take your . pem file and convert it into a putty private key.

@bastosmichael

http://bit.ly/KiFciT

You've now loaded the *.pem file


Select Save private key. You can save it without a pass code. It saves as a *.ppk on your Desktop

@bastosmichael

http://bit.ly/KiFciT

2) Modify your Security Group

@bastosmichael

http://bit.ly/KiFciT

3) Start an Ubuntu Instance

@bastosmichael

http://bit.ly/KiFciT

Check Key Pair and Security Group

@bastosmichael

http://bit.ly/KiFciT

Make sure to change Security Group

@bastosmichael

http://bit.ly/KiFciT

Launch your Instance when correct

@bastosmichael

http://bit.ly/KiFciT

4) Allocate an Elastic IP for Instance


Choose an EC2 IP Select the ID for the Instance you just started

@bastosmichael

http://bit.ly/KiFciT

Right Click to view Connect option

Copy ssh command..

Be sure to login with username "ubuntu@" instead of "root@"

5) Now Open a new Terminal (Linux Desktop & MacOSX)


Linux Desktop users can log into their servers via ssh like so "ssh -i server.pem ubuntu@ElasticIP" Mac users can log into their servers via like so "ssh -i ~/.ssh/server.pem ubuntu@ElasticIP" You may need to do a "chmod 400 *.pem" in order to get this working

@bastosmichael

http://bit.ly/KiFciT

Using the PuTTY terminal (Windows)

Click putty. exe on your Desktop and enter the Elastic IP

@bastosmichael

http://bit.ly/KiFciT

Select Data Option on the left

Make sure to make your Auto-login username "ubuntu" instead of "root"

@bastosmichael

http://bit.ly/KiFciT

Select SSH and Auth on the left


Remember that *.ppk file we created with PuTTYGen? Click Browse and add it, then hit open.

@bastosmichael

http://bit.ly/KiFciT

6) Instal Web Server (Nginx)


sudo su apt-get install mysql-server mysql-client apt-get install nginx /etc/init.d/nginx start

Now that your terminal is open, go ahead and run the following commands... $ sudo apt-get update

@bastosmichael

http://bit.ly/KiFciT

7) Install PHP-5 FPM


apt-get install php5-fpm php-apc php5-mysql php5-curl php5-gd php5-idn php-pear php5imagick php5-imap php5-mcrypt php5memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5tidy php5-xmlrpc php5-xsl /etc/init.d/php5-fpm restart vi /etc/nginx/sites-available/default
http://bit.ly/QZTPsB -> Use for Default Domain

/etc/init.d/nginx restart

@bastosmichael

http://bit.ly/KiFciT

8) Install Postfix for mail()


pear install mail pear install Net_SMTP pear install Auth_SASL pear install mail_mime

This will replace sendmail() with postfix apt-get install postfix

@bastosmichael

http://bit.ly/KiFciT

9) Install WordPress Now


mkdir -p ~/your_domain/ cd /tmp wget http://wordpress.org/latest.tar.gz tar xvfz latest.tar.gz cd wordpress/ mv -R * ~/your_domain/ chown -R www-data:www-data ~/your_domain mv ~/your_domain/wp-config-sample.php ~/your_domain/wp-config.php

@bastosmichael

http://bit.ly/KiFciT

10a) Create MySQL Database


mysqladmin -u root -p create database mysql -u root -p mysql> GRANT ALL PRIVILEGES ON database.* TO 'admin'@'localhost' IDENTIFIED BY 'your_password'; mysql> GRANT ALL PRIVILEGES ON database.* TO 'admin'@'localhost. localdomain' IDENTIFIED BY 'your_password'; mysql> FLUSH PRIVILEGES; mysql> quit;

@bastosmichael

http://bit.ly/KiFciT

10b) Create an RDS Instance


https://console.aws.amazon.com/rds/home Once you've created the RDS Instance, connect to it in command line
mysql -hRDShostaddress -uUsername -p create database wordpress;

Now when you modify wp_config.php, keep all of these configuration changes in mind. Create as many databases as you'd like in RDS, pay attention to scale and size

@bastosmichael

http://bit.ly/KiFciT

11) Modify wp-config.php


vi ~/your_domain/wp-config.php define('DB_NAME', 'database'); define('DB_USER', 'admin'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');

Don't forget to add salting to your site.


https://api.wordpress.org/secret-key/1.1/salt/

@bastosmichael

http://bit.ly/KiFciT

12) Create a new Nginx Host


vi /etc/nginx/sites-available/your_domain
http://bit.ly/QZTPsB

cd /etc/nginx/sites-enabled/ ln -s /etc/nginx/sites-available/your_domain your_domain Replace "_" if hosting multiple sites.


server_name _;

Change to "/home/ubuntu"
root /var/www;

/etc/init.d/nginx reload

@bastosmichael

http://bit.ly/KiFciT

13) Now go to your IP and or Domain

@bastosmichael

http://bit.ly/KiFciT

What you should know?


You can take your ElasticIP and use with your DNS service to point domain to server
Route53 is the best DNS service for AWS (cheap)

Use Amazon RDS instead of localhost to host your database, S3 to store your files. Amazon CloudFormation has a WordPress blog stack both for single and RDS

@bastosmichael

http://bit.ly/KiFciT

Do we have any questions?


Credits

Stephen (MacOSX) and Devin (Windows) WP-CLI Presentation - http://bit.ly/RQahN8


Advanced WordPress on Facebook