Serving APEX: HTTPD & EPG

The Oracle XE database comes out-of-the box with the Embedded PLSQL Gateway (EPG), which is a robust web server. EPG is an embedded web server to run PLSQL application via mod_plsql. It's simple and straightforward when you are running APEX on an XE database, and you you know the basic DBMS_EPG API for adminstrating the Database Access Descriptors (DADs) for the XML DB HTTP. But practice revealed that EPG is limited and more often it best to put a Apache HTTP server "on top" of EPG, for extended features and simplicity.

Configure EPG DAD settings

By default, leave the EPG HTTP port to 8080. Check the current port by connecting to sqlplus as sys and execute: select DBMS_XDB.GETHTTPPORT() from dual;

At this point, you can access you application at: http://mydomain.com:8080/epg_dad

The epg_dad value is automatically set during the APEX installation, and it's value is apex with the path /apex. So your application would be typically accessed from http://mydomain.com/apex

You can change the DAD path value and the default page with the following procedure (example for using /blog and application 100:1 as a default):

begin
— Remap the default APEX URL path
sys.dbms_epg.map_dad(dad_name => 'APEX', path => '/blog/*');
commit;
end;

 

— Set default application
sys.dbms_epg.set_dad_attribute(dad_name => 'APEX',
attr_name => 'default-page',
attr_value => 'f?p=100:1:0'); — 100 is your application id, default is 4550
commit;
end;

Configure the HTTPD server

Reverse Proxy port 8080 to 80

Almost every Linux installation comes with the HTTPD server installed.  Before starting the HTTPD server, edit httpd.conf file, usually located in etc/httpd/conf. Add the following lines at the end of httpd.conf:

<Location /apex>

  Options None
  Order allow,deny
  allow from all
                   
  ProxyPass  http://localhost:8080/apex
  ProxyPassReverse  http://localhost:8080/apex


 </Location>

This configuration with "Reverse Proxy" the default EPG application homepage (http://localhost:8080/apex) to the default HTTPD homepage (http://localhost), that runs implicitly on port 80. So, with the HTTPD server started, accessing the URL http://localhost:8080/apex will proxy to http://localhost/apex.

Create an alias for the images folder

With the HTTPD server enabled, the APEX images folder, that has the alias /i, will not be accesible, because now, with the reverse proxy, all the resources use the port 80, not EPG's 8080:

Add this to the httpd.conf to create a new alias for the APEX images folder:

Alias /i/ /usr/lib/oracle/xe/app/oracle/product/10.2.0/apex/images/
<Directory "/usr/lib/oracle/xe/app/oracle/product/10.2.0/apex/images/">

  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
               
  <IfModule mod_expires.c>
    ExpiresActive    On
    ExpiresDefault    "access plus 1 month"
  </IfModule>
         
  ### Extra file types that are compressed
  <IfModule mod_deflate.c>
    AddOutputFilterByType   DEFLATE text/css
    AddOutputFilterByType   DEFLATE application/x-javascript
    AddOutputFilterByType   DEFLATE application/xhtml+xml
    AddOutputFilterByType   DEFLATE application/xml
    AddOutputFilterByType   DEFLATE text/x-component
  </IfModule>
                                 
</Directory>

Use .htaccess redirects for the homepage

Use the .htaccess file to set up a proper start page for you APEX application, using the mod_rewrite Apache module:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^$uri\.$tld$ [NC]
RewriteRule ^(.*)$ http://www.$apexninjas$1 [R=301,L]

RewriteRule ^index.html$ /blog/ [NC,L]
– The RewriteEngine On directive enables the runtime rewriting engine.

RewriteCond %{HTTP_HOST} ^$uri\.$tld$ [NC]
RewriteRule ^(.*)$ http://www.$apexninjas$1 [R=301,L]

permanently redirects the users to access the site with www prefix

RewriteRule ^index.html$ /apex/ [NC,L] 

– redirects index.html to the /apex page, set as a homepage by the EPG DAD settings. A blank index.html file must exist in the httpdocs host folder, in order for the redirection to work. By default, when accessing http://www.mydomain.com/, HTTPD server will try to load the index.html file located in the root web folder, and the .htaccess rewrite rule will redirect to http://www.mydomain.com/apex.

 

 

 

Leave a Reply