Amazon EC2 Setup with Ubuntu and XAMPP Installation
Wall Script
Follow Me:
Tuesday, December 08, 2015

Amazon EC2 Setup with Ubuntu and XAMPP Installation

Very long time back I had published an article about Amazon Cloud installation, nowadays Amazon Web Services is offering 12 months free trial for micro instance with 700 MB RAM. Now they simplified few interface setting for installation process, this post will explain you how to setup an Amazon micro instance with Ubuntu operating system and XAMPP server. Try this for your first web project.

Display Browser Notifications from Web Application


Getting started with Amazon Web Services EC2(Elastic Compute Cloud)
Very first you have to create an account in Amazon.com with valid credit card and then activate micro free tie. Click here to access Amazon console dashboard.

Step 1
After Amazon console login you find the following screen, select EC2 from Compute category.
Launch Amazon EC2 instance

Step 2
Click Launch Instance button.
Launch instance

Step 3
Now choose operating system for your web server, I suggest use Ubuntu for more package advantages. Make sure, that should be listed in free tier.
Select Amazon Operating System

Step 4
You find the following screen, now click Launch button.
Amazon Ubuntu OS

Step 5
Here you can modify your server type, but initially explore things with free tier.
Select Amazon Free tier

Creating Amazon Key File - Authentication
Most important part in this installation process.

Step 6
Here choose Create a new pair key
Create key .pem file

Step 7
Give valid name and click to Download Key Pair. You will get an .pem file.
Download key pair .pem

Step 8
Instance has been created successfully.
instance created successfully


Firewall Security Settings

Step 9
You will find the instance status here.
Running Instance

Step 10
Select the instance box and scroll down the page, you will find inbound rules for firewall security
Instance Amazon Inbound rules

Step 11
Add HTTP rule for web server access.
Add HTTP Rule

Elastic IP - Create Static IP Address
Basically Amazon instance will provide you a dynamic public DNS name, this is not stable. So you need a static IP.

Step 12
Go to Network & Security category and select Elastic IPs, click Allocate New Address
Launch instance

Step 13
Amazon will provide you a random IP address.
Launch instance

Step 14
Now associate IP address with instance box.
Launch instance

Step 15
Choose instance box here.
Launch instance

Step 16
Click Associate address.
Launch instance

Step 17
Associated IP address with instance.
Launch instance


Linux & MAC connection
Executing following command with Linux or MAC terminal, you can directly access your box.
ssh -i keyname.pem ubuntu@IP_ADDRESS

Sometimes you will get following error.
Permissions 0640 for 'keyname.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "keyname.pem": bad permissions
Permission denied (publickey).

Give only READ permission for .pem file, then execute SSH command again.
sudo chmod 400 keyname.pem

Windows connection
You have to download Putty and PuttyGen softwares. Click this Amazon Windows Connectivity link, follow steps under Windows connect using Putty

ubuntu@ip-172-31-19-204:~$ sudo su
root@ip-172-31-19-204:/home/ubuntu#

This will update Ubuntu OS Packages
sudo apt-get update

Stop Default Apache
sudo /etc/inid.d/apache stop

XAMPP Installation Commands for Ubuntu

Download XAMPP for 64 bit
wget http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.8.3/xampp-linux-x64-1.8.3-5-installer.run

Make Execute Installation
sudo chmod +x xampp-linux-x64-1.8.3-5-installer.run

Run Installation
sudo ./xampp-linux-x64-1.8.3-5-installer.run

XAMPP instructions
Select the components you want to install; clear the components you do not want to install. Click Next when you are ready to continue.
XAMPP Core Files : Y (Cannot be edited)
XAMPP Developer Files [Y/n] : Y
Is the selection above correct? [Y/n]: Y

Installation Directory
XAMPP will be installed to /opt/lampp
Press [Enter] to continue:
Do you want to continue? [Y/n]:Y

Run XAMPP
sudo /opt/lampp/lampp start

XAMPP Access Forbidden
Open your browser and access http://IP-ADDRESS/ you will find this Access forbidden screen.
Launch instance

XAMPP Configurations
Edit XAMPP configurations.
vi /opt/lampp/etc/extra/httpd-xampp.conf

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

to

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
Allow from all
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>

Restart XAMPP
sudo /opt/lampp/lampp restart

Security Settings
sudo /opt/lampp/xampp security

XAMPP: Your XAMPP pages are NOT secured by a password.
XAMPP: Do you want to set a password? [yes]
XAMPP: Your XAMPP pages are NOT secured by a password.
XAMPP: Do you want to set a password? [yes] no
XAMPP: MySQL is accessable via network.
XAMPP: Normaly that's not recommended. Do you want me to turn it off? [yes] yes
XAMPP: Turned off.
XAMPP: Stopping MySQL...ok.
XAMPP: Starting MySQL...ok.
XAMPP: The MySQL/phpMyAdmin user pma has no password set!!!
XAMPP: Do you want to set a password? [yes] yes
XAMPP: Password:*******
XAMPP: Password (again):*******
XAMPP: Setting new MySQL pma password.
XAMPP: Setting phpMyAdmin's pma password to the new one.
XAMPP: MySQL has no root passwort set!!!
XAMPP: Do you want to set a password? [yes] yes
XAMPP: Write the password somewhere down to make sure you won't forget it!!!
XAMPP: Password:*******
XAMPP: Password (again):*******
XAMPP: Setting new MySQL root password.
XAMPP: Change phpMyAdmin's authentication method.
XAMPP: The FTP password for user 'daemon' is still set to 'xampp'.
XAMPP: Do you want to change the password? [yes] no
XAMPP: Done.

PhpMyAdmin
Access PhyMyAdmin at http://IP-Address/phpmyadmin/
Launch instance

Domain Settings
If you own a domain address, go to domain DNS(Domain name settings). Add host value @ points to IP-Address
Launch instance


You can also convert the key using putty for MAC or Linux
sudo port install putty
This will also install puttygen. To get puttygen to output a .PEM file:
puttygen keyname.ppk -O private-openssh -o keyname.pem

File Uploads
Download here and install into your PC. Click this Amazon FileZilla Connectivity link, follow steps under FileZilla - File Uploads


Copy your project folder from /home/ubuntu/ directory to XAMPP htdocs folder.
sudo cp  -R WebProjectFolder /opt/lampp/htdocs/


Domain Redirection using .htaccess
Create a .htaccess file and copy into /opt/lampp/htdocs/ directory.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteCond %{REQUEST_URI} !^/WebProjectFolder/
RewriteRule (.*) /WebProjectFolder/$1

Now access your domain http://YourDomain.com/
Was this article helpful?
Thanks! Your feedback helps us to improve 9lessons.info


15 comments:

  1. Thanks a lot for this great tutorial. It is very useful.

    ReplyDelete
  2. Though am not into it now but someday sometime will find it useful..Big thanks

    ReplyDelete
  3. Thank you sir for sharing this article. This is very good article. Actually sir you write very well. So please sir write more article like this for us.

    Thank you.
    Balram Paul.

    ReplyDelete
  4. Thanks. Will give it a try. Cheers!!!

    ReplyDelete
  5. Good tutorial, I am not upload .htaccess in opt/lampp/htdocs/.htaccess in ftp, error
    cannot create remote file 'opt/lampp/htdocs/.htaccess'. So that i can redirect to my domain. Please write us.

    ReplyDelete
  6. Actually the free tier program offers instance of 1GB RAM.. You might wanna correct it in the intro.

    ReplyDelete
  7. Your posts are always nice. The above post is worth reading. Thanks for sharing.

    ReplyDelete
  8. Hi , i did what you said , and now amazon is charging me 25 $ for linux running on demand , and my website is not public yet , is that normal ?!

    ReplyDelete
    Replies
    1. I am planning to use for demo only. Will they charge?

      Delete
  9. Thanks a lot. very help ful.
    is it possible to install cpanel for manage all files, database

    ReplyDelete
  10. by using this amazon EC2 my XAMPP local server will turn in to Live server right?

    ReplyDelete
  11. Thanks for great help. i ma facing issue, after this commoand "sudo ./xampp-linux-x64-1.8.3-5-installer.run" its not working. i was expecting to see XAMPP instructions but terminal gos idle for long. nothing happens further.

    Am i missing anything?

    ReplyDelete
  12. hi, I am unable to access phpmyadmin as it says Access forbidden. I have done everything in this article. please guide

    ReplyDelete
  13. An easier way to setup Amazon EC2 instance and host an application on is using a managed hosting platform, like Cloudways. If you are using this platform you won't have to use command line.

    ReplyDelete

Make in India