Apache - Apache interview questions answers faqs, Apache Tips and handful Guide

Apache interview questions answers faqs


This document is an quick reference. It gives you most of the answers on your question related to apache.

How do you check for the httpd.conf consistency and any errors in it?
 # apachectl configtest 
 # apachectl graceful

What is the command to stop Apache?
kill the specific process that httpd is running under, or killall httpd. If you have apachectl installed, use apachectl stop.

What does apachectl graceful do?
It sends a SIGUSR1 for a restart, and starts the apache server if it is not running.

When I do ps -aux, why do I have one copy of httpd running as root and the rest as nobody?
You need to be a root to attach yourself to any Unix port below 1024, and we need 80. "nobody" is an user account which doesn't have root permissions.
To do network setups, the Apache HTTP server must start with root permissions. Specifically, it needs to bind itself to port 80 so that it can listen for requests and accept connections. Once it does this, Apache can give up its rights and run as nonroot(nobody) user, as specified in its configuration files. By default, this is the user nobody. So when your mysql didn't start, check this folder permission is properly assigned.

But I thought that running apache as a root is a security risk?
That one root process opens port 80, but never listens to it, so no user will actually enter the site with root rights. If you kill the root process, you will see the other child process disappear as well.

Why do I get the message "...no listening sockets available, shutting down"?
In Apache 2 you need to have a listen directive. Just put Listen 80 in httpd.conf.

How do you set up a virtual host in Apache?

<VirtualHost www.w3calculator.com>
    ServerAdmin admin@w3calculator.com
    DocumentRoot /home/apache/share/htdocs/hostw3calculator
    ServerName www.w3calculator.com
    ErrorLog /home/apache/logs/error/hostw3calculator/error_log
    TransferLog /home/apache/logs/access/hostw3calculator/access_log
</VirtualHost> 


What is ServerType directive?
It defines whether Apache should spawn itself as a child process (standalone) or keep everything in a single process (inetd). Keeping it inetd conserves resources. This is deprecated, however.

What is mod_vhost_alias?
It allows hosting multiple sites on the same server via simpler configurations.

What does htpasswd do?
It creates a new user in a specified group, and asks to specify a password for that user.

If you specify both deny from all and allow from all, what will be the default action of Apache?
In case of ambiguity deny always takes precedence over allow.

What is DSO stands for?
Dynamic Shared Object (DSO). DSO support means that modules may be loaded at runtime.
The ability to dynamically load modules is known as DSO support. DSO allows you to extend the features and capabilities of Apache by adding the specific module you need, when you need it, without recompiling the Web server binary.

Command to list apache modules?
 # httpd -l

Command to list php modules?
 # php -m

What is apache extension?
In Apache you can load and unload modules as per your need, which is called as Dynamic Shared Objects (DSOs). Apache includes a program called apxs (APache eXtenSion) that automates the process of building DSOs.

How to install apache DSO?
 # /usr/bin/apache/bin/apxs -cia modesec.c
 # apxs -i -a -n foo mod_foo.la 
where
 -c : Stands for compile
 -i : stans for install

To compile Apache to use most of the dynamic modules
 # ./configure -enable-module=most --enable-shared=max

Example:
Here we not not going to discuss about installation steps, we are going to see only the compiling or configuring the php modules statically and dynamically for apache.
Install php dynamic Module with apache
 # ./configure --prefix=/www --enable-module=so
After configuring, we enable the LoadModule and AddModule
 # LoadModule php5_module libexec/libphp5.so

 # AddModule mod_php5.c

Install php static Module Installation for Apache
 # gunzip -c apache_1.3.x.tar.gz | tar xf -
 # cd apache_1.3.x
 # ./configure
 # cd ..

 # gunzip -c php-5.x.y.tar.gz | tar xf -
 # cd php-5.x.y
 # ./configure --with-mysql --with-apache=../apache_1.3.x
 # make
 # make install

 # cd ../apache_1.3.x
 # ./configure --prefix=/www --activate-module=src/modules/php5/libphp5.a
Hope the above example would have given you a better idea.

How to ensure that apache is installe with DSO support?
To confirm that your apache is compiled with the Dynamic Shared Object run the below command.
 # httpd -l
OUTPUT:
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c
If mod_so.c appears in the list of modules, then your Apache server can use dynamic modules. Once the mod_so module is statically compiled, any other module can be added or dropped using the 'LoadModule' command in the 'httpd.conf' file.

How to load dynamic modules in apache?
TO load or use a dynamically shared module, that module must have a LoadModule line and an AddModule line in httpd.conf.

# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.

 #LoadModule mmap_static_module modules/mod_mmap_static.so
 LoadModule vhost_alias_module modules/mod_vhost_alias.so
 LoadModule env_module         modules/mod_env.so
 LoadModule config_log_module  modules/mod_log_config.so
 LoadModule access_module modules/mod_access.so
 LoadModule auth_module modules/mod_auth.so
 LoadModule auth_anon_module modules/mod_auth_anon.so
 LoadModule auth_dbm_module modules/mod_auth_dbm.so
 #LoadModule auth_digest_module modules/mod_auth_digest.so
 #LoadModule ldap_module modules/mod_ldap.so
 #LoadModule auth_ldap_module modules/mod_auth_ldap.so
 LoadModule include_module modules/mod_include.so

The modules can be enabled by uncommenting the line in configuration file. Commenting the line will disable the module. Here the first line is commented out, which means that the corresponding module (mmap_static_module) was compiled in but not loaded.

Next, you need to uncomment the corresponding line from the AddModule section in httpd.conf. To continue with our previous example, uncomment the mod_mime_magic line, which looks as below. Once you have loaded and unloaded apache modules restart the httpd or apache service.
 #AddModule mod_mime_magic.c

Apache Static and Dynamic Modules: A quick look.

Static binary is reportedly faster. If you want to squeeze the last bit of performance out of your server then choose static module.

A static binary cannot have a precompiled dynamic module to it.

To add a backdoor to a statically compiled server, the attacker has to recompile the whole server from scratch.

The static modules or the static version use more memory.

Static apache modules are compiled into the httpd or hhtpsd daemon programs, when apache is compiled.

Dynamic is very much easy to install and use.

Dynamic modules are loaded using AddModule and LoadModule.

To enable or get the support of DSO, Apache must be compiled statically with mod_so.

The topic on Apache - Apache interview questions answers faqs is posted by - Math

Hope you have enjoyed, Apache - Apache interview questions answers faqsThanks for your time

Tech Bluff