Tuesday, March 29, 2011

Install Apache module without re-installation with APXS

In case we have installed Apache using source code and we would like to install one of its modules called mod_rewrite or whatever. Then we need to do the following to install module without re-installing Apache:




cd apache-source-code
cd modules/mappers

/path/to/apache2/bin/apxs -iac mod_rewrite.c


Add following to httpd.conf file:


LoadModule rewrite_module modules/mod_rewrite.so




Then Restart Apache, thats it!!!

Tuesday, March 15, 2011

Apache Virtual Hosting


What is Apache Virtual Hosting?

When setting up more then One Host/Site over Single Server, this is called Virtual Hosting.

Virtual Hosting can be of 2 type's:

1) Name Based Virtual Hosting
2) IP Based Virtual Hosting

1) Name Based Virtual Hosting : Running multiple virtual hosts over a Single IP is called Name Based Virtual Hosting.

2) IP Based Virtual Hosting : When a Server is having multiple IP's and per IP is having it's own Virtual Host is called IP Based Virtual Hosting.


How to Setup Name Based Virtual Hosting and IP Based Virtual Hosting?

Name Based Virtual Host :

edit /etc/httpd/conf/httpd.conf

Listen 192.168.1.1:80

NameVirtualHost 192.168..1.1:80

VirtualHost 192.168..1.1:80
ServerName localhost
ServerAlias localhost.localdomain
DocumentRoot /var/www/html

Directory /var/www/html
AllowOverride None
Options -Indexes -FollowSymLinks
Order allow, deny
Allow from All
/Directory

CustomLog logs/localhost_access.log common
ErrorLog logs/localhost_error.log
/VirtualHost


VirtualHost 192.168..1.1:80

ServerName fistsite.com
ServerAlias www.firstsite.com
DocumentRoot /var/www/html/firstsite

Directory /var/www/html/firstsite
AllowOverride None
Options -Indexes -FollowSymLinks
Order allow, deny
Allow from All
/Directory
CustomLog logs/firstsite_access.log common
ErrorLog logs/firstsite_error.log
/VirtualHost
------------------------------------------------------------------------------------------------

IP Based Virtual Host:


edit /etc/httpd/conf/httpd.conf

Listen 192.168.1.1:80
Listen 192.168.1.2:80


VirtualHost 192.168..1.1:80
ServerName localhost
ServerAlias localhost.localdomain
DocumentRoot /var/www/html

Directory /var/www/html
AllowOverride None
Options -Indexes -FollowSymLinks
Order allow, deny
Allow from All
/Directory

CustomLog logs/localhost_access.log common
ErrorLog logs/localhost_error.log
/VirtualHost


VirtualHost 192.168..1.2:80
ServerName fistsite.com
ServerAlias www.firstsite.com
DocumentRoot /var/www/html/firstsite

Directory /var/www/html/firstsite
AllowOverride None
Options -Indexes -FollowSymLinks
Order allow, deny
Allow from All
/Directory
CustomLog logs/firstsite_access.log common
ErrorLog logs/firstsite_error.log
/VirtualHost

VirtualHost 192.168..1.3:80
ServerName second.com
ServerAlias www.second.com

DocumentRoot /var/www/html/second

Directory /var/www/html/second
AllowOverride None
Options -Indexes -FollowSymLinks
Order allow, deny
Allow from All
/Directory

CustomLog logs/second_access.log common
ErrorLog logs/second_error.log
/VirtualHost

-------------------------------------------------------------------------------------------------

Wednesday, March 9, 2011