An account with AWS is required which currently is free for the first six months. If a paid account is used the costs incurred for experimenting with the launch of a server is very low so long as any servers created are stopped when not being actively used. In fact it is a good strategy to launch several Ubuntu or other operating systems in order to become familiar with the process.
Having set up an account with AWS, you are encouraged to create an Identity Access Management (IAM) user with limited but suffienet priveleges for the task(s) you intend to carry out. Then you can log in as an IAM user instead of as a root user. This is particularly useful if more than one person is using the account. However, you can sign in as the root user which means you can skip IAM.
Navigate to EC2 and click Launch instance.
Give the instance a name.
Click on Ubuntu.
Click Create new key pair
Give the key pair a name.
Choose the type/
Choose the .pem file format (for use with OpenSSH).
Click Create key pair.
At the prompt, save the .pem file and keep a note of the location and name you gave the key pair. On a linux computer it is typical to save the .pem file to a directory called .ssh in your home directory. This is indicated as ~/.ssh.
Tick Allow HTTPS traffic from the internet.
Tick Allow HTTP traffic from the internet.
Click Advanced details and paste a bash script into the user data section. This can be omitted and the steps involved in installing and configuring Apache can be done interactively after the server has been launched. Intitially this interactive procedure may be a good idea in order to become familiar with the various steps. Using a Bash script will be quicker if more servers are to be launched in future. It will also be more reproducible and enable a record to be kept of exactly how the configuration was achieved.
Click Launch instance
If the Bash script was included when launching the server then Apache will now be installed and it’s default web page will be accessible. Navigate to Instances and copy the public IPv4 address and paste it into the address bar of a browser. If this leads to an error page click on the address and change the protocol from https to http and try again. You should see the Apache default web page which has some useful information about setting up and using Apache.
You can now access the command line of the instance remotely from your computer using SSH. This will require the .pem file saved during the server launch. If using a local Linux computer then the permissions of the file should be set to r——– which is achieved with the command:
chmod 400 ~/.ssh/ec2private.pem
Now run the following command on your local computer:
ssh -i "path/to/your-key-pair-file.pem" ubuntu@<Public DNS>
The name of your .pem file and the path to it from your current working directory should be known to you. The user ubuntu will have been set up automatically at launch. The Public DNS is obtainable from the AWS Instances page if the instance under consideration is selected.
Running this command will change the prompt to the ubuntu user on the server and any commands entered will now run on that server.
If a Bash script was not supplied as user data during the launch the commands to install and configure Apache can be issued. The Bash script can be used as a guide for doing this. The Bash script would be run as the root user. The ubuntu user will need to preface most of the commands with sudo which enables them to be run as if the user were root.