Apache Tutorials For Beginners
Apache Tutorials For Beginners
What is Apache?
How to install Apache
Install Apache on Linux Platform
Install Apache from Source
What is Apache?
Apache is a remarkable piece of application software. It is the most widely used Web Server app
world with more than 50% share in the commercial web server market. Apache is the most wide
Server application in Unix-like operating systems but can be used on almost all platforms such a
X, OS/2, etc. The word, Apache, has been taken from the name of the Native American tribe
for its skills in warfare and strategy making.
It is a modular, process-based web server application that creates a new thread with each simul
connection. It supports a number of features; many of them are compiled as separate modules
core functionality, and can provide everything from server side programming language support
authentication mechanism. Virtual hosting is one such feature that allows a single Apache Web S
a number of different websites.
There are numerous ways of installing the package or application. There are enlisted below -
1. One of the features of this open source web application is that anyone can make installer
own environment. This has allowed various vendors like Debian, Red Hat, FreeBSD, Suse etc.
the file location and configuration of apache taking into account other installed applications a
2. Apart from installing it from a vendor based installer, there is always the option of building an
from the source code. Installing Apache from source file is a platform independent & works fo
http://www.guru99.com/apache.html 2/23
08/03/2017 Apache Tutorials for Beginners
The apache web server is a modular application where the administrator can choose the require
and install different modules as per his/her requirement.
All modules can be compiled as a Dynamic Shared Objects (DSO is an object file that could be s
multiple apps while they are executing) that exists separately from the main apache file. The DS
highly recommended, it makes the task of adding/removing/updating modules from the servers
very simple.
If you are using an rpm (RedHat Package Manager is a utility for installing application on Linux s
Linux distribution i.e. Red Hat, Fedora, CentOs, Suse, you can install this application by either ven
Package Manager or directly building the rpm file from the available source tarball.
You can install Apache via the default Package Manager available on all Red Hat based distributio
CentOs, Red Hat and Fedora.
The apache source tarball could be converted into an rpm file using the following command.
It is mandatory to have -devel package installed on your server for creating .rpm file from source
Once you convert the source file into an rpm installer, you could use the following command to
After the installation the server does not start automatically, in order to start the service, you ha
of the following command on Fedora, CentOs or Red Hat.
http://www.guru99.com/apache.html 3/23
08/03/2017 Apache Tutorials for Beginners
Installing apache from the source require the devel package to be installed on your server. .You
latest available version of Apache, you can download it here . Once you download the source fil
the /usr/local/src folder.
[root@amserversterdam ~] cd /usr/local/src
[root@amserversterdam ~] httpd-2.2.26
In order to see all configuration option available for Apache, you can use ./configure help optio
common configuration option is prefix={install directory name}.
[root@amserversterdam ~] make
The above example shows the compilation of Apache within the /usr/local/apache directory with
capability. The enable-so option, can load required modules to apache at run time via the DSO
rather than requiring a recompilation.
Once the installation completes, you can browse the web servers default page with your favorite
firewall is enabled on your server, you must have to make exception for port 80 on your OS firew
use the following command to open port 80.
You can see the default Apache2 Welcome screen by browsing your server IP address.
http://www.guru99.com/apache.html 4/23
08/03/2017 Apache Tutorials for Beginners
An Apache web server can host multiple websites on the SAME server. You do not need separate
machine and apache software for each website. This can achieved using the concept of Virtual H
Any domain that you want to host on your web server will have a separate entry in apache confi
http://www.guru99.com/apache.html 5/23
08/03/2017 Apache Tutorials for Beginners
Name based virtual hosting is used to host multiple virtual sites on a single IP address.
In order to configure name based virtual hosting, you have to set the IP address on which you ar
receive the Apache requests for all the desired websites. You can do this by NameVirutalHost di
the apache configuration i.e. httpd.conf/apache2.conf file.
NameVirtualHost *:80
<VirtualHost 192.168.0.108:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/example1.com
ServerName www.example1.com
</VirtualHost>
<VirtualHost 192.168.0.108:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/example2.com
ServerName www.example2.com
</VirtualHost>
You can add as many virtual hosts, as per your requirement. You can check your web configurati
[root@amsterdam ~]#httpd t
Syntax OK
If the configuration file has some wrong syntax, it will throw an error
Invalid command '*', perhaps misspelled or defined by a module not included in the server con
In order to setup IP based virtual hosting, you need more than one IP address configured on you
the number of vhost apache will depend onnumber of IP address configured on your server. If y
10 IP addresses, you can create 10 IP based virtual hosts.
http://www.guru99.com/apache.html 7/23
08/03/2017 Apache Tutorials for Beginners
In the above diagram two websites example1.com and example2.com were assigned different IP
using IP-based virtual hosting.
Listen 192.168.0.100:80
<VirtualHost 192.168.10.108:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/example1.com
ServerName www.example1.com
</VirtualHost>
<VirtualHost 192.168.10.109:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/example2.com
ServerName www.example2.com
</VirtualHost>
http://www.guru99.com/apache.html 8/23
08/03/2017 Apache Tutorials for Beginners
Running Php files on Apache needs mod_php enabled on your server. It allows Apache to interp
It has Php handlers that interpret the Php code in apache and send HTML to your web server.
If mod_php is enabled on your server, you will have a file named php.conf in /etc/httpd/conf.d/
can also check it with:
mod_php
CGI
FastCGI
suPHP
mod_phpis the oldest PHP handler, it makes PHP part of apache and does not call any external P
This module is installed by default in every Linux distribution repository, so enabling/disabling th
very easy.
http://www.guru99.com/apache.html 9/23
08/03/2017 Apache Tutorials for Beginners
If you are using FastCGI as your PHP handler, you can set multiple versions of PHP to be used b
accounts on your server.
Running ruby files on Apache needs mod_ruby to be enabled. Apache can also handle ruby files
FastCGI. It is possible to use multiple version of ruby with the help of mod_fcgid i.e. FastCGI.
You can also install apache passenger and configure Apache to use it for serving ruby pages.
(Phusion Passenger also known as passenger is a free web server module that is designed to i
Apache and Nginx )
cd /tmp
wget http://www.modruby.net/archive/mod_ruby-1.2.6.tar.gz
cd mod_ruby-1.2.6/
./configure.rb --with-apr-includes=/usr/include/apr-1
make
make install
We have to add the mod_ruby module to the Apache configuration i.e. /etc/httpd/conf.d/ruby.co
following line.
If you like to enable or disable these modules, you have to edit the apache configuration file and
uncomment these modules, if the web server is already compiled with these modules.
http://www.guru99.com/apache.html 10/23
08/03/2017 Apache Tutorials for Beginners
Securing your web server is very important, it means allowing others to see only the intended in
protecting your data and restricting access.
These are common things that enhance your Apache web servers security.
Apache displays its version and the name of the operating system in errors as shown in below sc
http://www.guru99.com/apache.html 11/23
08/03/2017 Apache Tutorials for Beginners
A hacker can use this information to launch an attack using the publicly available vulnerabilities
particular version of the server or OS.
server signature option available in the apache configuration file. By default, it is on, we need
vim /etc/httpd/conf/httpd.conf
ServerSignature Off
ServerTokens Prod
We have also set ServerTokens Prod that tells the web server to return only apache and suppre
major and minor version
After modifying the configuration file, you have to restart/reload your apache web server to mak
http://www.guru99.com/apache.html 12/23
08/03/2017 Apache Tutorials for Beginners
If your document root directory does not have an index file, by default your apache web server w
the content of the document root directory.
This feature could be turn off for a specific directory through options directive available in the
configuration file.
<Directory /var/www/html>
http://www.guru99.com/apache.html 13/23
08/03/2017 Apache Tutorials for Beginners
Options -Indexes
</Directory>
It is good practice to disable all unnecessary modules that are not in use. You can see list of ena
available in your apache configuration file -
[root@amsterdam ~]#httpd M
perl_module (shared)
php5_module (shared)
proxy_ajp_module (shared)
python_module (shared)
ssl_module (shared)
Many of the listed modules can be disabled likemod_imap, mod_include, mod_info, mod_userdir
mod_autoindex, as they are hardly used by any production web servers.
vi /etc/httpd/conf/httpd.conf
/etc/init.d/httpd restart
http://www.guru99.com/apache.html 14/23
08/03/2017 Apache Tutorials for Beginners
If you like to make sure that files that is outside the web root directory are not accessible, you ha
sure that the directory is restricted with Allow and Deny option in your web server configurat
<Directory/>
Options None
AllowOverride None
Order deny,allow
</Directory>
Once you restrict acess outside the web root directoy, you will not be able to access any file loca
other folder on your web server, you will get 404 return code.
If you like to protect your web server from Dos (i.e. Denial of Service) you must enable the modu
mod_evasive. It is a third party module that detects Dos attack and prevents the attack from doi
damage as it would do if left to run its course. It could be downloaded here.
http://www.guru99.com/apache.html 15/23
08/03/2017 Apache Tutorials for Beginners
This module works as a firewall for Apache and allows you to monitor traffic in real time. It also
web server from brute force attacks. The mod_security module could be installed with the defau
manager of your distribution.
Apache does not have any restriction on the total size of the http request that could lead to a Do
can limit the request size of an Apache directive LimitRequestBody with the directory tag. The v
set anything from 0 to 2 GB (i.e. 2147483647 bytes) as per your requirement.
<Directory "/var/www/html/uploads">
LimitRequestBody 512000
</Directory>
Apache logs provide detailed information that help to detect common issues with server.
TransferLog directive is available in the apache configuration file and it rotates virtual host log fil
parameters.
<VirtualHost www.example.com>
ServerAdmin [email protected]
DocumentRoot /usr/www/example/httpd/htdocs/
ServerName www.example.com
ErrorLog /usr/www/example/httpd/logs/error_log
TransferLog/usr/www/example/httpd/logs/accesslog
</VirtualHost>
You can enable them by editing the apache configuration file i.e. apache2.conf (Debian/ubuntu)
(rpm based systems) file
[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration:
live/ap/htdocs/test
Here,
199.187.122.91 - - [06/Mar/2014:04:22:58 +0100] "GET /robots.txt HTTP/1.1" 404 1228 "-" "Mozi
atible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
Custom Log creates separate log file for each Virtual Host on your server. It needs to be specifie
host section of the config file.
You can see below mentioned virtual host configuration, generated log will be custom for that vi
the format will be combined.
1. In order to have a running production web server, you need a dedicated node (Physical/Virtu
instance) running Linux/Unix, Windows, MacOS etc.
2. The Web Server must have a direct network connection and a staticIP address configured
3. It needs to have all the modules required for running web pages. If a web server processes P
needs to have PHP module enabled.
http://www.guru99.com/apache.html 18/23
08/03/2017 Apache Tutorials for Beginners
4. It also needs to have a good Antivirus application configured and running for securing the W
Malware or Virus attacks. You also need mechanism to update the configured antivirus/anti m
application on regular basis without any manual intervention in order to get maximum benefi
5. If you have hundreds of domains to be hosted on your web server, you must have to impleme
on file system quota for each domain, number of databases each domain can create, nu
email accounts per domain etc.
6. If your web server has been setup for shared hosting services, users on your web server n
restricted. A shared hosting user should have least user privilege so that he does not damag
files & break the entire server. Apache does not provide any such functionality and needs diff
party applications, customization of OS to achieve this.
7. If you are adding a new domain on your web server, it needs editing hundreds of configurati
enable all features for the added domain.
8. If one of the hosted domains requires different PHP setting than rest of the domains, imple
core Apache web server is very complex and needs customization of your web server in great
9. A production web server needs a firewall to block unwanted traffic that could cause high load
server. Implementing IPTABLE rules with command line is very complex. It needs expertise o
Linux/Unix environment to write effective firewall rules for blocking unwanted traffic. IPTABL
netfilter module; it is an OS level firewall that allows an administrator to create rules for incom
traffic on the server.
10. A production web server requires several different applications like Email, FTP for file upload
Name System for parked domains. Managing all these applications on a core Linux/Unix sys
expertise on the respective technologies.
So, one can say that managing a web server for multiple domains is very complex task and requi
hundreds of configuration file, customizing each application to fulfill the desired result. Trouble
miss configuration will be very difficult for beginners.
If you have to recompile your web server i.e. apache on normal Linux platform, you have to ma
select/search the module that is required. cPanel provides Easyapache functionality that is a scr
http://www.guru99.com/apache.html 20/23
08/03/2017 Apache Tutorials for Beginners
It not only provides you web services but also Mail, DNS, FTP and many more services that is req
web application.
A task that needs expertise on core Linux/Unix based hosting like installing SSLs, recompiling Ap
different PHP modules, updating Web Security, configuring effective IPTABLE rules, Adding ftp us
mail accounts for each domain, scanning your document root with antivirus and creating databa
complete with cPanel.
It provides a lot of scripts that fixes, install and troubleshoot common administrative tasks.
It provides a backup and restore functionality eliminating the need to manually copy files to bac
you are backing up your domain, cPanel will create a tar file that will contain document root fold
accounts and mails, ftp accounts, databases, DNS records and other applications.
It also provides a robust documentation, andhas a very big community of users where you could
get solution of your issues.
So, one can say that cPanel is a best application for managing your web server with required fea
provides you, easy to use interface for managing your domain and a mechanism to avoid compl
managing core Web Server.
There are many competing products to cPanel like Plesk, ISPConfig, Ajenti, Kloxo, Open Panel, Zp
http://www.guru99.com/apache.html 21/23
08/03/2017 Apache Tutorials for Beginners
SAP HANA Training What is SAP Risk Based Testing: PHP file() Function Mong
Tutorials for Instance & SID Approach, Matrix, for Be
Beginners Process &
Examples
Learn More
http://www.guru99.com/apache.html 22/23
08/03/2017 Apache Tutorials for Beginners
http://www.guru99.com/apache.html 23/23