«

»

Oct 14

Apache configuration on linux

The Apache is a web server and runs in the background, waiting for request of clients connecting to the server. Apache either responds to those requests or leaves notes in log files. Its behavior is controlled through its configuration. Some Configuration Given below.

ServerRoot

Some server configuration files in apache (i.e. server’s configuration, error, and log files) are kept at the top of the directory tree. This location is the ServerRoot. and we can set a different value in Apache’s main config file. Its depending on the installation, The default can be something like /usr/local/apache2 or /etc/apache2. When you first install your server, the configuration and log files are placed in the ServerRoot. You can change its value to a new directory, but make sure to copy the configuration files to the new location. Also, make sure you do not to add a trailing slash to the path when you modify the value.

ErrorLog

When any error occures then its log into log file in apache. The location of the error log is determined by the value specified using the ErrorLog directive. This file is critical because you will refer to it in order to debug errors, solve server configuration problems, and optimize the server.

The error log file topically located at /usr/local/apache2/logs/error_log or /var/log/apache2/error.log but its depend on your installation.

For absolute path please consider following directive
ErrorLog logs/error_log

The actual error log location is $ServerRoot/logs/error_log.

DocumentRoot

The DocumentRoot directive sets the location of the server’s public files. htdocs, This is the default Apache web server document directory. Its contents is publicly available to clients connecting through the web.

If you hosting multiple website on same server then you need to set the DocumentRoot for each site. This can be done within the respective VirtualHost directive that corresponds to each site. your virtual hosts file might look something like the following:


DocumentRoot /usr/local/apache2/htdocs/website1
ServerName website1
.
.
.

DocumentRoot /usr/local/apache2/htdocs/website1
ServerName website1
.
.
.

File Inclusion

It is possible to separate server configuration and settings into multiple files. This approach is ideal in order to keep your config file light and clear, but it also forces you to look inside multiple files residing in different locations to completely understand how Apache is configured. In any case, below is the syntax for including external config files.

# Include ports listing:
Include /etc/apache2/ports.conf
# Include generic snippets of statements
Include /etc/apache2/conf.d/
# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

As you can see from the examples above, you can include a specific file by name, a directory , or multiple files by using wildcards.

Start, Stop, and Restart Apache

To stop the Apache server, type in the following command in the console:

/etc/init.d/apache2 stop

To start the Apache server, type in the following command:

/etc/init.d/apache2 start

To restart the Apache server, type in the following command:

/etc/init.d/apache2 restart

For execution of above command you need to login with a privileged user. If you don’t know that password or have not the permission for execution of above command the you need to ask your server admin. Preceding the above commands with sudo:

sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 restart

ServerName

ServerName directive is used to set the host name of the server. You can set this directive either in the server’s configuration or virtual hosts.

for example

ServerAdmin webmaster@localhost
DocumentRoot /var/www
ServerName websitename
.
.
.

Listen

You can find this file in the same location as your Apache configuration files (/etc/apache2/ports.conf).

For example set ip address 122.23.25.121 To set Apache to listen to ports 80 and 443. the respective default ports for HTTP and HTTPS, you need to enter the following directives in yourports.conf file:

Listen 122.23.25.121:80

Listen 122.23.25.121:443

Alternatively, if you want Apache to listen to ports 80 and 443 on all interfaces regardless of the IP address.

Listen 80

Listen 443

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>