Monday, October 21, 2013

Using Tomcat & Apache for APEX and Oracle XE

Using Open Source components is always my first priority for software application design.  In recent APEX Listener releases, Oracle removed the instruction of using Tomcat, and it added Weblogic and Glassfish as Servlet container instead. I think it's a really bad idea that Oracle tried too hard to push their products and suppressed the info of using free alternatives.  It just make me even more likely not to use Weblogic nor Glassfish to host APEX application.  If you want to get the best, free, and most stable combination of software stack to host the APEX installation, here are the steps.  I created these steps under Windows 7 platform. However, the same steps could be apply to any Linux/Unix environment.

Once the setup has done and the site runs smoothly, you can then add any framework, Servlet, JSP, web services or other open-source components to enrich your application easily.

Bottom line: no need to use Weblogic for APEX unless you are designing the Obamacare website.

(1) Install Oracle XE 11g as usual

(2) Open SQL*Plus as sysdba, run the script to drop original APEX installation:
C:\oraclexe\app\oracle\product\11.2.0\server\apex\apxremov.sql

(3) Download APEX Release 4.2.3 from http://download.oracle.com/otn/java/appexpress/apex_4.2.3.zip.  Unzip this file to c:\temp\apex423.

(4) Open SQL*Plus as sysdba, run the script to install APEX 4.2.3
c:\temp\apex423\apex\apexins.sql SYSAUX SYSAUX TEMP /i/

(5) Unlock the account APEX_PUBLIC_USER and reset its password
alter user APEX_PUBLIC_USER account unlock;
alter user APEX_PUBLIC_USER identified by APEX_PUBLIC_USER;

(6) Run the script c:\temp\apex423\apex\apxconf.sql to set admin initial password and the XDB port to zero (to avoid port conflict with Tomcat)
SQL> @apxconf.sql
      PORT
----------
      8080
Enter values below for the XDB HTTP listener port and the password for the Application Express ADMIN user.
Default values are in brackets [ ].
Press Enter to accept the default value.
Enter a value below for the password for the Application Express ADMIN user.
Enter a password for the ADMIN user              []
Session altered.
...changing password for ADMIN
PL/SQL procedure successfully completed.
Enter a port for the XDB HTTP listener [      8080] 0
...changing HTTP Port
PL/SQL procedure successfully completed.

(7) Download APEX Listener 2.0.5 from  http://download.oracle.com/otn/java/appexpress/apex_listener.2.0.5.287.04.27.zip.  Unzip this file to C:\temp\apex_listener

(8) Create a directory (C:\APEX) to hold the APEX configuration data.  Then run the config.
java -jar c:\temp\apex_listener\apex.war
Enter the location to store configuration data:C:\apex
Oct 21, 2013 12:26:07 PM oracle.dbtools.common.config.cmds.ConfigDir execute
INFO: Set config.dir to C:\apex in: C:\temp\apex_listener\apex.war
Oct 21, 2013 12:26:10 PM oracle.dbtools.common.config.file.ConfigurationFolder logConfigFolder
INFO: Using configuration folder: C:\apex\apex
Enter the name of the database server [localhost]:
Enter the database listen port [1521]:
Enter 1 to specify the database service name, or 2 to specify the database SID [1]:2
Enter the database SID [xe]:XE
Enter the database user name [APEX_PUBLIC_USER]:
Enter the database password for APEX_PUBLIC_USER:
Confirm password:
Enter 1 to enter passwords for the RESTful Services database users (APEX_LISTENER,APEX_REST_PUBLIC_USER),
2 to use the same password as used for APEX_PUBLIC_USER or, 3 to skip this step [1]:3
Oct 21, 2013 12:26:36 PM oracle.dbtools.common.config.file.ConfigurationFiles update
INFO: Updated configurations: defaults, apex
Enter 1 if you wish to start in standalone mode or 2 to exit [1]:2

(9) Download Tomcat 7, unzip/install it to a directory (e.g. C:\TOMCAT7)

(10) copy the war file C:\temp\apex_listener\apex.war to C:\TOMCAT7\webapps.  Move the directory C:\temp\apex423\images to C:\apex\images

(11) Edit the tomcat config file C:\TOMCAT7\conf\server.xml to create the URI path of /i/ to c:\apex\images
....
<Host name="localhost" appBase="webapps"
....
<Context docBase="C:\apex\images" path="/i" />
...
</Host>

(12) Make sure system variable JAVA_HOME has set.  Start Tomcat and open URL http://localhost:8080/apex
Browse around and check whether it run properly.  If it looks good, shutdown Tomcat.

(13) Download Apache HTTP Server 2.4 binaries VC11 from Apache Lounge (and corresponding Visual Studio Redistributable).
Then download Tomcat connector from Apache (tomcat-connectors-1.2.37-windows-i386-httpd-2.4.x.zip)

(14) Unzip/Install Apache HTTP Server to C:\Apache24.  Extract the Tomcat connector file mod_jk.so and put it to C:\Apache24\modules

(15) Create the Tomcat Worker file (worker.conf) and put it under C:\Apache24\conf.  The content is similar as follows:
workers.tomcat_home=C:/tomcat7
workers.java_home=C:/JRE7
worker.list=worker1

worker.worker1.type=ajp13 
worker.worker1.host=localhost 
worker.worker1.port=8009 

(16) Edit the Apache config file (httpd.conf) and add these lines:
LoadModule jk_module modules/mod_jk.so

JkWorkersFile C:/Apache24/conf/worker.conf
JkLogFile     C:/Apache24/logs/mod_jk.log
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkMount  /apex/*  worker1

Alias /i/ C:/APEX/images/
<Directory C:/APEX/images>
    Require all granted
</Directory>

(17) Remove the change in Step (11) since the static files are served by Apache now.

(18) Start Tomcat, and then start Apache.  Open URL http://localhost/apex
Browse around and check whether it run properly.




9 comments :

Unknown said...

Thanks for the excellent post, just what I need, will try it out with linux

Unknown said...

For this: Step (13) Download Apache HTTP Server 2.4 binaries. They are windows binaries, can I do the same for Linux ?

Bill Ennis said...

Appreciate the post. I'll give it a try. Is the Apache http install optional?

Koloo said...
This comment has been removed by the author.
Koloo said...

chris,

I am having problem trying to implement sso/single sign-on Apache Web server with Apex listener on unix red hat but what do ive to do next to implement sso ive installed apex listener and installed already the apache server?

thank you.

Anonymous said...

Thanks for the excellent post it is really very helpful blog,
Thank you so much.

Anand said...

Good one. Thanks for this article. We don't want to invest in Glass fish or weblogic for this, so Tomcat will be an ideal solution for this situation. Can this sustain for 200 - 300 users?

whats up said...

Awesome post.Helpful post

Unknown said...

Hi,

I tried installing tomcat 7 and it works but after installing apache and doing all configs, i get error when accessing localhost/apex as requested url /apex was not found on this server. Please help