/ APEX

Oracle Database XE, APEX, ORDS, Tomcat and httpd on CentOS 7: all-in-one guide - part two

This is the second part of the series of blog posts dedicated to tell you in detail how to organize a usual production-like environment for APEX. In this part we are going to sort out the installation and configuration process of Oracle Database XE, ORDS and APEX itself. This instruction assumes you prepared your system following the instructions from the part one of this guide.

Let's go straight to the point starting with the downloading the software to our server.

Downloading the software

The first thing to do here is to download the software from Oracle Technology Network (or OTN):

You have to have an account and accept the licence agreement before you can start to download the stuff.

In case you have downloaded all the the software on your desktop computer, you will need to upload it to your server. It could be done using an SCP-client, for intance pscp or WinSCP if you're a Windows user.

After everything is done we are assuming all the Oracle software is on your server in the root user home directory, which is usually /root.

Installation of Oracle Database 11g XE

This is quite an easy thing to do when you followed the previous steps. To install the RDBMS, just run the following commands:

cd /root
unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
yum localinstall oracle-xe-11.2.0-1.0.x86_64.rpm -y

Note that I used yum to install a local package instead of rpm. This will enable us to use all the power of yum in the future if needed (for example, to remove the package with dependencies).

The user oracle and the group dba are created during the package installation, so we do not need to create them explicitly. But if you like, you can set a password for this user by invoking passwd oracle command. This user is the owner of the /u01 directory where the Oracle Database is located and this must stay unchanged. Also it is good to set up a default environment for this user:

mkdir -p /home/oracle
cp -a /etc/skel/. /home/oracle/
chown -R oracle:dba /home/oracle

Now when the package is installed and the user is set up, you need to run the initial database configuration script:

/etc/init.d/oracle-xe configure

And answer the questions prompted. Note that you should specify 0 as the HTTP port that will be used for Application Express (in the first question), because this is a configuration property of Embedded PL/SQL Gateway which we are not going to use.

Note that CentOS 7 uses systemd instead of sysconfig to run the system services, and that is why you could need to run systemctl enable oracle-xe if notice that the Oracle Database does not start at the system startup. You should also stop and start the oracle-xe service using systemctl instead of using lsnrctl command. Otherwise, you are risking to find yourself with the listener not working properly.

Now it is a good idea to set up Oracle environment variables in order to make users be able to use sqlplus from anywhere:

. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
echo '# setting oracle environment variables' >> /etc/profile.d/oracle_env.sh
echo '. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh' >> /etc/profile.d/oracle_env.sh

And we are ready to log into the database and check if everything is good:

rlwrap sqlplus /nolog
-- connect to the database
SQL> connect sys as sysdba

-- basic query to check if everything works
SQL> select * from dual;
    
-- check components and their versions
SQL> select comp_id, version, status from dba_registry;
    
SQL> exit

That is it! By now we have succesfully installed the XE instance and it is up and running.

Installation of the latest version of APEX

Installation process of the latest version of Oracle Application Express (APEX) consists of deinstalling of the previous version, unzipping the downloaded APEX archive, running a few installation scripts and then copying static files to the web server directory.

Deinstallation of pre-installed version of APEX

Since we are configuring a fresh install, let's first totally get rid of the one which is preinstalled with Database XE, for this change your directory to $ORACLE_HOME/apex, which should be /u01/app/oracle/product/11.2.0/xe/apex if you followed the previous steps, and then run the uninstallation script:

cd /u01/app/oracle/product/11.2.0/xe/apex
rlwrap sqlplus /nolog

-- connect to the database
SQL> connect sys as sysdba

-- uninstall the preinstalled version of APEX
SQL> @apxremov.sql

-- you must exit from sqlplus after uninstall is complete
SQL> exit

Note that we could just drop user APEX_040000 to uninstall the previous version of APEX, but running the unistallation script is preferrable for a fresh install, because it also deletes the unneeded static files from the database.

Installation of current version of APEX

Now we are ready to get started with the current version. Change your directory back to /root, unzip the APEX archive and make the user oracle the owner of the directory:

cd /root
mkdir -p /u01/apex
unzip apex_18.1_en.zip -d /u01/
chown -R oracle:dba /u01/apex

Note that we will be installing the full development environment of APEX. This could be converted to a runtime only environment if needed. Refer to the official documentation for this. The full environment should be used only when the Application Builder is needed. On a production environment it is recommended to choose runtime only.

From the APEX new home directory connect to the database as sysdba and run the installation scripts (we will be using SYSAUX schema for APEX metadata):

cd /u01/apex
rlwrap sqlplus /nolog

-- connect to the database
SQL> connect sys as sysdba

-- installing a full development environment
SQL> @apexins.sql SYSAUX SYSAUX TEMP /i/
   
-- you will be disconnected after APEX is installed
rlwrap sqlplus /nolog
-- connect to the database again
SQL> connect sys as sysdba
    
-- creating an instance administrator user and setting a password to them
SQL> @apxchpwd.sql
    
-- configure "RESTful Services" (needed to ORDS to serve workspaces and applications static files)
SQL> @apex_rest_config.sql

-- disable embedded PL/SQL gateways
SQL> exec dbms_xdb.sethttpport(0);
SQL> exec dbms_xdb.setftpport(0);

-- unlocking and setting up APEX public user, this is needed by ORDS to connect to APEX engine
SQL> alter user apex_public_user account unlock;
SQL> alter user apex_public_user identified by "APEX_PUBLIC_USER";

-- now disconnect from the database
SQL> exit

Then we need to copy APEX static files (images, stylesheets, js files and so on) to the web server directory:

mkdir -p /var/www/apex/images
cp -a /u01/apex/images/. /var/www/apex/images

Now we finished with the APEX installation.

Installation of ORDS

The Oracle Rest Data Services (ORDS) installation consists of unzipping the downloaded archive, running the configuration command, and then deploying the ords.war file into the Tomcat webapps folder.

Change back your directory to /root and unzip the ORDS archive:

cd /root
mkdir -p /u01/ords
unzip ords.18.1.1.95.1251.zip -d /u01/ords

Run the ORDS configuration command before deployment. Choose the advanced mode - in this case the installation process will be interactive:

cd /u01/ords
java -jar ords.war install advanced

When prompted for ORDS configuration directory (the first question), enter config. Then provide the connection info (you can leave almost everything by default, just specify XE for the service name).

Note that "RESTful Services" is required by APEX 5 and above, so enable this by specifying passwords for the APEX_LISTENER and APEX_REST_PUBLIC_USER when prompted

After the configuration is completed, the values are saved in /u01/ords/config/defaults.xml file and may be modified there.

The Tomcat user (created as part of Tomcat install) must have write access to the /config/ folder:

chown -R tomcat:tomcat /u01/ords/config

Now it's high time to deploy ORDS to Tomcat. Copy the ords.war into the Tomcat webapps directory for this (and we will restart the Tomcat service later):

cp -a /u01/ords/ords.war /usr/share/tomcat/webapps/

Done! We succeded in installing of ORDS and deploying it to Tomcat. Only one step is left.

Configuration of Apache httpd to map HTTP-requests to ORDS

The last, but not the least step in this part of the guide is to configure Apache httpd to map HTTP-requests to ORDS application, powered by Tomcat, when needed.

For this, add a custom httpd configuration file. By default, every .conf file placed in the etc/httpd/conf.d/ directory is read by httpd as an additional configuration file to the main /etc/httpd/conf/httpd.conf config file.

Note that these additional config files are read and processed by httpd in alphabetical order, so name your custom config accordingly if you use multiple config files.

So let's create the 10-apex.conf file in the etc/httpd/conf.d/ directory with the contents as below:

# additional apache httpd configuration for apex requests proxying
# add this to the end of /etc/httpd/conf/httpd.conf
# or put it in a separate file such as /etc/httpd/conf.d/10-apex.conf

# forward ORDS requests to tomcat
<VirtualHost *:80>
    # uncomment the lines below if you plan to serve different domains 
    # on this web server, don't forget to change the domain name
    # ServerName yourdomain.tld
    # ServerAlias www.yourdomain.tld
    
    # alias for apex image files
    Alias "/i" "/var/www/apex/images/"

    # uncomment the line below if you want 
    # to redirect traffic to ORDS from root path
    # RedirectMatch permanent "^/$" "/ords"

    # proxy ORDS requests to tomcat
    ProxyRequests off
    <Location "/ords">
        ProxyPass "ajp://localhost:8009/ords"
        ProxyPassReverse "ajp://localhost:8009/ords"
    </Location>
</VirtualHost>

Now you are ready to save the configuration file and restart the services.

Restarting the services

In order for changes to take effect, we need to restart the services:

systemctl restart httpd
systemctl restart tomcat

And finally, you're ready to access APEX from your web browser using a link like http://yourdomain.tld/ords (or http://yourdomain.tld in case you switched on redirection), where yourdomain.tld is the domain name or the IP-address of your server.

In case you're facing the situation when ORDS doesn't map APEX application and workspace static files properly after its installation (I mean, APEX engine static files worked fine, but images, style sheets and other files from your applications generate the 404 not found error), try validating the ORDS install (and then restart the tomcat service):

cd /usr/share/tomcat/webapps/
java -jar ords.war validate

Next Chapters

My congratulations! If you achieved this point, it means all the mandatory things are set up and should be running nicely. The next, final chapter of this guide will be covering additional steps to improve users experience and security of the installation, but all the further actions are not required for the installation.

Here is the link for your convenience:

Previous Chapters

In case you missed some previous steps, please, use the following links to catch up:

Hope this post will be helpful for you. Be free to leave your comments if you have some advice how to improve the guide or if you found a mistake!

Oracle Database XE, APEX, ORDS, Tomcat and httpd on CentOS 7: all-in-one guide - part two
Share this

Subscribe to SELECT BLOG FROM DUAL