Search This Blog

Saturday 27 August 2011

Installing Virtual Hosts on Apache2 Webserver

Installing Virtual Hosts on Apache2
1. Create a folder for the domain:
mkdir -p /usr/share/tomcat/webapps/example

2. Within the /etc/apache2/sites-available/ folder create unique files for each of domains. For example, a file called “example” in that directory:
sudo nano /etc/apache2/sites-available/example

3. Copy content of default site to the newly created file:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example
(directories for Apache and Tomcat can be placed in a convenient place, however must be the same. For Tomcat server root folder for applications is webapps)

4. Adjust document roots as necessary and append to the file the following:

ServerName (name of the host)
JkMount /jsp/* worker1
JkMount /jsp worker1
#JkAutoAlias /usr/share/tomcat7/webapps/examples/
(appends requests for resources after webapps)
5. Enable mod_rewrite in Apache2:
sudo a2enmod rewrite

6. Now enable the site:
sudo a2ensite example

This site is now available (as in configured) and enabled (as in listening) once the Apache service is restarted:
sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 reload
sudo /etc/init.d/tomcat7 restart
 

Testing

7. To test your configuration you can, temporarily, configure the /etc/hosts file to point the domain to your IP address and see if your server loads up the correct site. This is only needed if the hostname or domain name does not already resolve to your IP address. Editing the /etc/hosts by adding the following line:
ip.address domain.tld (For instance 67.207.131.28 example.com)

8. Open a browser, try to access http://example and see if it loads the contents from the local DocumentRoot (from the configuration above). You might want to drop a file in the DocumentRoot to verify its pulling your local content:
sudo mv /var/www/index.html /usr/share/tomcat/webapps/examples/

9. Check PHP libraries:
sudo cp /var/www/test.php /usr/share/tomcat/webapps/examples/ or
sudo nano /usr/share/tomcat/examples/test.php
Write in it the only line:
<?php phpinfo(); ?>

10. Point the web browser to http://example/test.php and observe server’s phpinfo.

No comments:

Post a Comment