It is often very helpful to test changes to a website before deploying to the production web server. If you have made changes to just one html file you can browse the file directly on your computer by referring to it as a file://path/filename.html. The disadvantage is that you may not be able to test all of the links to and from the file and you cannot test java servlets. A better way to test your changes is to host the entire Website, including any java servlets, on your local computer. Testing your Website on your local computer is normally called local hosting. This tutorial provides instructions for how to setup local hosting in linux or OSX. The basic steps required to setup local hosting are as follows:
For information on downloading and configuring Apache HTTP and Tomcat please refer to and follow the instructions on the Apache website. The following is detailed instructions for each of the major steps:
Creating a Virtual Host in Apache: To create a new Virtual Host in Apache you need to edit the <VirtualHost ...> section inside the /etc/apache2/extra/httpd-vhosts.conf as shown in the example below:
<VirtualHost *:80>
ServerAdmin username@mail.com
DocumentRoot "/Users/dparoulek/app/pnatts"
ServerName yoururl.com
ErrorLog "/private/var/log/apache2/yoururl.com-error_log"
CustomLog "/private/var/log/apache2/yoururl.com-access_log" common
<Location />
Order allow,deny
Allow from all
</Location>
<Directory /Users/yourusername/app/urldirectory>
Require all granted
</Directory>
</VirtualHost>
Enable Virtual Hosts in Apache: Enable vhosts by uncommenting the following line in /etc/apache2/httpd.conf:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
Set File Permissions: To set file permissions run the following:
Restart Apache: Use the following command to restart apache:
Start Tomcat: Use the following command to start tomcat:
Mapping your url to local host: To trick your computer into thinking that your url (yoururl.com) is localhost you need to edit /etc/hosts and add a line like the following:
127.0.0.1 yoururl.com
Now when you type yoururl.com into your browser you should see your website that is running on your local computer. If you have problems you can check the connections using the curl command: