Disclaimer

The End Product

VirtualBox with Oracle Enterprise Linux 5.6

VirtualBox Basic Configuration

Creating a new VM

Setting up network

Installing OEL 5.6

Oracle Enterprise Linux Configuration

Configuring yum with Oracle public repository

Preparing for Oracle Software

The easy way

The Hard Way

Finalizing VirtualBox Setup

Installing VirtualBox Guest Additions

Adding Shared Folder

Starting Your VM Without Terminal Window

Cloning You Virtual Machine

Installing Oracle 11g XE

Pre Flight Check

Installing the software

Editing environment variables for user oracle

Installing Apache HTTP Server

Pre-requisites

Installing Apache

Configure automatic start

Configure Apache with APEX

Copy images directory

Configure Apache with APEX

Installing Java

Installing Apache Tomcat 7

Installation

Configure automatic startup

Installing and configuring APEX Listener with Apache HTTP and Apache Tomcat

Installing APEX Listener

Configure APEX Listener

Bringing it together

Upgrading to Application Express 4.1

Disclaimer

This document is no guarantee for happiness or good health, but it might save you some trouble nonetheless.

This is more like a log of observations for my own use, and I give no guarantees as to the end result (you know; whatever you do, do not blame it on me ).

The End Product

So, what am I aiming at here? Briefly it’s the architecture illustrated below:

 

This is nothing new, but sure to give some headaches if it is you first time.

Why did I choose Tomcat when it is not a supported configuration? Well, old habits die hard I guess. I know Tomcat, that is all...

VirtualBox with Oracle Enterprise Linux 5.6

This is an installfest for OEL 5.6 64bit with some tidbits of software. It is based on a Windows 7 64-bit host, but should be similar for Linux host as well. Written for VirtualBox 4.1.2r73507.

Oracle Linux is licensed under GNU GPL, but commercial technical support can be bought.

I used Dr. Tim Hall et al at http://oracle-base.com for the VirtualBox, Linux and Oracle database installations when I got stuck:

If I have gotten any of the steps here wrong, he probably got them right!

VirtualBox Basic Configuration

Setting default directory and host-only network

Creating a new VM


Setting up network

For this particular configuration, I am going to use two network adapters: One used as a static IP for the Host Only Network, and secondary as a DHCP Bridged Network to be used with yum and such.


Installing OEL 5.6

Oracle Enterprise Linux Configuration

After reboot:

 

Configuring yum with Oracle public repository

Preparing for Oracle Software

Beware that some of the packages installed here, will be used by the Virtualbox Guest Additions too.

The easy way

The Hard Way

Choose the easy way!

Finalizing VirtualBox Setup

Installing VirtualBox Guest Additions

This is probably going to be a bit messy, so bear with me…

Adding Shared Folder

Starting Your VM Without Terminal Window

Now that things are starting to get settled, maybe you won’t need the gui anymore (putty works just fine). The blog post here gave me some pointers: http://blogs.oracle.com/mock/entry/running_virtualbox_vms_as_services.

[Settings]

ServiceName=VBoxVmService

VBOX_USER_HOME=C:\Users\<your windows user name>\.VirtualBox

PauseShutdown=5000

[Vm0]

VmName=oel-5.6-64-base

WorkingDir=C:\Software\VirtualMachines\vms

ShutdownMethod=acpipowerbutton

AutoStart=yes

To start you vms, just right click the “Start My VMs.bat” and choose “Run as Administrator”.

Cloning You Virtual Machine

Before moving on with installing more software on your machine, this is a nice time to backup your work. I will create a clone of my machine at present state (chicken backup…).

I prefer cloning when “BIG” things happen to my vm’s, and use the snapshots for smaller changes. If I want to have a version of the vm without any Oracle software installed, I clone, if I want to try out different install options for software, I use snapshots.

Installing Oracle 11g XE

Pre Flight Check

First off, remove Network Adapter 2 with DHCP, we will use static IP for this:

Installing the software

After booting, log in as root

Editing environment variables for user oracle

Done.

Installing Apache HTTP Server

I like things tidy, so I will install a new Apache HTTP server at the same location as the rest of the server products (/u01), and ditch the one that came with the installation.

A side note: From here on out, there will be precious little gui. If you are not familiar with linux command line or vi, you will probably get through, but knowledge of these are preferable.

Pre-requisites

(Rant: don’t you just hate it when you see that: “pre-requisites”?!? All the hard parts are usually hidden behind the precious few bullet points following “pre-requisites”, and since they are just “pre-requisites”, the author never bothered to fully explain what you actually have to do… Like me :-))

Installing Apache

There are a number of install options, but we are going to keep it somewhat simple. It is going to be installed at /u01/app/apache2.

Configure automatic start

Setting up Apache for automatic start on boot

#!/bin/bash

#

# Startup script for the Apache Web Server

#

# chkconfig: - 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#              HTML files and CGI.

# processname: httpd

# pidfile: /u01/app/apache2/logs/httpd.pid

# config: /u01/app/apache2/conf/httpd.conf

# Source function library.

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then

        . /etc/sysconfig/httpd

fi

# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""

# Path to the apachectl script, server binary, and short-form for messages.

apachectl=/u01/app/apache2/bin/apachectl

httpd=/u01/app/apache2/bin/httpd

pid=/u01/app/apache2/logs/httpd.pid

prog=httpd

RETVAL=0

# The semantics of these two functions differ from the way apachectl does

# things -- attempting to start while running is a failure, and shutdown

# when not running is also a failure.  So we just do it the way init scripts

# are expected to behave here.

start() {

        echo -n $"Starting $prog: "

        daemon $httpd $OPTIONS

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd

        return $RETVAL

}

stop() {

        echo -n $"Stopping $prog: "

        killproc $httpd

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid

}

reload() {

        echo -n $"Reloading $prog: "

        killproc $httpd -HUP

        RETVAL=$?

        echo

}

# See how we were called.

case "$1" in

  start)

        start

        ;;

  stop)

        stop

        ;;

  status)

        status $httpd

        RETVAL=$?

        ;;

  restart)

        stop

        start

        ;;

  condrestart)

        if [ -f $pid ] ; then

                stop

                start

        fi

        ;;

  reload)

        reload

        ;;

  graceful|help|configtest|fullstatus)

        $apachectl $@

        RETVAL=$?

        ;;

  *)

        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status"

                echo $"|fullstatus|graceful|help|configtest}"

        exit 1

esac

exit $RETVAL

Configure Apache with APEX

If you want to use Oracle APEX with Apache Tomcat and APEX Listener, you must check the next chapter to avoid duplicate steps (no harm done, just unnecessary work…).

Copy images directory

Configure Apache with APEX

<VirtualHost *:80>

  ServerAdmin dummy@dummy-host.example.com

  DocumentRoot "/u01/www"

  ServerName bomturlocalhost

  ServerAlias bomturlocalhost

  #RewriteEngine On

  #RewriteLog "logs/rewrite.log"

  #RewriteLogLevel 9

  #LogLevel debug

  ProxyRequests Off

  SetEnv force-proxy-request-1.0 1

  SetEnv proxy-nokeepalive 1

  <location  /apex>

    RewriteEngine on

    # Look for requests using the GET request method

    RewriteCond %{REQUEST_METHOD} GET

    # Look for requests to /apex/f

    RewriteCond %{REQUEST_URI} /apex/f.*

    # Allow access if the app is 1000 and 2000 and 4*

    # If any of the following are removed, acces will be denied

    RewriteCond %{QUERY_STRING} !^p=1000.*

    RewriteCond %{QUERY_STRING} !^p=2000.*

    RewriteCond %{QUERY_STRING} !^p=4*

    # If the above rules match, then deny access

    RewriteRule /.* [F]

    SetEnv force-proxy-request-1.0 1

    ProxyPass http://127.0.0.1:8080/apex

    ProxyPassReverse http://127.0.0.1:8080/apex

  </location>

</VirtualHost>

 

Oracle APEX is now ready to use with Apache HTTP Server, if you have no interest in using APEX Listener with the Apache Tomcat, then you can end here.

Installing Java

Installing Apache Tomcat 7

Installation

Configure automatic startup

#!/bin/bash

# description: Tomcat Start Stop Restart

# processname: tomcat

# chkconfig: 234 20 80

JAVA_HOME=/u01/app/java/jre1.6.0_27

export JAVA_HOME

PATH=$JAVA_HOME/bin:$PATH

export PATH

CATALINA_HOME=/u01/app/tomcat7

case $1 in

start)

sh $CATALINA_HOME/bin/startup.sh

;;

stop)  

sh $CATALINA_HOME/bin/shutdown.sh

;;

restart)

sh $CATALINA_HOME/bin/shutdown.sh

sh $CATALINA_HOME/bin/startup.sh

;;

esac    

exit 0

tomcat          0:off   1:off   2:on    3:on    4:on    5:off   6:off

Installing and configuring APEX Listener with Apache HTTP and Apache Tomcat

I am going to use Apace HTTP in front of Apache Tomcat with APEX Listener installed. I will suffer the performance penalty of the extra software component (Tomcat) for the safety of running the listener inside a proven container. I will use mod_proxy/mod_proxy_http to achieve this.

Installing APEX Listener

Done with the Tomcat.

Configure APEX Listener

Bringing it together

To make it all work, Apache HTTP must be configured to route call through the APEX Listener in the Tomcat. The next steps will explain how to do this:

<VirtualHost *:80>

  ServerAdmin dummy@dummy-host.example.com

  DocumentRoot "/u01/www"

  ServerName bomturlocalhost

  ServerAlias bomturlocalhost

  #For debugging when something goes wrong

  #RewriteLog "logs/rewrite.log"

  #RewriteLogLevel 9

  #LogLevel debug

  ProxyRequests Off

  SetEnv force-proxy-request-1.0 1

  SetEnv proxy-nokeepalive 1

  <location  /apex>

    RewriteEngine on

    # Look for requests using the GET request method

    RewriteCond %{REQUEST_METHOD} GET

    # Look for requests to /apex/f

    RewriteCond %{REQUEST_URI} /apex/f.*

    # Allow access if the app is 1000 and 2000 and 4*

    # If any of the following are removed, acces will be denied

    RewriteCond %{QUERY_STRING} !^p=1000.*

    RewriteCond %{QUERY_STRING} !^p=2000.*

    RewriteCond %{QUERY_STRING} !^p=4*

    # If the above rules match, then deny access

    RewriteRule /.* [F]

    SetEnv force-proxy-request-1.0 1

    ProxyPass http://127.0.0.1:8900/apex

    ProxyPassReverse http://127.0.0.1:8900/apex

  </location>

</VirtualHost>

    <Connector port="8900" protocol="HTTP/1.1"

               connectionTimeout="20000"

               maxHttpHeaderSize="32676"

               redirectPort="8443"

               proxyPort="80"

               proxyName="<yourservername>"

    />

 

Notice the URL now points to port 80, and goes through Apache HTTP

Upgrading to Application Express 4.1

Oracle 11g XE ships with APEX 4.0.2, I am now going to upgrade to the latest version. I will only be installing APEX 4.1 en, as I only use the one language for development.

DECLARE

  ACL_PATH  VARCHAR2(4000);

  ACL_ID    RAW(16);

BEGIN

  -- Look for the ACL currently assigned to '*' and give APEX_040100

  -- the "connect" privilege if APEX_040100 does not have the privilege yet.

  SELECT ACL INTO ACL_PATH FROM DBA_NETWORK_ACLS

   WHERE HOST = '*' AND LOWER_PORT IS NULL AND UPPER_PORT IS NULL;

  -- Before checking the privilege, ensure that the ACL is valid

  -- (for example, does not contain stale references to dropped users).

  -- If it does, the following exception will be raised:

  --

  -- ORA-44416: Invalid ACL: Unresolved principal 'APEX_040100'

  -- ORA-06512: at "XDB.DBMS_XDBZ", line ...

  --

  SELECT SYS_OP_R2O(extractValue(P.RES, '/Resource/XMLRef')) INTO ACL_ID

    FROM XDB.XDB$ACL A, PATH_VIEW P

   WHERE extractValue(P.RES, '/Resource/XMLRef') = REF(A) AND

         EQUALS_PATH(P.RES, ACL_PATH) = 1;

  DBMS_XDBZ.ValidateACL(ACL_ID);

   IF DBMS_NETWORK_ACL_ADMIN.CHECK_PRIVILEGE(ACL_PATH, 'APEX_040100',

     'connect') IS NULL THEN

      DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(ACL_PATH,

     'APEX_040100', TRUE, 'connect');

  END IF;

EXCEPTION

  -- When no ACL has been assigned to '*'.

  WHEN NO_DATA_FOUND THEN

  DBMS_NETWORK_ACL_ADMIN.CREATE_ACL('power_users.xml',

    'ACL that lets power users to connect to everywhere',

    'APEX_040100', TRUE, 'connect');

  DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL('power_users.xml','*');

END;

/

commit

/

DONE :D