Apache has been the most popular web server on the Internet Apache HTTP Server httpd was launched in 1995 and it has been the most popular web server on the Internet since April 1996.Latest release from the 2.4.x stable branch represents the best available version of Apache HTTP Server. Up to this point, you only have an operating system on your instance. We need to install the Apache web server to server website content. So, on the instance details page, click on ‘Connect using SSH’ Then, enter the following on the command line interface: $ sudo apt-get update $ sudo apt-get install apache2. Apache is web server which is used to deploy web applications on production. You can setup Apache web server on you premises or let you setup in cloud platform such as Amazon EC2 instances. By defalt Django or any other web apps run on single thread which do not give better performance.
- Apache Web Server Windows
- Apache Web Server Linux Download
- Apache Web Server Download
- Aws Apache Server
This tutorial exploains, how to launch Apache Web Server on AWS.
In this tutorial , we will launch an EC2(Elastic Cloud Compute) instance on AWS and configure the Apache httpd on it. EC2 is nothing but a Raw Virtual Machine on AWS where you have to install your services.This is tutorial is beginner friendly and provides basic configuration of Apache and also provides Information about Virtual Host.
Read About : 21 Important AWS Services that you must know
&& What is DNS and How DNS works
Apache is a very well known open-source Web Server. It is not only popular but also very old Web Server. Like any other Web Servers, Apache also accepts requests from the clients, search for the requested queries and then send the response back to them. Launching EC2 Instance on AWS.
How to Launch Apache Web Server on AWS ?
Apache is a very well known open-source Web Server. It is not only popular but also very old Web Server. Like any other Web Servers, Apache also accepts requests from the clients, search for the requested queries and then send the response back to them.
Launching EC2 Instance on AWS
Login to your AWS Account. If you do not have an AWS account, you can create a free account on AWS and use it free for one year. Follow the link following link to create a free account on AWS.
Click on Services and navigate to EC2
Click on Launch Instance
Select Amazon Machine Image(AMI) to launch your Linux box. I would recommend choosing Amazon Linux 2 AMI.
Select an Instance Type. I am choosing t2.micro(Free tier eligible) here. You can use a Free tier Instance,750 hours free for each month for the first 12 months.
Read more about free tier usage on AWS official website.
In the Configure Instance Tab, select Network, Subnet and keep ” Auto-assign Public IP” enable to assign a Public IP. Keep other settings as it is.
Mkv video for mac os. In the add storage tab enter the size of the Volume.
Add Tag
Put “Name” as key and “Apache-Server” as value. Tag is basically a Name that appears in the Instance tab in EC2 Section.
Configure your Security Group
Security Group is basically a Firewall for your AWS Network. I am opening port 22 for everyone to access this Server. You can put your IP to allow it from your location only.
Review your settings to launch the Server.
Create a new key pair and download it. In the below screenshot, I created a key pair named apache-server. Make sure to download the key pair and save it to your drive because it is the only key for login into your server. If you lost this key you will not be able to log in to your server.
As soon as you click on the launch, your Server will be launched. Navigate to the Instance Tab in EC2 Section and search for your Server. Note down the Public IP so as to connect it from the Internet.
Apache Web Server Installation
Apache Web Server Windows
Now Connect Apache-Server from the key you downloaded using Public IP from your local Linux Machine.
$ sudo ssh -i server-key [email protected]
Switch to Root Account for Installation.
$ sudo su
Update your Linux Box
$ yum update -y
Install Apache-Server
$ yum install httpd -y
Start httpd service
$ service httpd start
check the httpd service status
$ service httpd status
Run chkconfig command to run the httpd service automatically after a system reboot
$ chkconfig httpd on
Now your Apache-Server is installed and ready.
To browse Apache Web Server from the Internet, open port 80 and 443 in the security group
Navigate to EC2—>Instances—> Search for your Web Server—-> Click on the Security group as shown in the square box in the below screenshot.
Configuring Apache Server
Let us understand the Apache Server step by step from basic to advanced configuration.
As soon as your installation is done and port is opened in the security group, without doing any configuration change just enter the public IP in the web browser of any computer. You will see the default page as shown below.
To access the server from your domain name, create A record for your web server in your DNS zone configuration.
I have created A record for my domain as follows:
devopsmyway.in ————–> IP Address of my Server.
Now I can browse the apache Server from my domain name devopsmyway.in. The same test page will come as I did not change any configuration yet.
Let’s do some basic changes to open your Web Server (Web Site) as per your configuration.
Create an index.html file in “/var/www/html” directory and write some content in this to serve in the web browser. I am using echo command here to create and write content in index.html.
$ echo “Hello , Welcome to Devopsmyway.in ” > /var/www/html/index.html
As soon as you create and write content in index.html file in Document Directory “/var/www/html” your website will start serving the content written in index.html.
Now we have done the basic configuration of Apache Web Server. Let us move ahead and learn some advanced settings.
Virtual Host
Virtual host comes into picture when you want to host multiple Websites on a Single Server. Virtual host are of two types:
- Name-based virtual host
- IP based virtual host
Name-based Virtual Host
Name-based Virtual Host is used to configure multiple websites on a Single Server having a single IP Address. To configure Name-based Virtual hosts we need to do configuration changes in Apache Configuration file.
Apache Configuration file : /etc/httpd/conf/httpd.conf
Let us configure two websites www.devopsmyway.in and www.devopsmyway.net on the same Server with same IP address. To do so , open /etc/http/conf/httpd.conf and add the following lines at the bottom of the file.
$ vi /etc/httpd/conf/httpd.conf
<VirtualHost 172.31.22.60:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.in
ServerName www.devopsmyway.in
ErrorLog logs/www.devopsmywa.in-error_log
CustomLog logs/www.devopsmyway.in-access_log common
</VirtualHost>
<VirtualHost 172.31.22.60:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.net
ServerName www.devopsmyway.net
ErrorLog logs/www.devopsmyway.net-error_log
CustomLog logs/www.devopsmyway.net-access_log common
</VirtualHost>
Now Create to Directories as follows:
$ mkdir -p /var/www/html/devopmyway.net
$ mkdir -p /var/www/html/devopmyway.in
Create index.html file in each folder and add some content in it.
$ echo “Hello , Welcome to Devopsmyway.in ” > /var/www/html/devopsmyway.in/index.html Messenger for vk mac.
$ echo “Hello , Welcome to Devopsmyway.net ” > /var/www/html/devopsmyway.net/index.html
Now check the configuration and restart the httpd service
$ httpd -t
$ service httpd restart
Note: If you donot have two websites in Public DNS , you can do host entry in /etc/hosts on the same server as follows for testing
Now you will able to browse both the URL.
IP based virtual host
IP bases virtual host is used to configure multiple websites on a Single Server with multiple IP Addresses. To configure IP-based Virtual hosts we need to do the following configuration changes in the Apache configuration file.
Let us configure two websites www.devopsmyway.in and www.devopsmyway.net on the same Server on two IP addresses. To do so , open /etc/http/conf/httpd.conf and add the following lines at the bottom of the file.
<VirtualHost 172.31.22.60:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.in
ServerName www.devopsmyway.in
ErrorLog logs/www.devopsmywa.in-error_log
CustomLog logs/www.devopsmyway.in-access_log common
</VirtualHost>
<VirtualHost 172.31.27.122:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.net
ServerName www.devopsmyway.net
ErrorLog logs/www.devopsmyway.net-error_log
CustomLog logs/www.devopsmyway.net-access_log common
</VirtualHost>
Again check your configuration, restart the httpd service and browse both the sites using the curl command.
I hope you enjoyed this tutorial and learned to launch Apache Web Server on AWS . If you think this is really helpful, please do share my website https://devopsmyway.com to others as well. I will continue for the tutorial for Apache in my next blog. Also, please give your valuable feedback in the comment box.
If you think we helped you or just want to support us, please consider these:-
Connect to us: Facebook | Twitter
Ansible is an open-source software provisioning, configuration management, and application-deployment tool. It is one of the most powerful enough to automate complex multi-tier IT application environments. To know more about Ansible you can go through this post >> What is Ansible and How it is so Powerful?
How to set Ansible?
I have already created a post where you can learn how to set up the ansible successfully and we also troubleshoot some of the problems. Incase if there any error occurred you can comment down below or can connect with me over the social media handle as well. To know the setup part you can go through this post >> How to setup Ansible in RHEL8?
Task Description
We are going to create one Ansible playbook that will set the following set up:
- Provision an EC2 instance on AWS.
- Fetch the public IP using the EC2 dynamic inventory concept.
- Configure webserver.
Prerequisite
Before going further to solve the task we need some additional setup. I already installed the Ansible on my RHEL8 system.
- We need one IAM role in AWS so that Ansible can log in and do the required set up.
- Boto and Boto3 library of python. To install the library we can use “pip install boto” and “pip install boto3“. This will install the boto library and that library will automatically source the AWS API credential for EC2 instances and IAM roles.
- To provide the AWS credential we have multiple ways and one of them is by providing through the below command
- Ansible dynamic inventory file. Now you need two files EC2.py script and the EC2.ini config file. The EC2.py is written using the Boto EC2 library and will query AWS for your running Amazon EC2 instances. The EC2.ini file is the config file for EC2.py and can be used to limit the scope of Ansible’s reach. You can specify the regions, instance tags, or roles that the EC2.py script will find.
In order to get the above files, you can follow below link
To download this through command you can use wget<url>. Now we have to make it executable and to do so we can use below command
As for the Linux user there, one more thing I have to change is in the ec2.py file where we have to make some changes in the header path of the python interpreter. Earlier it is #!usr/bin/python and we have to convert it as #!usr/bin/python3.
now we have to add the location of above both files in our configuration as above our inventory file.
Let’s come to our task. Before going to the task I would like to tell you that in this task i am going to use some technical terms of AWS and in case you don’t know you can go through my AWS posts.
Code
Provision an EC2 instance on AWS
To provision this I created a role and named that as task2
For creating the key pair for the task through the below code and also saved the key locally.
To create the security group
To create the EC2 instance
This will launch an instance over AWS and also set the inventory dynamically in our inventory file of Ansible. Our first and second step is done now we will set the webserver.
Configuring Webserver
To configure this I created another role name as web
To install the apache web server we need python3 so we install that first
Now to launch the apache webserver we will use
This will install the web server and copy the code from the url and start the httpd service.
Now to run both the roles I created one playbook aws.yml
Now after running this our whole set up will be ready and here is some result of that.
To get the whole code you can go through Github >> https://github.com/anubhavsinghgtm/aws-ansible-dynamic-inventory
In case of any query, you can comment down below or connect with me over.
VISIT OUR WEBSITE BRIGHTERBEES FOR MORE INTERESTING STUFFS ABOUT LEARNING.
Apache Web Server Linux Download
IF YOU WANT TO KNOW ABOUt DATA SCIENCE click here.
Apache Web Server Download
Thank you