How To Install Apache On Amazon Ec2
How to Install Apache 2 on AWS EC2 Instance Ubuntu 20.04
Dear Reader, I promise y'all are doing great. In i of my previous tutorials, I explained how to install apache spider web server on Amazon Linux.
Today, I am here to help you lot install apache 2 on AWS EC2 instance ubuntu 20.04 . If you have gone through my previous tutorial, you might say that we installed httpd in that. Then why apache2 here?
Well, in case of Ubuntu/Debian, the binary to install apache web server is called apache2 instead of httpd. And then basically, it doesn't make any difference. All we are going to practise is installing apache spider web server on EC2 instance ubuntu.
I hope that makes sense 🙂
Steps to Install Apache 2 on AWS EC2 Case Ubuntu 20.04
- Launch an EC2 Instance(Ubuntu 20.04)
- Connect to your Ubuntu Example
- Install Apache 2 on the Example
- Configure Security group of instance to allow port eighty
- Verify the Installation by Accessing the Server
- Customize the web folio
- View Customized Web page
Allow'south get started …
Step i: Launch an EC2 Instance(Ubuntu twenty.04)
Earlier we install apache web server on the EC2 example, nosotros will demand an EC2 instance(ubuntu) up and running. You can refer my previous tutorial to launch an instance in AWS.
Link to tutorial:How to Launch EC2 Instance Step by Step in AWS
Important Annotation: Please note that, above tutorial uses Linux ii AMI. Notwithstanding, to create Ubuntu instance you need to select Ubuntu while choosing AMI for your instance. Rest of the process for creating case remains same.
While you are in Choose AMI screen, search for ubuntu keyword and select ubuntu server twenty.04(gratuitous tier eligible) as shown below. Here is how it looks while choosing AMI.

Step 2: Connect to your EC2 instance
Once your instance is upwardly and running, yous need to connect to your instance. I will be using EC2 instance connect feature for this. It allows you to SSH into instance from browser itself.
Lazy me 😛
Withal, if you want to usual SSH client, navigate to the directory where keypair file is there on your local system and then run command like beneath from your final.
ssh -i "DemoKeyPair.pem" ubuntu@case-public-ip
To SSH from browser using Instance connect, follow below steps.
- Select your instance and click connectas highlighted below

2.One time, yous click Connect, you will see a screen with default username for ubuntu example

Verify thatubuntu is showing in username field and clickConnect.
A new browser window will open and you will exist continued into your case like below.

Amazing !!!
Now, you are ready to run commands on your EC2 instance. Let's move to the installation role in side by side stride.
Stride three: Install Apache Web Server
Now, we need to run below set of commands one past one, to install apache web server on our case. Please annotation that we will usesudo(root privilege ) to run all these command. The reason is, whenever y'all try to install, remove or change whatever software, you must have root privilege to do such tasks.
sudo apt update sudo apt install apache2 -y apache2 -version sudo systemctl condition apache2
Explanation of commands
Update latest packet available on the system
It's a best practice to update all the packages to latest before installing anything new.
sudo apt update
Install Apache Web Server
In this step, we are installing apache ii on the EC2 instance. We are providing -y option here to run this control silently. If yous don't provide -y option, the CLI will ask you Y/n choice and you accept to choose Y to install it. We want it install anyway so we are using -y option.
sudo apt install apache2 -y
Verify Apache Installation
Permit's bank check if apache2 has been installed successfully. You lot tin can use beneath command-
apache2 -version

As you can come across in above screenshot, apache 2.4.41 has been installed successfully.
Check Apache Server Status
By default, Apache is configured to kickoff automatically when the server boots. Lets check the condition of server by using below command.
sudo systemctl status apache2
At this moment, your apache spider web server is already installed and started in your Ubuntu 20.04 instance. But, you can't access it right now. if you try to hit the public IP you will get fault likeThis site can't exist reached.
Why?
Considering, our EC2 case doesn't permit web traffic notwithstanding.
On the security group, simply SSH is allowed as of now.
Let'southward change that.
Pace 4: Alter Security Group of example to permit port lxxx and 443
Let'southward allow spider web traffic on port 80 and 443(Internet traffic for http and https).
Click on your instance id to encounter the case details. Whorl downwardly and click onSecurity Tab and you should run into security group.
Click on Security Group id link -> Click on Edit Inbound Rule

Utilize Add rule push to add more than dominion i by i.
Specify rules for HTTP and HTTPS Spider web traffic from anywhere like above.
Step 5: Verify the Installation by Accessing the Server
Nosotros have installed apache spider web server and it is running on our instance. We have allowed web traffic also in previous step.
Therefore, our instance allows web traffic now, it'southward time to grab the public IP or public dns of the instance.

Click onopen address and you should exist able to run across the default folio similar below.

Step half-dozen: Customize the web page
We accept seen the default apache page served by apache. Lets modify that.
We will create our ain index.html in theCertificate Root binder which is/var/www/html in our example.
DocumentRoot: Document Root is the directory from which apache looks for and serves web files on your asking. So we volition create an index.html in/var/www/html folder
You can utilise various command to create and put content into index.html inside binder. Y'all tin can cheque this tutorial
For case- one of the simplest option is to utilise:
sudoecho "Hello World from $(hostname -f)" > /var/www/html/index.html
But using '>' creates a trouble and the the higher up command ends upwards running equallyubuntu instead ofrootresulting in permission denied like below.
-bash: /var/www/html/index.html: Permission denied

Permit's switch our user to root hither by using sudo su. As you can run across in below screenshot, afterward using this command, root becomes the current user.

Although it is advisable to stick to sudo
when performing tasks that require root privileges. By doing and then, the electric current user is but granted privileged for the specified command. On the other manus, su
switches to the root user completely and every control runs as root which is not secured.
After switching the user effort that command over again but this time without sudo equally we already are running it every bit sudo
echo "Hello Globe from $(hostname -f)" > /var/www/html/index.html

Once you hit enter, the file content gets replaced by hullo globe things. Let'south verify that.
Step 7: View the customized web folio
This fourth dimension when you lot enterpublic ip or dns into the browser, you will see your customized page like beneath.

Congratulation !!!
You accept installed and customized apache web server on Ubuntu twenty.04.
Other important commands:
Here are few more commands that you might observe useful during your journey with apache web server.
1. Restarts Apache Web server
sudo systemctl restart apache2
two. Stop Apache Web Server
sudo systemctl end apache2
3. Start the Apache If it is Stopped
sudo systemctl commencement apache2
four. Prevent Apache from loading on system boot
By default, Apache is configured to start automatically when the server boots. If you lot don't need that, you can disable information technology by beneath command:
sudo systemctl disable apache2
five. To Re-enable Apache to Load on Boot
sudo systemctl enable apache2
vi. Strength Apache Web Server to refresh configuration files
sudo systemctl reload apache2
Conclusion:
In this mail, we learnt toInstall Apache 2 on AWS EC2 Instance Ubuntu twenty.04 . We launched an Ubuntu Ec2 Example, connected to it using browser based connect and we used a set of commands to install apache web server.
We also modified the security group of instance to allow web traffic using port 80 and 443. Finally we customized the apache default page with our own code and we reviewed the modified page.
Feel gratuitous to drop a comment in case y'all face whatsoever issue or just to share the feedback.
Enjoyed the content?
Subscribe to our newsletter beneath to get awesome AWS learning materials delivered straight to your inbox.
Don't forget to motivate me by-
- Adding a comment below on what you liked and what can be improved.
- Follow us on
- Share this post with your friends
Suggested Read:
- Launch EC2 Example in an Existing VPC using CloudFormation
- Attach an IAM Role to an EC2 Example using CloudFormation
- Deploy a Spring Boot application AWS EC2 Instance
Source: https://cloudkatha.com/how-to-install-apache-2-on-aws-ec2-instance-ubuntu-20-04/
Posted by: pierceweread.blogspot.com
0 Response to "How To Install Apache On Amazon Ec2"
Post a Comment