Integrating Apache and Tomat with mod_jk

This post is a continuation of my previous post. In this post I’ll tell you what I did to access my tomcat apps via Apache.

All the files you edit here are very crucial. Take a backup and make a note of the changes you do. Otherwise, it may goof your Apache configuration.

Installing mon-jk library

$ sudo apt-get install libapache2-mod-jk

Make sure the AJP redirect port is enabled on tomcat/config/server.xml

<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />

Create a new worker file

sudo vi /etc/apache2/workers.properties

# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

Reconfigure jk.conf

Change the JkWorkersFile property to /etc/apache2/workers.properties

sudo vi /etc/apache2/mods-available/jk.conf

# JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkWorkersFile /etc/apache2/workers.properties

Configure the URL Apache should pass through the Tomcat

sudo vi /etc/apache2/sites-enabled/000-default

and add the line starts with JKMount in your configurtation

<VirtualHost *:80>
…………………………………
…………………………………
JkMount /gplus* worker1
</VirtualHost *:80>

Restart apache

I found http://<apacheIP>/gplus worked.

Appreciations and thanks to http://thetechnocratnotebook.blogspot.sg/2012/05/installing-tomcat-7-and-apache2-with.html

 

 

 

 

 

Setting up Ubuntu VM in Azure cloud for PHP & Java development

This step by step guide will be helpful to understand how to setup LAMP with tomcat on a fresh Ubuntu Azure VM

What are we going to do?

  1. Install Apache
  2. Install PHP
  3. Open Azure firewall for port 80
  4. Configure Apache for PHP
  5. Install mysql
  6. Install phpmyadmin
  7. Install FTP Server
  8. Install JDK 8
  9. Install Tomcat 8
  10. Open Azure firewall for port 8080
  11. Deploy a war file to tomcat

All of the instructions given below assumes you have a SSH connection to your Azure VM.

02

Apache

sudo apt-get install apache2

Let’s start apache service

pandian@grassfield:~$ sudo /etc/init.d/apache2 start
* Starting web server apache2                                                   *

Is it listening to port 80?

pandian@grassfield:~$ telnet localhost 80
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.

Let’s open the port 80 with azure firewall.

Goto Network security groups

03

You will find you security group. If you don’t find any, add one.04

This is your essential settings. Click on Inbound security rules

05

You will find the rules created already. Here is the one created for SSH access.

06

Allowed TCP Port 80

08

Try to browse your public IP on your browser.

12

PHP

sudo apt-get install php5

Let’s test php now.

$ cd /var/www/html/

$ sudo mkdir testphp

$ sudo  chmod 777 testphp/

$ cd testphp/

$ vi index.php

09

Try to browse your url.

10

MySQL

ok

Lets install mysql and its connectors now

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Lets’s start it now.

pandian@grassfield:~$ sudo /etc/init.d/mysql start
* Starting MySQL database server mysqld                                 [ OK ]

Check the port is open

$ telnet localhost 3306
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
[
5.5.46-0ubuntu0.14.04.2

Lets install phpmyadmin now. Otherwise, I’ll feel handicapped as many other developers

sudo apt-get install phpmyadmin

Lets test if this is accessible.

11

Java SDK

We can install Open JDK, But I wanted to use the oracle jdk. Hence I downloaded and transferred the .tar.gz file using SCP.

$ wget http://xxxxxxxxxxxxxxxxxx/jdk-8u65-linux-x64.tar.gz

$ gunzip jdk-8u65-linux-x64.tar.gz

$ tar -xvf jdk-8u65-linux-x64.tar

$ jdk1.8.0_65/bin/java -version
java version “1.8.0_65”
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

Tomcat

$ wget http://www.eu.apache.org/dist/tomcat/tomcat-8/v8.0.30/bin/apache-tomcat-8.0.30.tar.gz

$ gunzip apache-tomcat-8.0.30.tar.gz

$ tar -xvf apache-tomcat-8.0.30.tar

$ cd apache-tomcat-8.0.30/bin

$ ./catalina.sh start
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program

$ export JAVA_HOME=/home/pandian/jdk1.8.0_65

$ ./catalina.sh start              Using CATALINA_BASE:   /home/pandian/apache-tomcat-8.0.30
Using CATALINA_HOME:   /home/pandian/apache-tomcat-8.0.30
Using CATALINA_TMPDIR: /home/pandian/apache-tomcat-8.0.30/temp
Using JRE_HOME:        /home/pandian/jdk1.8.0_65
Using CLASSPATH:       /home/pandian/apache-tomcat-8.0.30/bin/bootstrap.jar:/home/pandian/apache-tomcat-8.0.30/bin/tomcat-juli.jar
Tomcat started.

Make sure tomcat is started

tail ../logs/catalina.out

09-Jan-2016 11:34:16.126 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 5799 ms

Okay! Ready!!

 

 

 

 

Apache VirtualHosts – HowTo

IMAG0652

I used to do this whenever I make a new PHP project. But I forget the steps often. This post will explain you how to add a new virtual host in apache.

1. Apache server installed (I’ve used XAMPP ) with php plugin enabled

2. Make a new folder in your computer. Ensure you have an index.html or index.php on that folder. I’ve my folder on C:\xampp\htdocs\market

3. Make the following steps on C:\xampp\apache\conf\extra\httpd-vhosts.CONF file. This will be the file to define your virtual hosts

Add the following lines at the end of this file.

#this is to access the standard xampp home page
NameVirtualHost localhost:80
<VirtualHost localhost>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
#ServerAlias http://www.dummy-host.localhost
#ErrorLog "logs/dummy-host.localhost-error.log"
#CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>

#this is our virtual host grassfield.dev
NameVirtualHost grassfield.dev:80
<VirtualHost grassfield.dev>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs\market"
ServerName grassfield.dev
#ServerAlias http://www.grassfield.dev
#ErrorLog "logs/grassfield.dev-error.log"
#CustomLog "logs/grassfield.dev-access.log" combined
</VirtualHost>

4. Restart the apache service

5. Access http://localhost and http://grassfield.dev sites are rendered correctly on the browser. Sample file is attached in this post.

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/&gt;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
NameVirtualHost localhost:80
<VirtualHost localhost>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
#ServerAlias http://www.dummy-host.localhost
#ErrorLog "logs/dummy-host.localhost-error.log"
#CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias http://www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</Virtual
NameVirtualHost grassfield.dev:80
<VirtualHost grassfield.dev>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs\market"
ServerName grassfield.dev
#ServerAlias http://www.grassfield.dev
#ErrorLog "logs/grassfield.dev-error.log"
#CustomLog "logs/grassfield.dev-access.log" combined
</VirtualHost>

The picture at the top don’t have any relations with this post 😉

Apache – Tomcat connector in Windows

This is another interesting assignment completed today. Though our CRM portal is no so busy, we want to in a robust infra. There are series of new releases available kn the market. JDK 7, Tomcat 7 etc. Previously the application was using tomcat itself as a web server. This is a risky situation since I expose the complete applivation to public. Hence I have installed the apache as web front-end and tomcat 7 as middleware.

Here is the procedure:

mod_proxy_ajp would be the easiest to use if you are using Apache 2.2. It is part of the Apache distribution so you don’t need to install any additional software.

In your httpd.conf you need to make sure that mod_proxy and mod_proxy_ajp are loaded:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

Then you can use the ProxyPass and ProxyPassReverse directives as follows:

ProxyPass /portal ajp://localhost:8009/portal
ProxyPassReverse /portal ajp://localhost:8009/portal

As simple as that.