Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Thursday, June 5, 2014

Setting up Wordpress on Elastic Beanstalk

ElasticBeanStalk is a service that automates scaling, load-balancing, and deploying applications so you can concentrate on only software development. In a way, it is very similar to Google App Engline.

In this article, we will visit how we can set up Wordpress on Elastic Beanstalk.


Configuration the Elastic Beanstalk Environment

First log into your ElasticBeansTalk and click on Create a New Application.

Enter the Application Name and Description and click Next.

Click on "Create one now" to create a new environment.

Environment tier: Web Server 1.0
Predefined configuration: PHP
Environment type: Load balancing, autoscaling

Note for Environment tier, Web Server handles web requests (HTTP/S) while workers handle background processes.

Choose sample application for now

You will then be prompted to input an Environment Name. Label it whatever, as we will use CNAME later.

For Additional Resources, check create an RDS DB instance with this environment.

In Configuration Details, select your EC2 key pair and leave the other details as it is. You can always change these later.

For RDS configuration, put 5GB for allocated storage. Input the username and password. Select Create snapshot and single availability zone.

Click Launch.

Once it's launched, click Configuration on the left sidebar, then Software Configuration. In PARAM1, set to production, staging or something else.


Installing Wordpress

We need to have different wp-config files for local development and Elastic BeanStalk. Let's define the local config as local-config.php.

Set up wordpress in your local computer. 

In wp-config, replace the database configs with the following: 

if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
    define( 'WP_LOCAL_DEV', true );
    include( dirname( __FILE__ ) . '/local-config.php' );
} else {
    define( 'WP_LOCAL_DEV', false );
    define('WP_HOME','');
    define('WP_SITEURL','');
    define('DB_NAME', 'database');
    define('DB_USER', 'username');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');
}

Fill in the above db_name, db_user, db_password, db_host with the appropriate settings.

Create a file called local-config.php at the same directory as wp-config.php

Put in the following with your local database information.

<?php
    define('WP_HOME','');
    define('WP_SITEURL','');
    define('DB_NAME', '');
    define('DB_USER', '');
    define('DB_PASSWORD', 'root');
    define('DB_HOST', '');


Install AWS ElasticBeanstalk Tools and AWSDevTools

Download  from http://aws.amazon.com/code/6752709412171743

Read this: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.GetSetup-devtools.html

Check to make sure eb is running properly:

eb --version

Configure your ElasticBeanstalk Git settings:

git aws.config

Reading Credentials from C:\Users\Kenneth\.elasticbeanstalk\aws_credential_file.

The file does not exist.  You can supply credentials by creating the file or editing .elasticbeanstalk/config to reference a different file.
The credential file should have the following format:

AWSAccessKeyId=your key
AWSSecretKey=your secret

AWS Access Key:
AWS Secret Key:
AWS Region [default to us-east-1]: (Check this in your Elastic Beanstalk console)
AWS Elastic Beanstalk Application: <put in the application name you created above>
AWS Elastic Beanstalk Environment: <put in the environment name you created above>

Check if Elastic Beanstalk can detect your app:

eb status --verbose

Now deploy your application:

git aws.push

Remember to use Route53 to map to Elastic Beanstalk.

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customdomains.html

After you point the domain to the Elastic Load Balancer. If the site does not load up in the browser, do not panic. Give it 15 mins. It will be back up.

Thursday, January 17, 2013

Running Wordpress on Amazon EC2


This article is about how to install Wordpress on Amazon EC2 with MySQL running on Amazon RDS.


Launch a EBS-backed AMI

In the ec2 console,  click launch select Ubuntu Server 12.04.1 LTS 64-bit (AMI id = ami-3d4ff254).
Use t1.micro.
Set delete on termination to false for the root device.
Set termination behaviour to Stop.
Add port 22, 80, 443 for security group


Install Software

sudo apt-get update
sudo apt-get install apache2 libapache2-mod-auth-mysql php5-mysql mysql-client libapache2-mod-php5

We are not going to install mysql-server, since we will be using RDS.


Use Amazon RDS as the database

If you want to set up your own MySQL database, you can do so. For the purpose of this tutorial, we will use Amazon RDS because it takes care of scaling, replication and backups (to S3) without minimim effort.

Read Using MySQL on Amazon RDS to create a MySQL database.

After you created a database, note the database name, username, password, and endpoint address of the DB instance. The endpoint address will be like wordpress.a2ks0zoxdxq.us-east-1.rds.amazonaws.com.

You can ssh into your ec2 instance and run the mysql command to access the database.

mysql -h {endpoint_address} -P 3306 -u{username} -p{password}

Note that when I used a different syntax for the above mysql command, I kept on getting access denied error. Please use the syntax I specified above.


Download Wordpress

sudo mkdir /var/www
cd /var/www
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rm latest.tar.gz
mv wordpress {name_of_your_blog}


Configure Wordpress

mv wp-config-sample.php wp-config.php
vi wp-config.php

Change these:

define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

The DB_HOST will be the endpoint we specified above. Include the port :3306 as well.
Ex. wordpress.a2ks0zoxdxq.us-east-1.rds.amazonaws.com:3306

Generate keys for the following:
https://api.wordpress.org/secret-key/1.1/salt/

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

Configure Apache

cd /etc/apache2/sites-available
cp default wordpress
vi wordpress

Change DocumentRoot and Directory from /var/www/ to your blog's directory.

Change AllowOverride from none to all. (If you don't do this, you can't do pretty links in Wordpress.)


                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
       

Save the File.

a2dissite default
a2ensite wordpress

a2enmod rewrite

service apache2 reload

Launch the site

If you are starting a new Wordpress site, access the site from the browser, and following the on screen instruction and you are done.


Porting data from local MySQL to RDS MySQL

To export data:

mysqldump -u{username} -p{password} -h {host} {database} > backup.sql

To import data:

mysql -u{username} -p{password} -h {host} {database} < backup.sql


Creating a Wordpress EBS-backed AMI


The goal is to create a customized Wordpress image that can be quickly launched for scaling purposes.
When an instance is launched with this image, all services (Apache, MySQL, etc) should start on boot and resume normal operations.

Steps for creating a Wordpress AMI:
  1. Launch a EBS-backed AMI instance (MUST be EBS-backed, not instance store-backed)
  2. When the instance is running, install required software and load applications (Apache, Wordpress).
  3. Create an image from the instance

Note that if you attach new volumes, the new AMI will contain block device mapping information for those volumes. When you launch an instance with the new AMI, the instance will launch additional volumes.

1 & 2) Launch a running Wordpress Instance

Follow Running Wordpress on Amazon EC2 to launch a running instance with all Wordpress software installed.

3) Create an image from the instance

In the AWS Management Console, click instances at the left sidebar.

Right click on the Wordpress instance created above and click on Create Image.

Fill in the image name. I like to name things in a convention that is systematic. If you are planning to write deploy scripts and do auto-scaling, it is easier to identify what an image is. I use the following convention:

{namespace}_{what_is_it}_{date}

Ex. mycompany_blog_20130118

You will want the date because you may create an image every time you deploy new codes.

Leave the other options as default, and click on Create Image.

On the left sidebar, click on AMIs under Images.

You can see the status of the AMI we just created.

You should launch an instance from this AMI and test all the data is there.