Guide To Host Website in AWS-EC2
Guide To Host Website in AWS-EC2
1. Creation z
of the AWS-EC2 environment
2. Setup of the AWS-EC2 LAMP Stack environment
3. Setup of the Filezilla/FTP envornment
1
Part-1 Creation of the AWS-EC2 Instance
2
Part-1 Logon to AWS as you normaly would
https://labs.vocareum.com/home/login.php
z
login to your AWS
account viia vocareum
3
Part-1 Select AWS console
4
Part-1 Select EC2
5
Part-1 Launc/create EC2 instance
When you select EC2 you will see the above screen. We are going
create our first instance. Select/click the Launch instance tab 6
Part-1 Select EC2 instance Type
First, Step 1 allows the user to select the image. Choose the option
titled Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type — ami-
6b8cef13. It should be covered under the free tier choices.
7
Part-1 Select EC2 instance Type
8
Part-1 Select EC2 instance Type
9
Part-1 Configure EC2 Security Group
10
Part-1 Configure EC2 Security Group
z
1. The SSH rule should be added by default, if not, select SSH from the
drop-down menu under Type, then under the source column, choose
“Anywhere”.
2. Next, choose add rule, then select HTTP from the Type drop-down
menu and again “Anywhere” under the source column. Check that your security group
3. After that, select Add Rule again, and this time chose HTTPS from the configuration looks similar to the
Type drop-down menu and again choose “Anywhere” as the Source. screenshot above before
4. Finally, add the last rule by choosing MYSQL/AURORA from the Type choosing “Review and Launch”.
drop-down menu and “Anywhere” under source.
11
Part-1 Configure EC2 Security Group
If you hit an error as shown above. It appears you You need to delete the entry and
were trying to save the entry with a blank source re-create with by choosing
field. MYSQL/AURORA from the Type
drop-down menu and “Anywhere”
You will still have to put in a valid source in the under source and set to 0.0.0.0/0
source field. If you want it to apply to the "world" just
insert 0.0.0.0/0. Then choose Review and Launch at
The bottom of the screen. 12
Part-1 Preview EC2 Instance Details
13
Part-1 Launch EC2 Instance
Choose “Create a new key pair”. Under “Key Pair Name” type in a
name of your choosing, then click the “Download Key Pair” button.
You will be then prompted to save this key. Make sure to save this
somewhere safe, but also somewhere you will remember.
Amazon does not allow users to log into machines via a username and
passwords, instead you will use keys.
15
Part-1 Preview EC2 Instance Details
At the moment their should only be one instance present. It make take
a few minutes for your machine to instantiate, when its ready to go, it will
display a green dot beside the word running under the “Instance State”
column.
16
Part-1 Start/Stop EC2 Instances
z
PS: you stop instance once your website has been marked and completed.
Once you no longer want the EC2 instances to be active you can stop the instance - this suspends
the running of the instance and will save your credit points from being depleted.
To start the EC2 instance just choose from the Action tab Start and it will start the instance.
If you choose Terminate – the system will delete the whole EC2 instance and if you want to use
again you will have re-create the whole thing.
17
Part-2 we will now try and connect to the EC2 instance just created via SSH connection using
the .pem key we created earlier. Don’t loose the key otherwise you will not able to connect to EC2
Now that you have launched your EC2 instance, you can connect to it and use it the way that you'd use a
computer sitting in front of you.
There are 3 ways to connect to the EC2 instance. The next slides will describe the first two ways of
zto a Linux/EC2 instance:
connecting
The reason you need to connect to the EC2 instance is to setup the environment for hosting a website.
We need to install Apache, MySql, PHP etc (LAMP stack) so that it will support the application that will
be hosted by EC2. Take note you only need to these steps once for every new instance you create
18
Before we proceed we zneed
to get some information that
we will be using later to
connect. Just take note where
this information can be
obtained so that you now
where to find it. Take note of the URL address
19
z
Part-2 From this slide onwards the steps are meant for
windows laptops. If you have a Mac laptop please go to
slide no-35
20
Part-2 Establishing Connection to EC2 via PuTTY - Windows
21
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
22
PuTTY does not natively support the private key (.pem) format for SSH keys. PuTTY provides a tool named PuTTYgen, which converts
keys to the required format for PuTTY.
You must convert your private key (.pem file) into this format (.ppk file) as follows in order to connect to your instance using PuTTY.
We will create a .ppk fiile WITHOUT any passphrase for simplicity in this exercise.
4 Next select Load and a pop explorer will appear for you to locate
the .pem (key) you saved when it was generated during the creation
of EC2 istance.
Note: when browsing for your .pem file be sure to select All Files in
the dropdown list that is located to the right of the File name field.
PuTTYgen will then load and convert your file.
23
Once you load the .pem file a pop up window will appear, asking you to
save the private key.
Click ok and click save private key button. Save the .ppk file in the
same folder where you kept the .pem file.
5
z 6
24
Once you load the .pem file a pop up window will appear, asking you
to save the private key
z
You will now be asked where you want to save the .ppk file.
Save in the same folder as where you stored your .pem key file.
25
z
Next we launch PuTTY and provide the necessary
input to connect to AWS EC2 instance you just
created.
8 9
Insert the host name which is your AWS EC2
url which you can get from the EC2 dashboard
and select Connect tab
10
26
z
11
12
14
To ensure that all of your software packages are up to date,
perform a quick software update on your instance.
15
Now that your instance is current, you can install the Apache web server,
MySQL, and PHP software packages. Issue the following command
If you want the latest of version of Php7.2 issue the following command
29
z
16
Next we start the Apache web service. Issue the following
command
Add your user (in this case, ec2-user) to the apache group, to give
17 the apache group ownership of the /var/www directory and assign write
permissions to the group. Issue the following command
Log out and then log back in again to pick up the new group, and then verify
your membership.
Log out of PuTTY (use the exit command or close the terminal window): issue
exit
18
31
19
You establish connection again via PuTTY and repeat slides 26 and 27
z Then when you the login prompt type ec2-user again and enter
20
32
z
To add group write permissions and to set the group ID on future
subdirectories, change the directory permissions of /var/www and its
subdirectories.
23
Issue: sudo su
26
33
Now, the ec2-user user (and any future members of the apache group) can add, delete, and edit files in the
Apache document root. Now you are ready to add content, such as a static website or a PHP application.
z
Test your LAMP server
Create a PHP file in the Apache document root (/var/www/hmtl)
Then : cd html
Followed by ls –li and you will see phpinfo.php created for you
27
Once you have seen the above page being displayed you can now
28
29 delete the phpinfo.php file.
Issue: rm /var/www/html/phpinfo.php
http://ec2-18-212-57-160.compute-1.amazonaws.com/phpinfo.php
Part-2 From this slide onwards the steps are meant for
Mac laptops. If you have a windows laptop go to slide 20
35
Part-2 Establishing Connection to EC2 via SSH - Mac
36
z
In the Mac launch your terminal icon to get into
terminal mode and you will see screen on your right
1
Issue ls command and you will see files
of the current folder you are in
Take note the key file should only have .pem extension and
not .pem.txt – if this is the case rename and remove .txt
2 3
Next cd to the directory where your key was stored earlier. In my
case it was on the desktop and my key is MyAWS-ECS2-Key2.perm
5
Then chmod 400 MyAWS-ECS2-Key2.pem on the key – change the
Type”yes” here and enter
permission of the key. Your key filename wll be different. 4
Next we will connect to EC2 via ssh command (your ip address will be different)
ssh -i "MyAWS-ECS2-Key2.pem" ec2-18-212-57-160.compute-1.amazonaws.com
37
z
To ensure that all of your software packages are up to date, perform a quick
software update on your instance.
This process may take a few minutes, but it is important to make sure that you have
the latest security updates and bug fixes. – sudo yum update -y
38
z
Next we start the Apache web service. Issue the following command
If you want the latest of version of Php7.2 issue the following command
39
z
11
10
We install httpd again by issuing the command below. If you did not Once installed we need to start http service by the following command
encounter error at step 9 then you can skip steps 10 and 11
sudo service httpd start
sudo yum install httpd or
sudo yum install httpd24
40
Apache httpd serves files that are kept in a directory called the Apache Log out and then log back in again to pick up the new group, and then verify
document root. The Amazon Linux Apache document root is /var/www/html, your membership.
which by default is owned by zroot. This is where you must store all your webfiles Log out (use the exit command or close the terminal window): issue
later. exit
You can see the owner of html as root when you issue the following commands:
15
pwd followed by
ls –li /var/www 12
13
Then log in again to pick up the new group. To logon in again issue this command
16
To allow the ec2-user account to manipulate files in this directory, you must
modify the ownership and permissions of the directory. There are many
ways to accomplish this task.
Add your user (in this case, ec2-user) to the apache group, to give
the apache group ownership of the /var/www directory and assign write
permissions to the group. Issue the following command
41
Change the group ownership of /var/www and its contents to
the apache group. To add group write permissions and to set the group ID on future
subdirectories, change the directory permissions of /var/www and its
z
sudo chown -R ec2-user:apache /var/www subdirectories.
Then issue ls -li
Issue: sudo chmod 2775 /var/www 21
Then: ls –li
23
19
20
Issue: sudo su
Configure the web Apache/server to start with each
system boot/startup
Then : cd /var/www/html 24
Followed by ls –li and you will see phpinfo.php created for you 26
25
Once you have seen the above page being displayed you can now
delete the phpinfo.php file. 27
Issue: rm /var/www/html/phpinfo.php
In a web browser, type the URL of the file that you just created. This You are ready to go to Part-3 – where you will upload your
URL is the public DNS address of your instance followed by a forward webfiles to EC2. ---horray! job well done if you got this far.
slash and the file name. For example: Only the last bit left to setup Part-3
http://ec2-18-212-57-160.compute-1.amazonaws.com/phpinfo.php You do not need to do Part-1 and Part-2 ever again. You
only need to focus how to do Part-3
Part-3 From this slide onwards the steps are meant for
windows and Mac laptops.
44
Part-3 Uploading files/folder via Filezilla to EC2
45
Part-3 Download and Install FileZilla
z 1 Go to https://filezilla-project.org and
download the FileZilla Client for your laptop
Select this as we want client FTP and the it will detect automatically
2 whether you are downloading to Windows or for Mac
46
Part-3 Launch FileZilla
z
We will now setup the connection profile to EC2 via SSH so that we
need not type this each time when we want to connect to EC2.
4
You will see screen as shown. Then
select File and choose Site Manager.
47
Part-3 Create New Site Profile
z
z
For
Forthe
theHost
Hostpaste
pastethe
theEC2
EC2URL
URLaddress
addresswhich
whichlooks
lookslike
likesomething
somethingllike
llike
ec2-18-212-57-160.compute-1.amazonaws.com
ec2-18-212-57-160.compute-1.amazonaws.comyours
yourswill
willbe
bedifferent.
different.
99
88 For
Forthe
theProtocol:
Protocol:Select
SelectSFTP
SFTP
here
herefrom
fromdrop
dropdown
down
For
ForLogon
LogonType:
Type:Select
SelectKey
Keyfile
file
10
10 here
herefrom
fromdrop
dropdown
down
Type
TypeAWS-EC2
AWS-EC2here
here
For
ForUser:
User:Type
Typedefault
defaultusername
username
77 11
11 for
forEC2
EC2which
whichisisec2-user
ec2-user
12
12
For
ForKey
KeyFile:
File:Select
SelectBrowse
Browseand
andlocate
locate
On
Onyour
yourSite
SiteManager
Managerpanel
panelwe
wewill
willcreate
createaaprofile
profilefile
file where
whereyou
youstored
storedyou
youkey
keypair
pair(.pem
(.pemfile)
file)
and
andcall
callititAWS-EC2.
AWS-EC2.I Ihave
haveseveral
severalprofiles
profilesyou
youwill
willhave
have when
whenyou
youcreated
createdyour
yourEC2
EC2instance
instanceearlier
earlier
just
justone
one(first
(firsttime).
time).Select
SelectNew
NewSite
Site 13
13
66 Type
Typeaadescription
descriptionififyou
youwish
wishhere
here--optional
optional
14
14
Select
SelectOK
OK to
tosave
savethe
theprofile
profile 48
Part-3 Connect to EC2
z
17
Then select/highlight
AWS-EC2
15 16
49
Part-3 Connect to EC2
z
✓
19 For this pop-up select the box
to always trust this host and add 20
this key to cache
Select OK
50
Part-3 View folders after connection
z
This panel will show you the status and progress of every file
upload you do from your desktop to AWS-EC2
51
Part-3 Set Target Folder to Receive Files/Folders
z
21
52
Part-3 Locate your Webfiles Loacally
z
Next you must locate where you kept all your website
files in your local laptop/system.
53
Part-3 Check Local and Remote setup Before upload
z
Before you do this next step to upload PLEASE CHECK that
your Remote Site is pointing to /var/www/html – otherwise it
will upload to wrong place and overwrite other files and
folders!!!!!
24
25
Once you have confirmed the remote site is okay then right
click and select Upload to start the transfer.
54
Part-3 Commence Upload
z
The system will start to transfer all the selected files from your
local laptop to AWS-EC2 and you can see the status of the
transfer at this bottom panel
55
Part-3 Test Website from Browser
Once the transfer is complete and successful. You next go to your browser and
z paste your AWS-EC2 URL and hit enter.
open a new tab and
Your URL can be copied from AWS-EC2 Mangement panel in case you don’t
know and it should look like this (yours will be different)
ec2-19-299-57-160.compute-1.amazonaws.com
26
You will now see your website hosted on AWS-EC2
Job well done and complete!! Phew ! that was a long one…..
56
Part-3 Disconnecting Link to EC2
z
27
Once you have finish you can disconnect from AWS-EC2 by
selecting the Server tab followed by Disconnect
57
z
if YOU
WANT 58
Misc
z Your public DNS/AWS URL will look something similar to this line:
ec2-54-175-246-149.compute-1.amazonaws.com
60
Output of Some Commands
z
61
Output ofI Some
How can Commands
check all the software installed? (nginx, apache,
Then you
php,
have
etc).
to check the following versions and stuffs.
z 1.PHP version installed on the server
2.Mysql version installed on the server
3.PHP modules installed on the server
4.Apache modules installed on the server
62
Output ofI Some
How can Commands
check all the software installed? (nginx, apache,
Then you
php,
have
etc).
to check the following versions and stuffs.
z 1.PHP version installed on the server
2.Mysql version installed on the server
3.PHP modules installed on the server
4.Apache modules installed on the server
63
Output ofI Some
How can Commands
check all the software installed? (nginx, apache,
Then you
php,
have
etc).
to check the following versions and stuffs.
z 1.PHP version installed on the server
2.Mysql version installed on the server
3.PHP modules installed on the server
4.Apache modules installed on the server
64