2014-08-05

Amazon Web Services  (AWS) offer a way to host your own WordPress sight with no hardware and little to no expense on a small WP blog site. This is ideal if you want to start working with a self hosted WordPress site for developmental purposes, monetization of your blog, or just good ol’ bragging rights.

In this article I will go into an overview of the EC2 service and the various Virtual Machines (referred to as instances from here on out) that are free and paid. Some may be free to download and initially spin up but may incur an additional cost to the AWS price tier even if you are in the Free Tier. Even though I discuss the free tier exclusively and micro-instances it should be mentioned that the AWS allows for scalability of your WordPress site so it can grow as your site(s) grow.

There are various pre-made instances for use with your AWS account that are configured for just about “one touch” configuration. Some are free, others are free to upload to AWS but incur a usage cost, and others cost for upload and usage. A few of the providers are; Bitnami, JumpBox, and Turnkey Linux. If you do choose to go with these “one click” solutions be sure to read all the print to verify if there are any charges for the instance or use of and how the charges are calculated.



Above I mentioned the for purchase instances, they have all the services installed that are needed to make a WordPress site into a Linux operating system. First though you will need to set up an  WC2 Amazon Web Services account. Amazon has a wonderful step by step tutorial and FAQ outlining this process so I will not go through those steps. Below is a video from the tutorial page addressing the initial setup of the account.

Set Up a Base Instance

To set up your base instance, begin step one accordingly:

On the services page of your account, select the EC2 service to go to your Control Panel.

In the left hand panel you will see Instances, and under that heading a link for Instances. This link goes to the Management page for your EC2 instance.

In the middle of the page, click the big blue button titled “Launch Instance” to go to the selection screen.

Choose the Amazon Machine Image (AMI). Use the Amazon Linux AMI instance as it will have most of the services you need and not much fluff.

You will need to add a few services, Apache, MySQL, and PHP to create your LAMP server to host WordPress. This particular instance is listed at the top of the Step 1: Choose an Amazon Machine Image (AMI).

Step 2 involves choosing the instance type. To qualify for the free tier, use the micro instance as discussed earlier.

Step 3 involves configuring instance details. Keep defaults as you want to stay in EC2-Classic and the other defaults will work perfect for the instance to install the LAMP services to support your WordPress site.

The fourth step is adding storage. The default is 8 GB which is more than enough. If you find you need more at a later time you can add another partition to the instance but if you are needing more storage than it looks like your site is rocking and you have more traffic than the micro-instance can handle. Again just keep the defaults on this page and click next and move to the next step.

Step 5: Tag Instance step: By tagging your EC2 instance you can categorize for better instance management if you start to run more than one instance. You can also tag other AWS resources to help keep track of linked or grouped resources.

Security for your instance is now configured in Step 6: Configure Security Group. Name your security group this instance will belong to (if you do not already have a security group defined on AWS which you wish to use). This is an important step and allows you to remotely connect to the instance once you have it running.

As shown below, there are two basic security rules you need so you can connect to the instance and install the necessary services for WordPress to run and be able to connect to the instance via the WordPress dashboard for configuration and posting to the site.

Rules to implement in the group:

SSH:

TCP: Auto-configured

Port: 22

Source: Anywhere-0.0.0.0/0 (you can define your specific IP address which you are connecting from if you do not plan to connect to the instance via SSH anywhere else)

Custom TCP Rule

TCP: Auto-configured

Port: 80 (this the port that HTTP connections use)

Source: Anywhere-0.0.0.0/0 (this is so that anyone can view your WP site as well as work on your WP site from any location)

Step 7: Review Instance Launch stage. You are ready to spin up that cloud server (instance) and start preparing it for WordPress. Review your settings, insure that you are aware of any settings which may incur a charge from Amazon before pressing the blue “Launch” button.

Launch

When you click the launch button you will be greeted with one more configuration screen before AWS actually launches the instance. This screen allows you to configure a security key pair for SSH connections or configure the instance to not use a key pair. I use a key pair personally and teach my students to do as such.

If you have not previously used AWS you will type in a phrase to act as the key name. This will allow you to down load the file which is a .pem file which you will convert later to a .ppk file for use with the free application PuTTY for your SSH connection into the instance.

When you click the Launch Instance button you will then have a download dialogue for downloading the private side of the key to your computer. Take note where you down load this key as you will use it for SSH connections with PuTTY or another SSH application.

I also copy this file into a flash drive for portability as I work on my instances from various locations and PC’s. This also give you a back up of the key, it is quite difficult to retrieve once lost.

Running the Instance

Now you will need to connect the instance to a public IP address, AWS calls them elastic IP’s

Navigate to the Elastic IP configuration page using the navigation side bar so you can request and associate an Elastic IP address to your now running instance.

This configuration will generate a Public IP address as well as a Public DNS to use for logging into your instance for further configuration as well as viewing your WordPress Dashboard and Posts.

To log in we will use the DNS and a user name of EC2-user@[publicDNS] and the private key file you will convert after the Elastic IP is configured and attached to your running instance.

You will notice that the Elastic IP address is under the NETWORK & SECURITY heading. Click this link which will take you to the IP requesting page.

Here you request your Elastic IP and then assign it to the instance you have just created. Click the Allocate New Address button to receive the IP in the list. In the example image you will see several instances assigned an IP (I have made the IP’s unreadable as these are actual running instances). You will notice there is one line with no Instance assigned to the IP and also no Public DNS associated.

Once you have an unassociated Elastic IP you will need to associate your running instance with the IP. Select the IP address then click the Associate Address button which will bring up the following screen.

Click in the Instance box and you should get a list of your instances, or start to type the Instance ID and you will get a list of your instances to associate with the IP. When you instance is in the box click the “Associate” button. Now your instance has a Public IP and DNS.

Connecting to Your Instance

As mention before, if you do not have a SSH client PuTTY is a nice free alternative. I use it extensively to remote into instances on AWS, routers, and switches which I manage. You will also need to convert the .pem file to a usable file by PuTTY; .ppk. You can do this with the PuTTYgen tool which is part of the installation package of PuTTY. Here is a little one page how to convert the EC2 .pem file to the PuTTY .ppk file. The author of the article does not use a passphrase which OK for many users but I personally go a little over kill on security so I use a passphrase as well.

With the converted pass key file you can now log in to your instance via PuTTY. Go to your Instances page via the Sidebar navigation click on your running instance which will give you needed information at the bottom of the screen. We need the public DNS to log in.

Highlight the Public DNS as it is in the image above and copy to past into the putty Host Name field as shown in image below. Before the Public DNS that you pasted in type ec2-user@ this is the default user for the  Amazon Linux EC2 instance. Insure to select SSH as the connection type.Now you need to load in the pass key you generated with PuTTYgen.

In the left window of the PuTTY screen click on the + next to SSH to open the tree and click on the word Auth. This will allow you to browse to the location of the converted pass key and load it into PuTTY.

Click open to start the connection and you should be greeted with a screen as such:

If you configured a Passphrase as I did here the system will propt you for it. Be aware as you type the Passphrase nothing will display on screen. This is a Linux security feature true of all Linux distributions when working in command line. Now before you start installing the services needed to make a WordPress site you need to update the instance.

This is very easy with the yum command. Simply type sudo yum update and Linux will look for the latest updates. When the updates are found a list will be presented for your review and a prompt will ask for a y or n telling the system to install or not to install the updates. Press y and the system will begin installing the updates. This is good practice as new security updates are normally part of the download. The update may take a few minutes so you now can take a break before you start completing the build of your LAMP server.

Once again you will use the yum command to install the needed services that make up the LAMP server. First you will install the Apache Web Service with the command sudo yum install httpd -y we use the option -y to install all of the package without you having to type y at each transaction.

Once the Apache is installed you need to start it with the command sudo service httpd start the resulting screen will be this and Linux will give you a green ok as you see in the image.

Now you should be able to see the default Apache web page by pasting your Public DNS into a web browser.

You have the A installed for Apache in LAMP. Next we will install PHP for the P in LAMP. NO not in the order of spelling but it seems to lay in better. The order I have found to work best to create your LAMP server is Linux, Apachie, PHP, and then MySQL which will take a few lines of configuration.

Start the installation with the command sudo yum install php -y. Use the -y option again to help minimize time of installation.

Now you need to install the PHP binaries for MySQL so use the command sudo yum install php-mysql. This adds the added feature set for MySQL in ingratiation with the PHP service.

Now you need to verify that the PHP services are working. To do this you will create a test file and edit it with the vi text editor that comes in every distribution of Linux. Create the file with the following command as this will also place it in the correct directory: sudo touch /var/www/html/test.php. Open the file now with sudo vi /var/www/html/test.php, the vi text editor now opens up a blank file.

Press “i” on the keyboard to insert text into the file. Enter the following code to generate a test page that will return the version of PHP you have installed in your instance: . Insure that the spaces are correct as well as case. Linux and most programing languages are case sensitive.

Save the test.php document by pressing escape (esc) on the keyboard then the colon “:” which places you in command mode in vi and press qw on the keyboard then “enter.” This saves the document and quits vi.

Now you can verify that PHP is working by opening your browser, copying the public DNS into the address bar as you did to verify that Apache was up and running and type /test.php after the address and press enter.

You should see the page above load into the browser.

Now installation and configuration of  MySQL. Type the following command sudo yum install mysql-server -y.

As in above images you will see the loading and installation process of MySQL. You need to now start the service just as you did with Apache by typing the command sudo service mysqld start. Create your “blog” database withe command sudo mysqladmin -uroot create blog. Now secure your database database by entering in the following command, remember case is imortant, mysql_secure_installation. You will see a dialogue asking for the “root” password, as none has been set press enter. The following questions will be asked:

Change Root Password: Y

Type in new root password

Remove anonymous user: Y

Disallow root login remotely: Y

Remove test database and access to it: Y

Remove privilege tables now: Y

Now you need to insure that the services Apache and MySQL will run at boot if the instance is restarted. You do this with the command sudo chkconfig httpd on  and sudo chkconfig mysqld on. These two commands insure that your LAMP server will run even if the instance goes through a reboot.

You now have a running LAMP server. You can verify the services by reloading the test.php page in your browser.

Installing WordPress

You now need to change to the /var/www/html directory for downloading the tar file for WordPress. To do this use the command d /var/www/html to verify that you are in this directory use the command pwd (present working directory).

Verifying the directory you are in is important in the next step as we are downloading the WordPress installation .tar or compressed file which will unpack in the /var/www/html directory. Now download the WordPress installation with a different command than the yum, you will use the wget command as follows wget http://wordpress.org/latest.tar.gz. Once the down load finishes you need to extract the .tar file by using the tar -xzvf latest.tar.gz command.

At this point the WordPress installation has created its own /var/www/html/wordpress directory. Yes no capitalization on the WP directory. You may choose to use this directory or create a directory called “blog.” Here I will create the /var/www/html/blog directory.

The command sudo mv wordpress blog  will create the blog directory as well as move the installation of WP there.

Now you need to adjust the settings of the WordPress config file. to do this we will move the sample config file wp-config-sample.php to wp-config.php with the command sudo mv wp-config-sample.php wp-config.php. Now open the file with vi sudo vi wp-config.php. Press “i” to start the insert mode and navigate to modify the database connection to reflect our blog MySQL database you created earlier.

define(‘DB_NAME’,’blog);

define(‘DB_USER’,’root’);

define(‘DB_PASSWORD’,’YOUR_PASSWORD’);

define(

:wq to save and quit

The above image shows the the configurations in the wp-config.php file as it is in the vi editor once you have made the entries in the areas defined in the list of changes.

Open WordPress for Configuration

Now after all the back end work on the server your WordPress site is almost ready for blogging. Open a browser to YourPublicDns/blog. This will open up the WordPress configuration page for self hosted sites.

Fill in the requested information on this page to finalize your installation. Once this is all done you need to click “Install WordPress” at the bottom of the page. Once WordPress installs you will receive a “Success” page.

Now log in and start publishing.

To make this an actual production site you will need to get a domain name and associate with your instance but that is for another article.

Show more