Apache Web Server Apache Web by hcj


									Apache Web Server configration files: - httpd.conf - htaccess ex: <ifdefine closedForNow> Redirect http://otherserver.example.com </ifdefine> > httpd –D closedForNow File Systems and Web Space: - File System (Phsical) <directory> <files> -Web Space (Virtual) <location> <alias> ex: <directory /var/web/dir1> Options +Indexes </directory> <Files private.html> Order Allow, Deny Deny From All </Files> <Directory /var/web/dir1> <Files private.html> Order Allow, Deny Deny From All </Files> </Directory> <Location /private> Order Allow, Deny Deny From all </Location> Wildcards: *, ?, [], / DirectoryMatch, FilesMatch, LocationMatch ex: <Directory /home/*/public.html> Options Indexes </Directory> <FilesMatch \.(?i:gif|jpeg?|png)$> Order Allow, Deny Deny From All </Files Match>

!TRY FILE SYSTEMS FOR SECURITY ex: <proxy http://cnn.com/*> Order Allow, Deny Deny From All </proxy> <Location /> Order Allow, Deny Allow From All <Location> <Directory /> Order Allow, Deny Allow From All # doesnt take effect Deny From badguy.example.com </Directory> htaccess files: provides a way to make configration changes on a per directory basis AccessFileName .config # alters .htaccess file

AllowOverRide All AllowOverRide Name | FileInfo | Indexes This file should be used ONLY in case where the content provides need to make configration changes to the server on a per directory basis but dont have root access on the server system. ex: htaccess file: AddType text/example .ex main config file: <Directory /www/htdocs/example> AddType text/example .ex </Directory> The use of htaccess file may be disabled by “AllowOverRide None” Virtual Host: The practice of running more than one web site on a single machine - Ip Based (an IP Address for each web site) - Name Based (more than one wen site on a single IP)

IP Based virtual host: server must have a different IP address for each IP based virtual host - Run a seperate httpd deamon for each host name (different user, group, Listen and ServerRoot) - Run a single deamon which supports all the virtualhosts to set up multiple deamons: create seperate httpd installation, use listen directive in the config file to select the ip address. Listen www.smallco.com:80 single domain with multiple virtual hosts: the virtualhost directive in the configration file is used to set the values of ServerAdmin, ServerName, DocumentRoot, ErrorLog, TransferLog and Customlog. ex: <VirtualHost www.smallco.com> ServerAdmin webmaster@mail.smallco.com DocumentRoot /groups/smallco/www ServerName www.smallco.com ErrorLog /groups/smallco/logs/error.log TransferLog /groups/smallco/logs/transfer.log </VirtualHost> <VirtualHost ...> .. </VirtualHost> Name Based virtualHosts: 1- Need to cınfigure DNS server to map each hostname to the correct IP address and then configure the apache server to recıgnize the different hostnames. 2- the client must send the http host header HTTP/1.1 3- cannot use with SSL ex: NameVirtualHost * <VirtualHost *> ServerName www.domain.com ServerAlias domain.com, *.domain.com DocumentRoot /www/domain </VirtualHost> <VirtualHost *> ServerName www.otherdomain.com ServerAlias otherdomain.com, *.otherdomain.com DocumentRoot /www/otherdomain </VirtualHost> when a request arrives at the server will first check if it is using an IP address that matches the NameVirtualHost. If it is then it will look at each <VirtualHost> section with a matching IP address and try to find one where the servername or serveralias matches the requested hostname. If no matching found the first listed virtualhost that matches the IP address will be used.

ex: NameVirtualHost <VirtualHost> ServerName www.domain.com ServerPath /domain DocumentRoot /web/domain </VirtualHost> Note: All URI’s beginning with /domain will be redirected to virtualhost www.domain.com Dynamic Content With CGI: 1- ScriptAlias /cgi-bin /usr/local/apache/cgi-bin 2- <Directory /usr/local/apache/htdocs/somedir> Options +ExecCGI </Directory> 3- AddHandler cgi-script .cgi .pl ex: Options +ExecCGI AddHandler cgi-script cgi pl or Options +ExecCGI SetHandler cgi-script or .htaccess file AllowOverRide Options Options +ExecCGI Authentication, Authorization and Access Control: AllowOverRide .AuthConfig creating a password file: > htpasswd –c /usr/local/apache2/passwd/passwords <Directory /usr/local/apache2/htdocs/secret> AuthType [Basic|Digest] AuthName “Restricted Files” AuthUserFile /usr/local/apache2/passwd/passwords Require [user|group] rbowen </Directory> AuthGoupFile (content is simple) GroupName: rbowen dpitts sungo > AuthGroupFile /usr/local/apache2/passwd/groups

.htaccess file AuthType Basic AuthName “Password Required” AuthUserFile /usr/local/apache2/passwd/passwords AuthGroupFile /usr/local/apache2/passwd/groups Require Group Admins Tips: Deny From Deny From host.example.com Order Allow, Deny Deny From All Allow From dev.example.com Main Configration Parameters: ServerName The real name of the server at the DNS server or real IP address. Check the value if it is true or not Listen (Port) Which port do you want server to listen (Default 80) HostNameLookups To see the IP address -> Client name convertion of the computers that are connected to the server ServerAdmin The email address of the apache server manager StartServers The program count that will be started at the initalization of the apache MaxClients The maximum client number that can be connected to the server Redirect If the clients as a in a certain directory you can redirect them to another site. Redirect /linux www.linux.org ServerAlias If we want to connect more than one domain names then we use this parameter. ServerAlias gelecek.com.tr *.gelecek.com.tr DocumentRoot The directory that html documents will be placed UserDir To create a web site to the name of a user. ex.www.itu.edu.tr/~epeker (userdir / web, userdir / www) DirectoryIndex The first file to be read while visiting a directory ScriptAlias The place of the programs on the server and how you can reach them. (ScriptAlias /cgi-bin /home/httpd/html)

ex: (some sample httpd.conf configurations) IP of the server: CNAME register in the DNS Server: Port 80 ServerName server.firm1.com.tr NameVirtualHost <VirtualHost> DocumentRoot /www/firm1 ServerAdmin admin@firm1.com.tr ServerName www.firm1.com.tr ErrorLog logs/firm1_errorlog TransferLog logs/firm1_transferlog </VirtualHost> <VirtualHost> DocumentRoot /www/firm2 ServerAdmin admin@firm2.com.tr ServerName www.firm2.com.tr ErrorLog logs/firm2_errorlog TransferLog logs/firm2_transferlog </VirtualHost> Password Authentication 1- Arrange The Directory 2- AuthName AuthType AuthUserFile Require 3- htpassword –c /usr/local/passwords username www.firm1.com.tr www.firm2.com.tr

Enable PHP With Apache <ifModule> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </ifModule> PHP and Apache Installation (tested with PHP4.3.4 Apache 2.0.48) 1. 2. 3. 4. 5. 6. 7. 8. gzip -d httpd-2_0_NN.tar.gz tar xvf httpd-2_0_NN.tar gunzip php-NN.tar.gz tar -xvf php-NN.tar cd httpd-2_0_NN ./configure --enable-so make make install Now you have Apache 2.0.NN available under /usr/local/apache2, configured with loadable module support and the standard MPM prefork. To test the installation use your normal procedure for starting /usr/local/apache2/bin/apachectl start /usr/local/apache2/bin/apachectl stop 9. 10. 11. 12. 13. cd ../php-NN ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql ./configure --help for a list of available options make make install Setup your php.ini cp php.ini-dist /usr/local/lib/php.ini If you prefer having php.ini in another location, use –with-configfile-path=/some/path in step 10 14. Edit your httpd.conf to load the PHP module LoadModule php4_module libexec/libphp4.so LoadModule php5_module libexec/libphp5.so 15. Tell Apache to parse certain extensions as PHP AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps /usr/local/apache2/bin/apachectl start

For windows: PHP and Apache 2.0 as CGI ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php.exe" PHP and Apache 2.0 as Module ; For PHP 4 do something like this: LoadModule php4_module "c:/php/sapi/php4apache2.dll" AddType application/x-httpd-php .php

; For PHP 5 do something like this: LoadModule php5_module "c:/php/sapi/php5apache2.dll" AddType application/x-httpd-php .php

To top