This post will guide to install a basic Apache web server in CentOS and RedHAT operating system. Apache web server project was started by Robert McCool on 1996 (history of Apache Web Server) and nowadays it’s the most widely used web server due to it’s scalability, integration with several security and modules, .htaccess parsing etc. Apache is responsible for than 50% of traffic in web industry. (Apache Traffic Usage)
- CentOS or RedHAT Operating system installed. (We’ve used CentOS 6.8 x64 bit system)
- Any test editor installed.
- Off-course a working Internet connection
Difficulty: Easy Time Required: 10 minutes
Apache is called as httpd (http daemon, daemon is a typical RedHAT term to indicate Services, read more)in RedHAT based system and is present in base repository of yum installer.
|yum -y install httpd|
Apache is installed in your CentOS or RedHAT system now.. 🙂
httpd main configuration file is located in “/etc/httpd/conf/httpd.conf”. Edit it with your text editor with root or sudo right. We’ll use “nano” as command line text editor for rest of the text as “root” and so “sudo” will be ignored. If you like to install nano use the following command or else proceed with default “vim” or whatever is suitable for you.
|yum -y install nano|
Now edit the configuration file as follows
Find the following and change as follows if it’s not already there (You can easily find something in nano by pressing ctrl+w followed by what you want to search in the text, for ex: ctrl+w then “Listen” for the first line of the following)
Most of this are already present in the default configuration file and you need not to change, but just be sure those are there.
- “Listen 80” indicate in which port apache will listen for http connection. General format is IP:port (eg: Listen 192.168.0.2:80). If IP part is skipped as here and by default “httpd” will listen to port 80 of all IP addresses present in your system. [Don’t get excited for secure https and don’t replace with 443 here, this is not for https, there is other way for https, but that itself need another post].
- “User apache” and “Group apache” indicate under which User and Group the web server will run [Remember each process need to have an user in Linux].
- “ServerRoot” indicates root directory of the server. If you don’t explicitly define a directory starting with “/” it will be defined as “/etc/httpd/directory-name”
- “DocumentRoot” indicates the default directory of your web content. Notice DocumentRoot is started with “/” and so not a part of “ServerRoot”
- A tricky part is “Include” which can include any file and directory in the configuration without writing that directly in configuration. This keeps the configuration file clean and other things separated. Here any file in “/etc/httpd/conf.d” with .conf extension is included. This will be used latter to include virtual hosts (don’t worry right now)
Yahhh..!! You are ready to host your own Single html based website in your server. Just copy and past it into “DocumentRoot” that is “/var/www/html”. Please name the home page of your website as “index.html”. Now start httpd with the following command
|service httpd start|
Type your “Public IP address” in browser URL field (eg: http://126.96.36.199 where 188.8.131.52 is your IP address) or use any domain name pointed to that IP address in browser URL field and you’ll find your first website. To point your domain say yourdomain.com and your IP is 184.108.40.206 you’ve to create a DNS “A” record for yourdomain.com with a value 220.127.116.11 (more about DNS records). If you don’t have an Public IP and testing it on own laptop please browse “localhost” or “127.0.0.1” (i.e. http://localhost or http://127.0.0.1) in local browser in your laptop.
This finishes installing a very simple web server in CentOS or RedHAT based system. Although most of the functions like https, hosting multiple website on same server and other advanced functions are not covered yet and will be covered in subsequent posts.
For any quarry please don’t hesitate to leave a comment or contact the author with “authorname”@”serverlog.net” without any quotes.