Share, , Google Plus, Pinterest,

Print

Posted in:

Install Apache Server on CentOS 6

Why Install Apache Server?

Apache HTTP Server is the most popular web server in the world and has been so since April 1996. It played a key role in the growth of the World Wide Web. It is estimated that Apache Server is serving 54.2% of all active websites and 53.3% of the top servers across all domains! This is why you should install Apache Server too… 🙂

Apache was developed on Linux but is running on a wide variety of operating systems including Unix, FreeBSD, Solaris, Novell NetWare, OS X, Microsoft Windows, OS/2, TPF, and eComStation. Apache is an open-source software and is released under the Apache License.

Apache is developed and maintained by an open community of developers of the Apache Software Foundation.

The latest version of Apache HTTP Server is available for download at HTTPD Apache.Org.

Install Apache Server
Install Apache Server

In this post you will learn how to Install Apache Server on CentOS6 and where to find Apache Configuration Files.

Let’s Install Apache Server on CentOS 6!

1. Install Apache Server and dependencies

[root@foo ~]# yum install httpd -y

2. Apache start on boot

[root@foo ~]# chkconfig httpd on

3. Start Apache Server

[root@foo ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for foo.geekpeek.net
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[  OK  ]

 

If you got the same error as me it means, that your DNS records are not set up properly. Quick fix is adding a line to /etc/hosts file of your server with IP address and FQDN and the error should not appear any more:

[root@foo ~]# echo "192.168.61.100 foo foo.geekpeek.net" >> /etc/hosts
[root@foo ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.61.100 foo foo.geekpeek.net
[root@foo ~]# service httpd restart
Stopping httpd:                                            [  OK  ] Starting httpd:                                            [  OK  ]

4. Test Apache Server

You can now test your Apache Server from the server you just installed Apache on by visiting http://localhost in web browser (if web browser is installed on this system!!) or from a different machine in the same network by visiting IP address or FQDN (if DNS records are set up correctly) in your web browser.

If you see this Apache Welcome Page, Apache Server is running correctly:

Apache Welcome Page
Apache Welcome Page

 

Apache Configuration Files Location

If you followed this “Install Apache Server on CentOS 6” guide, you installed Apache Server from RPM. When installing Apache Server from RPM, configuration files location is:

1. /etc/httpd/conf/

This is the location of the main httpd.conf configuration file. You can configure globally defined settings in this file:

  • Server Root – this is the location where Apache Server’s configuration files, error and log files are kept
  • Listen –Listen: Allows you to bind Apache to specific IP addresses and/orports.
  • Dynamic Shared Object (DSO) Support – This is where you “load” all sorts of modules you would like to use with Apache Server.
  • User/Group – This is the user and group under which Apache daemon is running.
  • ServerAdmin – This is the address, where problems with the server should be e-mailed.
  • DocumentRoot – This is the location from which Apache Server serves HTML, PHP,… code from. Default location is /var/www/html.
  • …and much more…

This configuration file is well documented so read through it and you should not have any problems with it.

2. /etc/httpd/conf.d/

This is the location of the Virtual Hosts configuration files. You use Virtual Host configurations when running more than one web site on a single machine. You create a new .conf file with the desired name (example: vhost1.conf) in this folder with the configuration specific for this web site. Basic configuration settings are:

  • DocumentRoot – This is the location from which Apache Server serves HTML, PHP,… code from for this specific web site.
  • ServerName – This is the FQDN name of the website/server (example: server1.geekpeek.net).
  • Other directives – ServerAlias, RewriteEngine, RewriteRule,SSLEngine,…

Virtual Host configuration, SSL configuration,… will be covered in the next few posts!