Friday, January 30, 2015

Preparing architecture for APEX 5.0 upgrade

I doubted to set the title of this post to "Running APEX 4.2 and 5.0 in the same Oracle instance", but decided not to do that, but that is basically what I will do. Before going into details, I'll share my architecture.

In December 2013 I wrote it was time to update your APEX environment and I gave a quick overview of the architecture we're using. I thought it's time to review that post, so below you find how my preferred APEX architecture is today and tomorrow (once APEX 5 is production).

I'm using Apache as a reverse proxy in front of Tomcat. I'm not going in too much detail about which version to take: Apache v2.2 vs 2.4 and Tomcat v7 vs 8. There're many threads on the internet about that and I guess it depends your environment and your personal feeling. I've been using both versions but currently I'm on Apache v2.2 because it comes as a default with RHEL / OEL6 and SELinux is configured out of the box to protect the webserver. And for Tomcat I'm using v8 as that's the basis for the future versions of Tomcat (v9) and when you want to do Websockets for example, v8 has a more improved spec.

A few years ago we had the discussion about mod_plsql vs APEX Listener (now Oracle REST Data Services - ORDS). I think today, it's clear ORDS is the way to go as it gives you much more features and is proven technology.

For APEX I'm always on the latest version as fast as I can, as with every new release there're great improvements and fixes.

And finally the Oracle Database I'm on 12cR1 because I like the pluggable database concept and the other features it brings. I guess most people will go to 12c very soon, as 11.2 premier support ends this month. You can read more about when what is still supported in this doc.

But in this post I want to show you how easy it is to prepare your environment for APEX 5 and to test the upgrade with an architecture as above. I basically want to run APEX 4.2 and 5.0 next to each other. I'll clone my PDB and apply the APEX 5 installation on the new PDB. Next I'll configure ORDS so it knows to which database it needs to point to depending the url I'll call.

Step 1. Clone the PDB 

sqlplus / as sysdba

create pluggable database APEX50_PDB from APEX42_PDB file_name_convert=('/u01/app/oracle/oradata/cdb/APEX42_PDB','/u01/app/oracle/oradata/cdb/APEX50_PDB');

Step 2. Open the PDB and install APEX 5.0

alter pluggable database apex50_pdb open;

So now we have a new database which is a copy of our existing database open and ready to be used. Next we will need to install APEX 5.0. As the time of writing APEX 5.0 is not available yet, but it will probably be - connect to the new PDB and run @apexins... (follow the installation guide of APEX 5.0 once available!)

Step 3. Configure ORDS

With SQL Developer you can configure ORDS and add the connection to the new PDB.
In SQL Developer 4.1, first setup a connection to your ORDS (Tools > Manage REST Data Services Connections > Add Connection). Next open the ORDS Administration window (View > REST Data Services > Administration). Right click on the REST Data Services and Connect to ORDS:

You'll see the current configuration.

In order to connect to the new database we need to add a Database. Right click in Database Settings and add a new database. Before writing it back (the icon with the green up arrow - click the Test Settings button first (the icon with a v) to make sure everything is fine.

Final step is to let ORDS know that if we put in our url /apex50 we want to connect to the new database. You can do that by adding an entry in URL Mapping:

That's it...

Note: sometimes I've issues with adding the database and URL Mapping in SQL Developer, but it's as fast to do it command line too. The doc has a great example which commands to run:

Step 4. Test

When you navigate to your normal url e.g. http://localhost/ords/f?p=ABC you will see your APEX 4.2 instance, but if you navigate to http://localhost/ords/apex50/f?p=ABC you'll see the APEX 5.0 instance.

You can play a bit more with making it nicer urls or do some redirects in Apache, but I hope you get the idea how to start testing APEX 5.0 while still running APEX 4.2 too.


Scott Wesley said...

Wow, 12c makes it darn simple - but I don't think this statement will hold true for a while: "most people will go to 12c very soon"

Sasha Splinter said...

I share Your doubts ))) And one more thing. If REST is so obviously good, but mod_plsql is so obviously bad, why Oracle still develops WebTier product, that contains new HTTP and new mod_plsql again (i'm about 12 version)?

Juergen Schuster said...

Great post, thanks!

Martin Børge Nielsen said...

Hi Dimitri

How do you plan to have the 2 sets of static files under "/i/" co-existing for 4.2 and 5.0 ?
I assume they are served by the Apache server.

P.s. Thanks for all the great blogs here in Jan. 2015.


Dimitri Gielis said...

Hi Martin,

Thanks for the kind words.

Concerning the multiple images folder, I create an /i50/ directory and reference that.
You have a couple of options to reference it:
-) write some rewrite rules in Apache
e.g. when using different url
-) specify the /i50/ in Image Prefix in the User Interface section of your application.
-) use multiple ORDS with their own paths
-) run the reset_image_prefix.sql in your apex/utilities folder
-) ...

Hope that helps,

Pavel G said...

Great post, thanks!

Are using of new REST Data Service 3 necessary for APEX 5?

Sasha Splinter said...

Dimitri, You said "I'm using Apache as a reverse proxy in front of Tomcat".

Would You be so kind as to share Your proxy conf? the matter is that my conf seems to be wrong, so getting immediately redirects to
Here You are my apache proxy conf:

ProxyPass /oblako/ ajp://localhost:8009/ords/
ProxyPassReverse /oblako/ ajp://localhost:8009/ords/
ProxyPass /i/ ajp://localhost:8009/i/
ProxyPassReverse /i/ ajp://localhost:8009/i/

In the same time the following works perfect:

ProxyPass /ords/ ajp://localhost:8009/ords/
ProxyPassReverse /ords/ ajp://localhost:8009/ords/
ProxyPass /i/ ajp://localhost:8009/i/
ProxyPassReverse /i/ ajp://localhost:8009/i/

Marco Gralike said...


maybe the following helps regarding setting up a Apache proxy

Dietmar Aust said...

Hi Martin, Dimitri,

since APEX 4.2.2 the handling of the image prefix has changed:

... and it is specifically designed for that purpose.

Just set the global image directory to /42x/ or /50x/ in your respective APEX installation globally.

When you leave the image prefix empty in your application, it will pick up the global setting, i.e. /i42x/ or /i50x/. When you export the application, the image prefix will be exported as NULL and thus pick up the instance default in your target instance.

Works nicely.

Still, when you are using a custom virtual directory you will still have to manage that using rewrite rules or virtual hosts ... or you can actually use the new static files in the workspace ... nicely cached.


Neeraj Sarathe said...

Hello Sir/Madam,

Please tell me, Is it possible to revert back oracle apex 5.0.4 to apex 4.0.2??
If its possible then send me related links & documents.


Dimitri Gielis said...

Hi Neeraj,

You can go back to a previous version of APEX.
You find it in the documentation here:

Hope that helps.