In this tutorial, we’ll see how to access EC2 instance or vm from local computer using command line interface (CLI). If you are using windows, then I recommend you to install ssh in your command line. This video might be useful for you.
Access EC2 instance:
If you are using Linux or OS X, most likely you already have ssh. Open your terminal or CLI and run the following command:
1 |
ssh -v |
If you don’t see the version number, then install it.
In previous video, you’ve downloaded public key from Amazon Web Services. Keep it in a place (I prefer Desktop) where you can easily access for a now.
Open command line interface or terminal and go to the folder where you have saved the public key.
1 |
cd ~/Desktop/ |
Run the following command to protect your private key file:
1 |
chmod 400 MyKey.pem |
To access the vm or EC2, run the following command:
1 |
ssh -i MyKey.pem ec2-user@52.2.23.186 |
Here ec2-user is the username. It can vary depending on the AMI or system that you selected in previous tutorial. 52.2.23.186 is the “Public IP” that we got from our previous tutorial.
According to Amazon Web Services documentation:
For Amazon Linux, the user name is
ec2-user
. For RHEL5, the user name is eitherroot
orec2-user
. For Ubuntu, the user name isubuntu
. For Fedora, the user name is eitherfedora
orec2-user
. For SUSE Linux, the user name isroot
. Otherwise, ifec2-user
androot
don’t work, check with your AMI provider.
After running the above command, if there is no error on the screen, then you are logged into the vm (EC2) successfully.
Install Apache PHP MySQL on EC2 server:
After logging into the EC2 console successfully, run the following command to ensure that all software packages are upto date:
1 |
sudo yum update -y |
Above command will take some time to complete.
Now it’s time to install apache, php, mysql. Run
1 |
sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd |
Start apache server:
1 |
sudo service httpd start |
If you want to start apache server when the EC2 or vm server starts, run:
1 |
sudo chkconfig httpd on |
The above command doesn’t show you any status, but it works.
Allow HTTP to access your web server:
At this moment Amazon Web Services will not allow anybody to access our newly installed apache server that is HTTP server. To enable HTTP for all, we’ve to make some changes to our security group. Let’s do that now
Go back to your Amazon Web Services console (AWS) in your browser. Go to EC2 > Running instances.
If you scroll horizontally to the right of the table, you can see a “Security Groups” column at the end. Click on it ( red circle marked on the screenshot).
In the next screen, click Action > Edit inbound rules.
A popup box will appear. Click on Add Rule button and then select HTTP from type dropdown box. You don’t have to change any other value. Keep them as they are suggested. Click Save button.
Again Actions > Edit outbound rules and add new rule of HTTP the same way that you did for inbound rule.
Now, open your browser and type “Public IP”. You can see the following result, if everything goes okay.
Wow, now your server is accessible from anywhere in the world. In next tutorial, I’ll show you how to upload files using FileZilla.