Skip to content

Instantly share code, notes, and snippets.

@lokesh-webonise
Last active November 5, 2023 20:23
Show Gist options
  • Save lokesh-webonise/5821607 to your computer and use it in GitHub Desktop.
Save lokesh-webonise/5821607 to your computer and use it in GitHub Desktop.
Tomcat virtual host configuration

Apache tomcat setup

###Pre-requisites JDK (java) should be install.

####1. To Install Java

Download jdk binary package.

Goto the downloaded directory. Give executable permission to jdk-6u31-linux-x64.bin file

chmod a+x jdk-6u31-linux-x64.bin

Run jdk binary file

./jdk-6u31-linux-x64.bin

Set Environment variable

vim /etc/profile
.
.
.
JAVA_HOME=<path-to-jdk-extracted-directory>
export JAVA_HOME
PATH=$JAVA_HOME:$PATH
:wq!

####2. Configure tomcat

Download Tomcat binary distribution from http://tomcat.apache.org/download-70.cgi, then extract it

tar -zxf <path-to-tomcat-tarball> -C /opt/

Start tomcat server

cd /opt/<tomcat-dir>/bin
./startup.sh

Open http://localhost:8080, 8080 is default for tomcat

####3. Create virtualhost in tomcat

Goto the tomcat root directory

cd /opt/<tomcat-root-directory>
vim conf/server.xml
.
.
<Engine....>
 <Host name="localhost"  appBase="webapps" aunpackWARs="true" autoDeploy="true">
.
.
.    
</Host>
<!-- Custom Virtual host -->
<Host name="abc.example.com" appBase="webapps/war-file-name" unpackWARs   ="true" autoDeploy="true">
    <Context path="" docBase="/opt/apache-tomcat-7.0.40/webapps/<war-file-name.war>"/>
</Host>
</Engine>
:wq!

Restart Apache tomcat server

cd /opt/<tomcat-dir>/bin
./shutdown.sh
./startup.sh

now open url http://abc.example.com:8080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment