Sunday, 20 April 2014

Apache Server Interview Questions And Answers for linux admin


Q: - What is location of log files for Apache server ?
/var/log/httpd
Q: - What are the types of virtual hosts ?

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: - How to restart Apache web server ?

service httpd restart
Q: - How to check the version of Apache server ?

rpm -qa |grep httpd
Q: - What is meaning of "Listen" in httpd.conf file ?

Port number on which to listen for nonsecure (http) transfers.
Q: - What is DocumentRoot ?

it is a location of files which are accessible by clients. By default, the Apache HTTP server in RedHat Enterprise Linux is configured to serve files from the /var/www/html/ directory.
Q: - On which port Apache server works ?

http - port 80
https - port 443
Q: - Tell me name of main configuration file of Apache server ?

httpd.conf
Q: - On which version of apache you have worked ?

httpd-2.2.3
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 main difference between <Location> and <Directory> sections?

Directory sections refer to file system objects; Location sections refer to elements in the address bar of the Web page
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 the use of mod_perl module?

mod_perl scripting module to allow better Perl script performance and easy integration with the Web 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.
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: - 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: - 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: - How you will put a limit on uploads on your web server?

This can be achieved by LimitRequestBody directive.
<Directory "/var/www/html/data_uploads">
LimitRequestBody 100000
</Directory>
Here I have put limit of 100000 Bytes
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 t 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)
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 we have two apache servers having diff versions?
Yes, you can have two different apache servers on one server, but they can't listen to the same port at the same time.Normally apache listens to port 80 which is the default HTTP port. The second apache version should listen to another port with the Listen option in httpd.conf, for example to port 81.

For testing a new apache version before moving your sites from one version to another, this might be a good option.You just type www.example.com:81 in the browser window and you will be connected to the second apache instance


This month Oct-2011, I had experience of 5 years and 7 months in LAMP(Linux Apache MySQl PHP), during my magnificent professional journey, I had given many interviews and faced many common questions, and I my self is also interviewer from last 2 years.
I made this collection to the help my brothers who are looking good career in LAMP.
Before we come direct on questions and answers, we should prepare some basic things.
LinuxLinux is rarely asked subject by the interviewer, but still some one can ask about basic linux  commands and SVN commands like
  • How you manage the versioning of the files?
  • What is SVN?
  • How checkout / checkin the files?
  • How you add the new file to the SVN?
  • How you clean up the code directory from SVN before uploading to live or staging server?
  • chmod, chown, ls, vi, touch, grep etc?
Apache
  • What is Apache?
  • Which Apache version you are using? (very stupid question, but we were never cared to know about)
  • What is Virtual host and  how we set it?
  • What is htaccess and what we do with it?
  • what is htpasswd and what it do?
  • What are 404, 500 errors?
  • What are default session time and path?
  • What is URL rewriting?
  • How we can project folder with .htaccess?
PHP
General Questions.
  • What is difference between include(),  require() and require_once()?
  • What is difference mysql_connect() and mysql_pconnect()?
  • What is difference between echo and print?
  • What is difference between if and switch statement?
  • What is difference between $message and $$message?
  • What is difference between split and explode?
  • What is difference between passing by reference and passing by value?
  • What is difference between defining sting as “some string value” and ‘some string value’?
  • What is difference between Fatal Error, Warning and Notice?
  • What is difference between session and cookie?
  • How we can submit a form with “submit button”?
  • What are web services?
  • Difference between $_POST and $_GET
  • What is session and how it works?
  • What Is a Persistent Cookie?
  • What are constants and how to check constant is defined?
  • What is meant by urlencode and urldecode?
  • How we can find a string with in a sting?
  • What is the difference between strstsr() and stristr() functions?
  • What is the difference between the functions unlink and unset?
  • What is the difference between htmlentities() and htmlspecialchars()?
  • What is the difference between the functions unlink and unset?
  • In how many ways we can ways we can carry data from one page to other? (POST, GET, SESSION, COOKIE, Query String)
  • How can we know the number of days between two given dates?
  • What is session and how it works?
  • Why we use @ symbol before and function or variable?
  • Where we use === ?
Questions from Object Oriented Programming
  • What are access modifiers?
  • What is final keyword?
  • What is function overloading?
  • What is function overriding?
  • How to print and Object?
  • What is the use friend function?
  • What are the difference between abstract class and interface?
  • What are constructors and de-constructors and how we define them?
  • Define exceptions ?
Advance PHP
  • What is register_globals?
  • What is GD library?
  • How we can execute a PHP script from command line?
  • What we have to do upload a file of 1GB using a form?
  • What is cURL?
  • PHP how to know user has read the email?
  • What is PDO ?
  • Why we use ob_start() and ob_flush() functions?
  • What is the diffrence between Notify URL and Return URL?
    Answer:
    Notify URL
    : The URL to which PayPal posts information about the transaction via Instant Payment Notification. Must be URL-encoded. Its an optional field have maximum 256 characters length.Return URL: The URL to which the customer’s browser is returned after completing the payment; for example, a URL on your site that displays a “Thank you for your payment” page.
  • How we increase execution time of the script?
MVC Questions
  • What is MVC?
  • What are benefits of using MVC?
MySQL
  • What is the difference between CHAR and VARCHAR data types?
  • How can we know the number of days between two given dates using MySQL?
  • How we can store a image in MySql table?
  • How we can store an array in MySql?
  • How can we encrypt and decrypt a data presented in a table using MySQL? (AES_ENCRYPT, AES_DECRYPT)
  • What are stored procedures?
  • What is the difference between stored procedure and functions?
  • What are database engines and name some you know?
  • What is the difference between MyISAM and Innodb?
  • What is cascading?
  • What is view?
  • What is query optimisation and what we should do optimise a query?
  • What is difference between “DELETE from <table_name>” and  TRUNCATE <table_name>?
  • How can we repair a MySQL table?
  • What is the difference between Primary Key and Unique key?
  • What is the difference between char and varchar data types?
  • How can we know the number of days between two given dates using
    MySQL?
  • Explain Left Join?
  • What is full text search and which db engine support this?
  • What is transaction safe and which db engine support this?
Security
  • What is SQL injection?
  • What is XSS attacks?
  • Where and why we use htmlentities(), strip_tags(), utf8_decode() and addslashes()?
Logical & Debugging
  • What are the some reasons for the error “Cannot modify header information – headers already sent” and how we can resolve this?
JavaScript
  • How many ways I can redirect a PHP page using javascript?
Ajax
jQuery

Basic Tomcat Configuration
Tomcat 6 server is configured by setting parameter values for the components of Tomcat 6 before starting the server. Tomcats configuration is always stored within one or more XML files, the files contain numerous elements that are configurable. This web pages details the two most important files server.xml and context.xml, I will also discuss configuration files that the Service, Servers, Engine, Connectors, Realm and Valves use.
There is a Web-based GUI configuration tool called the Admin Web application, hopefully it should be bundled very soon.
Configuration Essentials
Tomcat uses 3 files to start with
server.xml
The primary configuration file, this file configures the Service, Connector, Engine, Realm, Valves, Hosts, etc. You also configure the virtual hosts in this file.
context.xml
Default version of the per-application configuration file for server components. Any components in this file are applied to all applications running on the server. You can override this file by placing a context.xml within the applications META-INF directory.
Components such as session persistence managers, Realms and resources such as JDBC connections are all configured here.
web.xml
Default version of the standard Java EE deployment descriptor for web applications, this is used by all applications unless it has been overridden by the application own web.xml file.
It provides servlet definition and MIME mappings common to all Web applications.
These files are kept in the conf directory, there are a number of other files that are used in this directory, i have already touched on these files in Tomcat Architecture
tomcat-users.xml
this file contains user authentication and authorization and role-mapping information for setting up a UserDatabase realm.
catalina.policy
Java SE has a fine-grained security model that enables the administrator to control in detail the accessibility of system resources
catalina.properties
This file provides for internal package access and definition control as well as control over contents of Tomcat class loaders
logging.properties
Tomcat uses it own logging to write log files, you can control the level of logging in this file and can change the destination if so desired



1 comment:

  1. Hello Mansoor,


    Apache Server Interview Questions being contrived to exist for many projects simply so it can be run will be the first to hit the wall, but those projects where the functions to make existing transactions cheaper in real world applications will find the elusive real world demand.

    I just got Linux for my Samsung chrome book, I used Crouton with the interface xfce. However, when I turn off the device and turn it on I enter a factory reseted device and have to redo the whole process. I'm I doing something wrong or do I have to redo everything every single time?
    Thank you very much and will look for more postings from you.


    Merci,
    Abhiram

    ReplyDelete