How to Install WordPress on Amazon AWS EC2
Nowadays, everyone wants to run a website and I am sure you too are looking for the same. You need to require hosting to launch your website, So I am covering step by step process to host your website with Amazon AWS Server.
If you have made your website on WordPress, you may have difficulty to upload it on the server. You may search all the possible solutions for a step by step process to do so (as we did while hosting FormGet on Amazon), but you won’t find any.
We faced some issues while uploading FormGet on the Amazon server and after solving all those hectic steps I thought it should be a subject of my upcoming post.
So, in this post, you will find a complete procedure (a step by step tutorial) of How you can upload WordPress on Amazon EC2.
Note : I assume that you have an account on Amazon Web Server (AWS). If you do not have account on Amazon then create it first.
Login into your AWS account.
Go to My Account / Console –> My Account
Login into your AWS account by entering your email address and password.
After successfully login,
Go to My Account / Console –> AWS Management Console
Select EC2 from the list of Amazon Web Services.
EC2 Dashboard appears on the screen. Now you need to create a new Instance. For that,
Go to Instance –> Launch Instance
Select Classic Wizard for the instance and click on Continue.
Choose Ubuntu Server 13.04 of 64-bit from the Amazon Machine Image (AMI) list and click on Select.
Select Instance Type T1 Micro
Click to Continue
Continue with default Instance Details.
Again click to Continue
Add tag to your Instance. For that create Key-Value pair.
Enter Value to the Name key. Lets give WordPress and go to Continue.
Create a key pair to securely connect to your instance after it launches. For that,
Go to Create a new Key Pair –> Enter a name for your key pair (lets give name wp-connect-file) –> click on Create & Download your Key Pair.
In just a click wp-connect-file.pem file downloaded into your computer.
Create a security group which helps to determine whether the network port is open/blocked on your Instance. For that,
Go to Create a new Security Group –> Enter Group Name( lets give WordPress) –> Enter Group Description –> select HTTP rule from the inbound rules list.
Click on Add Rule
HTTP Service added into the group.
Similarly select another rule SSH and added into the group
click to Continue
Review the details and click on Launch
If you want you can create status check alarms. Then click on Close.
Instance is launched now and it is at running position.
Put check on the newly created Instance. Then go to Actions –> Connect
Enter the Private key path ( location of your wp-connect-file.pem file which is stored on your machine)
Then click on Launch SSH Client.
Setup An Apache
You can see here wp-connect-file.pem file is opened now.
Bydefault user logged in as ubuntu. Switch user to root by following command.
Install Apache on your server by using command.
apt-get install apache2
After completion of Installation process.
Copy the Public DNS code.
Now, paste the code in browser’s address bar. You will see the page like this.
Above page shows that Amazon is working properly.
Install Php5 on Server
Use the following command to install Php5 on the server.
apt-get install php5
apt-get install libapache2-mod-php5
If your php installation fails with a message such as “Unable to fetch some archives…” then run the following command and repeat the above process.
Create a php test file ( let say mytest.php) to test php5 is running properly or not. Use the following command to do so.
Php test file is created. Now insert the content in the file by following sub-steps.
1. To switch into insert mode. Press i
2. Type <? php phpinfo() ?>
3. Press esc key to escape from insert mode.
4. Type :wq to write content in the file and quit form the editor.
Run the mytest.php file in your browser.
Use the address like this –> public DNS/mytest.php
The above page shows that PHP is running properly on your Apache.
Use the command to install MySQL server.
apt-get install mysql-server
Enter password for the MySQL root user in the respective field.
Re-enter the above password for confirm.
To run Php5 with MYSQL use command.
apt-get install php5-mysql
Install PHP module for MYSQL by following command.
apt-get install libapache2-mod-auth-mysql
Use the following command to Install phpMyAdmin on your server.
apt-get install phpmyadmin
Select apache2 web server.
Go with Yes to configure database for phpmyadmin.
Enter password for the user admin.
Enter MySQL Application password for phpmyadmin.
If error generate while installing database then choose ignore to continue with the operation.
You need to configure Apache to make phpmyadmin accessible via browser.
Use the following command to configure Apache.
To make phpMyAdmin accessible via browser use the command
ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
Restart Apache web server to pick up the changes by following command.
Now you can access phpmyadmin in your browser.
Use the address like this –> public DNS/phpmyadmin
Go to Database for creation.
Create database (lets say wordpress)
Database is created now as you can see in the image given below.
Installation of WordPress
Navigate to home directory of the server by using command.
Download the latest copy of the WordPress by using following command.
Extract it to the /var/www directory
tar -xzvf latest.tar.gz -C /var/www
Bydefault all files will be extracted in a directory “wordpress”.
So to move the files to root of the web server by using command given below.
cp -avr /var/www/wordpress/* /var/www
Now remove the “wordpress” directory by using command.
rm -rf /var/www/wordpress
Mapping Domain Name With Instance IP
Before you install WordPress you need to map domain name with the virtual server.
Select the newly created instance and then click on Elastic IPs listed in EC2 Dashboard.
Click on Allocate New Address
A window appears on the screen for Allocate New Address.
Click on Yes,Allocate.
Now go to Associate Address.
Select your Instance from the drop-down list and then click on Yes,Associate.
You can see here Elastic IP is now associated with your Instance.
Now run this Elastic IP in the address bar of your browser.
From the above image it is clear that it will work perfectly.
Open WordPress Installation Page
Enter the Elastic IP followed by index.php in the address bar of your browser.
Click on Create a Configuration File.
Continue with the next step by click on Let’s go!
Enter the database connection details.
Setting FTP Access To Your Server
Install FileZilla On Your Machine.
Now open FileZilla and then go to Edit –> Settings….
Under Settings select SFTP from the list and then click on Add keyfile…
Convert your wp-connect-file.pem in a format supported by FileZilla.
For this, click on Yes
Now the above file is converted into wp-file-connect1.ppk format.
Establish Connection With Server
Go to File –> Site Manager…
Under General Settings of Site Manager.
Create New Site (lets say wordpress_1)
Enter Elastic IP Address under Host field –> Select SFTP – SSH File Transfer Protocol –> Choose Logon Type as Normal —>Named user as ubuntu –> click on Connect.
Under Advanced Settings of Site Manager.
Select Server Type Unix —> Enter path of local directory of your machine -> click on Connect.
Connection is established now.
Follow the path ( … –> var –> www –> index.html)
In order to execute WordPress perfectly on your browser you need to delete this index.html file.
But, you are not allowed to delete index.html file right now.
Before deleting index.html file do following steps
Write the following command in the wp-connect-file.pem.
Below command allow you to write access to /var/www
sudo chown -R www-data /var/www
Follow the path ( … –> var –> www –> index.html)
Select index.html file –> do right click –> File permissions…
Change the permissions of the index.html file by put check on the highlighted Write and Execute fields appear in the image given below and then click on OK.
After make changes in file attributes.
Now delete this index.html file permanently.
Enable htaccess and URL Rewrite
You need to edit default Apache file by writing following code in the wp-connect-file.pem.
sudo vim /etc/apache2/sites-available/default
Press i to switch into insert mode.
Change the setting of AllowOverride from None to All
Now hit esc key to escape from insert mode.
And write :wq –> to write the changes in the file and exit from the editor.
Restart the Apache web server for changes to take effect by writing following command.
sudo /etc/init.d/apache2 restart
Now run the WordPress on Amazon EC2.
For that, paste Elastic IP / wp-admin in the address bar of the browser.
Click on Run the install.
Create your WordPress site.
You can see in the image given below WordPress site execute perfectly on your browser.
Note: To map above elastic IP Address of Amazon EC2 with the domain name. You can follow this Tutorial.
There are 2 type of Apache extention exists.
1. Rewrite Module
This module enables custom permalink on WordPress.
To enable it use follownig commands –
sudo a2enmod rewrite
sudo service apache2 restart
2. Curl Module
This module enables curl based function. Some premium themes and plugins use this curl for verifying activation key.
To enable it use following commands –
sudo apt-get install php5-curl
sudo service apache2 restart
Hope this tutorial helps you to install WordPress on Amazon EC2 easily. If you find any difficulty in any of the above step, let me know. I will definitly resolve your issues.