Showing posts with label Question Bank. Show all posts
Showing posts with label Question Bank. Show all posts

Saturday, 10 December 2016

Apache-Tomcat Interview Questions And Answers

Q. Difference between apache and apache-tomcat server ?
Apache:
  •     Apache mostly serves static content by itself, but there are many add-on modules (some of     which come with Apache itself) that let it modify the content and also serve dynamic content written in Perl, PHP, Python, Ruby, or other languages.
  •     Basically Apache is an HTTP Server, serving HTTP.

Apache-Tomcat:
  •     Tomcat is primarily a servlet/JSP container. Its written in Java. It can serve static content too, but its main purpose is to host servlets and JSPs.
  •     JSP files (which are similar to PHP, and older ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine.
  •     Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.
  •     Although it is possible to get Tomcat to run Perl scripts and the like, you wouldn't use Tomcat unless most of your content was Java.
  •     Tomcat is a Servlet and JSP Server serving Java technologies

Note:
    The two technologies can be used together through a connector module called mod_jk. This will allow you to use the Apache HTTP server to serve regular static webpages, and the Tomcat Servlet engine to execute servlets.
   
Q. Difference between web server and application server ?
    1. Application Server supports distributed transaction and EJB.
        While Web Server only supports Servlets and JSP.
    2. Application Server can contain web server in them. most of App server e.g. JBoss or WAS has
        Servlet and JSP container.
    3. Though its not limited to Application Server but they used to provide services like Connection
        pooling, Transaction management, messaging, clustering, load balancing and persistence. Now
        Apache tomcat also provides connection pooling.
    4. In terms of logical difference between web server and application server. web server is supposed
        to provide http protocol level service
        while application server provides support to web service and expose business level service
        e.g. EJB.
    5. Application server are more heavy than web server in terms of resource utilization.

Q. How to start and shutdown to tomcat server
   There are two .sh file in cd $CATALINA_HOME/bin  dir or in /usr/share/tomcat7/bin/
    ./startup.sh
    ./shutdown.sh

Q. After startup what is the url for default web-application?
      http://localhost:8080/

Q. What are the directories under the apache-tomcat installation dir ?
  •     conf - Server configuration files (including server.xml)
  •     logs - Log and output files
  •     shared - For classes and resources that must be shared across all web applications
  •     webapps - Automatically loaded web applications
  •     work - Temporary working directories for web applications
  •     temp - Directory used by the JVM for temporary files (java.io.tmpdir)

Q. How to change the default(8080) port number?
  •     Go to tomcat>conf folder.
  •     Edit server.xml. (/usr/share/tomcat/conf/server.xml)
  •     Search "Connector port"
  •     Replace "8080" by your port number.
  •     Restart tomcat server.
  •    
    For example, if you change the port to 1977, you would request the URL http://localhost:1977/
   
    Note: While changing the port number make sure that port is not already in use and port no should be greater than 1024, as ports less than or equal to 1024 require superuser access to bind to.
  
Q. How to know your Apache tomcat version ?
    root@ubuntu:~# /usr/share/tomcat7/bin/version.sh
    Using CATALINA_BASE:   /usr/share/tomcat7
    Using CATALINA_HOME:   /usr/share/tomcat7
    Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
    Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk-i386
    Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
    Server version: Apache Tomcat/7.0.26
    Server built:   Apr 1 2013 08:32:04
    Server number:  7.0.26.0
    OS Name:        Linux
    OS Version:     3.2.0-105-generic-pae
    Architecture:   i386
    JVM Version:    1.7.0_101-b00
    JVM Vendor:     Oracle Corporation

Q. what are the configuratiopn file in tomcat server?
    Tomacat XML Configuration Files:
  1.     server.xml(TOMCAT-HOME/conf/server.xml)
  2.     web.xml   (TOMCAT-HOME/conf/web.xml)    
  3.     tomcat-users.xml (TOMCAT-HOME/conf/tomcat-users.xml)
Q. How to use tomcat server as a HTTP server ?
    Tomcat also contains a HTTP connector which can be used to serve static HTML pages. The standard directory which will be served is below the Tomcat webapps/ROOT installation directory. Place static content into this directory.

    To allow directory browsing via Apache Tomcat change the listings parameter in the file conf/web.xml from false to true.
    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
   
Q. Explain what is Jasper?
    Jasper is a Tomcat’s JSP engine
    It parses JSP files to compile them into JAVA code as servlets
    At run-time, Jasper allows to automatically detect JSP file changes and recompile them
   
Q. Where can be set roles,username and password ?
   /conf/tomcat-users.xml
  
   <tomcat-users>
        <role rolename="manager-gui" />
        <user username="tomcat" password="s3cret" roles="manager-gui" />
   </tomcat-users>

Friday, 24 June 2016

Apache Server Interview Questions & Answers

Q. What is the Apache server ? 
  •  Apache Web Server is one of the most secure, powerful and popular open source HTTP Server which is written in portable C. It can be used to host anything from personal web sites to corporate domains.
  • It mostly serves static content by itself, but there are many add-on modules (some of which come with Apache itself) that let it modify the content and also serve dynamic content written in Perl, PHP, Python, Ruby, or other languages.       
Q. How to check the version of Apache server ?
    First, use the rpm command to check whether Apache installed or not. If it’s installed, then use
    httpd -v command to check its version.
    # rpm -qa | grep httpd

    httpd-devel-2.2.15-29.el6.centos.i686
    httpd-2.2.15-29.el6.centos.i686
    httpd-tools-2.2.15-29.el6.centos.i686

    # httpd -v

    Server version: Apache/2.2.15 (Unix)
    Server built:   Aug 13 2013 17:27:11

    In ubuntu linux try following command.
    mukesh@ubuntu:~$ apache2 -v
    Server version: Apache/2.2.22 (Ubuntu)
  
Q.  On which version of apache you have worked ?
    httpd-2.2.3

Q. What is location of log files in Apache server ?
    /var/log/httpd/access_log
    /var/log/httpd/error_log
  
    In Ubuntu:
    /var/log/apache2/other_vhosts_access.log
    /var/log/apache2/error.log
    /var/log/apache2/access.log
  
Q. Apache runs as which user? and location of main config file?
   Apache runs with the user "nobody" and httpd daemon. Apache main configuration file:
   /etc/httpd/conf/httpd.conf (CentOS/RHEL/Fedora)
   /etc/apache2.conf  or /etc/apache2/apache2.conf (Ubuntu/Debian)
 
Q. On which port Apache listens http and https both?
   By default Apache runs on http port 80 and https port 443 (for SSL certificate). You can also use
   netstat command to check ports.
    [root@mukesh ~]# netstat -antp | grep http

    tcp        0      0 :::80                       :::*                        LISTEN      1076/httpd        
    tcp        0      0 :::443                      :::*                        LISTEN      1076/httpd
  
Q. Where you can find all configuration directories of Apache Web Server?
   /etc/httpd/conf/ (CentOS/RHEL/Fedora)
   /etc/apache2/     (Ubuntu/Debian)
 
Q. You see a error "connection reset by peer" in error log. What could be the reason for this?
   If the end user terminates the connection when the server response was being formed or was being
   transferred, we see "connection reset by peer" in the error log.

Q. What is virtual hosting?
     Virtual hosting is a method for hosting multiple domain names on a server using a single IP
     address. Virtual hosting allows one server to share its resources, such as memory and processor
     cycles, in order to use its resources more efficiently.

   Sample VirtualHost:
    <VirtualHost *:80>
       ServerAdmin webmaster@dummy-host.example.com
       DocumentRoot /www/docs/dummy-host.example.com
       ServerName dummy-host.example.com
       ErrorLog logs/dummy-host.example.com-error_log
       CustomLog logs/dummy-host.example.com-access_log common
    </VirtualHost>

    Where :
    ServerAdmin  : Its usually the email address of the website owner, where the error or notification
                               can be sent.
    DocumentRoot : location where the web files are located in the server(Necessary).
    ServerName   : Its the domain name which you want to access from your web
                               browser(Necessary).
    ErrorLog     : Its the location of the log file where all the domain related logs are being recorded.


Q. What are the types of virtual hosts ?
    There are two types of virtual host name-based and IP-based.

    Name-based virtual host means that multiple names are running on each IP address.
    IP-based virtual host means that a different IP address exists for each website served. Most
    configurations are named-based because it only requires one IP address.
  
Q. If you have only one IP address, but you want to host two web sites on your server.
     What will you do?
     In this case I will use Name Based Virtual hosting.
  
    ServerName 10.111.203.25
    NameVirtualHost *:80
    <VirtualHost *:80>
        ServerName web1.test.com
        DocumentRoot /var/www/html/web1
    </VirtualHost>

    <VirtualHost *:80>
        ServerName web2.test2.com
        DocumentRoot /var/www/html/web2
    </VirtualHost>

  
Q. You need to install Apache web server on Ubuntu server. How can you download and install the
     Apache2 package?
     sudo apt-get install Apache2
         OR
     sudo aptitude install Apache2
     aptitude is known to sort out program dependencies in a better way.


Q. What are Iptables?
     Iptables are user space application programs that allow a system administrator to configure the
     tables provided by the Linux kernel firewall.

Q. Which privilege is required to operate iptables?
     Iptables require root user privilege for execution, otherwise they fail to function.

Q. What type of ports are 80 and 443?
     The port 80 is a regular port while port 443 is a secure port.

Q. How to restart Apache web server ?
    /etc/init.d/httpd  restart  (CentOS/RHEL/Fedora)
    service httpd restart        (CentOS/RHEL/Fedora)
  
    sudo /etc/init.d/apache2 restart (Ubuntu/Debian)

Q. What is the difference between a restart and a graceful restart of a web server?
    During a normal restart, the server is stopped and then started, causing some requests to be lost.
    A graceful restart allows Apache children to continue to serve their current requests until they can
    be replaced with children running the new configuration.
  
Q. What is DocumentRoot ?
     It is a location of web files which are accessible by clients. The default DocumentRoot of Apache
     is /var/www/html or /var/www. This can be changed to anything, by setting up "DocumentRoot"
     in a virtual host of configuration file of domain.
  
Q. How to change default Apache Port and How Listen Directive works in Apache?
    There is a directive "Listen" in httpd.conf file which allows us to change the default Apache port.
    With the help of Listen directive we can make Apache listen on different port as well as different
    interfaces.

   To change the Apache default port, please open your Apache main configuration file httpd.conf or
   apache2.conf or ports.conf(ubuntu/Debian) file with VI editor.
    [root@mukesh ~]# vi /etc/httpd/conf/httpd.conf
    [root@mukesh ~]# vi /etc/apache2/apache2.conf
    [root@mukesh ~]# vi /etc/apache2/ports.conf
  
    Search for the word "Listen", comment the original line and write your own directive below that
     line as following.
    # Listen 80
        OR
    Listen 8080
    Listen 172.16.16.1:8080
    Save the file and restart the web server.
    [root@mukesh ~]# service httpd restart
    [root@mukesh ~]# service apache2 restart
  
Q. Can we have two Apache Web servers on a single machine?
     Yes, we can run two different Apache servers at one time on a Linux machine, but the condition
     for that is they should listen on different ports and we can change the ports with Listen directive
     of  Apache.
 
Q. What is the difference between <Location> and <Directory>?
    <Location> is used to set element related to the URL / address bar of the web server.
    <Directory> refers that the location of file system object on the server

Q. If you have added "loglevel Debug" in httpd.conf file, than what will happen?
   It will give you more information in the error log in order to debug a problem.
   With the help of Loglevel Debug option, we can get/log more information in the error logs which
    helps us to debug a problem.
  
======================Some More Questions ==============================

Q. What type of IP is required for Apache Web Server to host our website?
    a DSL connection with a static IP then we can use the Apache web server to host our website.

Q. While installing Apache HTTP server, do we need SSL and PHP support?
   Yes, SSL and PHP support is required to install Apache HTTP server.

Q. Is there any size limit for URL rewriting and aliasing in Apache web server?
   Apache has no fixed limit on the numbers of Aliases and Redirects which may be declared in the
   config files.

Q. Create a new user file and add a user with username "test" and password "test".
    htpasswd -c /usr/local/etc/httpd/users test
    User will be prompted to provide the password. The -c argument tells htpasswd to create new file
    for users.
    To add more users, -c argument can be omitted.

Q. What do you mean by a valid ServerName directive?
    The DNS system is used to associate IP addresses with domain names. The value of ServerName is
     returned when the server generates a URL. If you are using a certain domain name, you must
     make sure that it is included in your DNS system and will be available to clients visiting your site.

Q. What is the use of mod_perl module?
    mod_perl scripting module to allow better Perl script performance and easy integration with the
    Web server.

Q. Can you record the MAC (hardware) address of clients that access your server.
    No

Q. Can you record all the cookies sent to your server by clients in Web Server logs?
    Yes, add following lines in httpd.conf file.
    CustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i" CustomLog
    logs/cookies2_in.log "%{UNIQUE_ID}e %{Cookie2}i"

Q. Can we do automatically roll over the Apache logs at specific times without having to shut down
     and restart the server?
    Yes
    Use CustomLog and the rotatelogs programs
    Add following line in httpd.conf file. CustomLog "| /path/to/rotatelogs/path/to/logs/access_log.%Y-%m-%d 86400" combined

Q. What we can do to find out how people are reaching your site?
     Add the following effector to your activity log format. %{Referer}

Q. Can I serve content out of a directory other than the DocumentRootdirectory?
    Yes, by using "Alias" we can do this.

Q. If you have to more than one URL map to the same directory but you don't have multiple Alias
     directives. What you will do?
    In this case I will use “AliasMatch” directives.
    The AliasMatch directive allows you to use regular expressions to match arbitrary patterns in
     URLs and map anything matching the pattern to the desired URL.

Q. I want to stop people using my site by Proxy server. Is it possible?
    <Directory proxy:http://www.test.com/myfiles>
        Order Allow,Deny
        Deny from all
        Satisfy All
    </Directory>

Q. What is mod_evasive module?
    mod_evasive is a third-party module that performs one simple task, and performs it very well. It detects when your site is receiving a Denial of Service (DoS) attack, and it prevents that attack from doing as much damage. mod_evasive detects when a single client is making multiple requests in a short period of time, and denies further requests from that client. The period for which the ban is in place can be very short, because it just gets renewed the next time a request is detected from that same host.

Q. How to enable PHP scripts on your server?
   If you have mod_php installed, use AddHandler to map .php and .phtml files to the PHP handler.
   AddHandler application/x-httpd-php .phtml .php

Q. Which tool you have used for Apache benchmarking?
    ab (Apache bench)
    ab -n 1000 -c 10 http://www.test.com/test.html

Q. Can we cache files which are viewed frequently?
    Yes we can do it by using mod_file_cache module.
    CacheFile /www/htdocs/index.html

Q. Can Apache be secured with TCP wrappers?
    No, It can’t be secured with the TCP wrappers since it doesn’t support libwrap.a library of Linux.

Q. Can we host files in different folder and what is Alias directive?
   Yes, this can be achieved by Alias directive in the main Apache configuration file. Alias directive
    maps resources in File system, it takes a URL path and substitute it with a file or directory path on
    the system with is set up to redirect.
   To use Alias directive, Its the part of mod_alias module of Apache. The default syntax of Alias
    directive is:

    Alias /images /var/data/images/
  
    Here in above example, /images url prefix to the /var/data/images prefix that mean clients will query for "http://www.test.com/images/sample-image.png" and Apache will pick up the "sample-image.png" file from /var/data/images/sample-image.png on the server. It’s also known as URL Mapping.

Q. What do you understand by "DirectoryIndex"?
   DirectoryIndex is the name of first file which Apache looks for when a request comes from a domain. For Example: www.test.com is requested by the client, so Apache will go the document root of that website and looks for the index file (first file to display). The default setting of DirectoryIndex is .html index.html index.php, if you have different names of your first file, you need to make the changes in httpd.conf or apache2.conf for DirectoryIndex value to display that to your client browser.


Q. How to disable Directory listing when an index file is missing?
   If, the main index file is missing in the website root directory, then the Apache will lists all the contents like files and folder of the website on the browser instead of Main website pages. To stop Apache directory listing, you can set the following rule in the main configuration file globally or in .htaccess file for a particular website.
    <Directory /var/www/html>
       Options -Indexes
    </Directory>

Q. What do you understand by MPM in Apache?
   MPM stands for Multi Processing Modules, actually Apache follows some mechanism to accept and complete web server requests.

Q. What is the difference between Worker and Prefork MPM?
   Both MPMs, Worker and prefork has their own mechanism to work with Apache. It totally depends on you that in which mode you want to start your Apache.
   Basic difference between Worker and MPM is in their process of spawning the child process. In the Prefork MPM, a master httpd process is started and this master process starts manages all other child processes to serve client requests. Whereas, In the worker MPM one httpd process is active, and it uses different threads to serve client requests.
   Prefork MPM uses multiple child processes with one thread each, where worker MPM uses multiple child processes with many threads each.Connection handling in the Prefork MPM, each process handles one connection at a time, whereas in the Worker mpm each thread handles one connection at a time.Memory footprints Prefork MPM Large memory footprints, where Worker has smaller memory footprints.

Q. What is the use of LimitRequestBody and how to put limit on your uploads?
   LimitRequestBody directive is used to put a limit on the upload size.
   For example: I want to put limits of 100000 Bytes in the folder /var/www/html/mks/uploads. So, you need to add following directive in Apache
    configuration file.
    <Directory "/var/www/html/mks/uploads">
        LimitRequestBody 100000
    </Directory>

Q. What is mod_perl and mod_php?
    mod_perl is an Apache module which is compiled with Apache for easy integration and to
    increase the performance of Perl scripts.
    mod_php is used for easy integration of PHP scripts by the web server, it embeds the PHP interpreter inside the Apache process. Its forces Apache child process to use more memory and works with Apache only but still very popular.

Q. What is the use of mod_ssl and how SSL works with Apache?
   Mod_ssl package is an Apache module, which allows Apache to establish its connection and transfer all the data in a secure encrypted environment. With the help of SSL certificates, all the Login details and other important secret details get transferred in an encrypted manner over the Internet, which prevents our data from Eavesdropping and IP spoofing.
Related Posts Plugin for WordPress, Blogger...