Apache Webserver!
What is a Web server?
Web server is a machine that server requests for web contents like web pages or web services. That is, Web server gives the response when it gets a request for a particular web page. Website builders host their web pages on a dedicated machine, which is queried when you ask for any web page.
So Google, Facebook, Microsoft have their web servers, and when we enter:
‘www.google.com’ or ‘www.facebook.com,’
a request goes to their web server, that this IP needs this page. So, in short, a web server gives you response when you ask for a web page.
In this post, we will learn how to build and configure Apache Web server on any Redhat based Operating System (RedHat, Fedora, CentOS). For Debian based OS, steps are different.
It is a very simple 8 step process; you can also try it on your own 🙂
yum install httpd -y
This command will use Yum to install https in your systemcp /etc/http/conf/httpd.conf /etc/http/conf/httpd.conf.bak
Always create a backup of the original file.
Just for when if you make some mistakes, you have one file to revert too!
Besides, it’s just one command. (Screenshot in next point)
vim /etc/http/conf/httpd.conf
Open the Configuration file.
- Now here, inside the conf file, you need to make some changes.
Search for ServerName using ‘/’ ,
type ‘/ServerName‘ without quotes.
And once found, enter ‘i’ to get into ‘insert mode’ to edit. Then edit it with the name of your website you’re creating. - Go to the end of Configuration file. Here you will find Virtual hosts section.
Edit it.
In ServerAdmin put the email id of Admin
In DocumentRoot enter the path where you want to keep your website’s data (HTML pages, CSS, images, PHP)
In ServerName, enter the name of the website.
These three are compulsory, rest all are optional.
Note: this is just a simple web server configuration. mkdir /var/www/html/test
touch /var/www/html/test/index.html
vim /var/www/html/test/index.html
Now in the above Image, you can see we have our document root as /var/www/HTML/test, but we don’t have a dir named test inside HTML. So we will first
Create a dir using ‘media.’
Create an index.html file using ‘touch’ command, and then edit the ‘index.html.’
Note: if you put any website’s name, web server automatically searches for the index.html file and displays that.
So we’re creating an index.html file. You are free to create any file, just put the full path before viewing it.
Eg. you created abc.html, then insert ‘www.test.com/abc.html.’vim /etc/hosts
After creating an index file, its time to change the host’s file.
When you’re viewing a new website for the first time, the browser checks it cache, and if since it is a new site, it will get a miss, so it checks the hosts file in /, etc.
- [IP]Â ‘site name.’
Here inside hosts file, enter your IP address (use config command to find your IP) and then insert your website’s name.
So the Browser will check this file, go to this IP, i.e., the same machine, find the document root and display files.
/etc/init.d/httpd restart
Restart the service
- Check your site.
- Check if its opening in some other machine of the same network.