# APEX, ORDS, and TOMCAT INSTALLATION

In this guide, I'll walk you through the installation process of Oracle Application Express (APEX), Oracle REST Data Services (ORDS), and Tomcat in Windows.

Following a step-by-step approach, we'll ensure a clean setup for all components.

## Prerequisites

### Oracle Database Installation

* Make sure Java is installed on your machine. if not install same (preferably &gt;= **jdk17**)
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707293028076/e2ee2206-585e-495d-a68a-6fbf7dc50212.png align="center")
    
* Ensure Oracle DB is installed (Version: **19c** in our case).
    
* Check Oracle DB version:
    
    ```sql
    SELECT banner FROM v$version;
    
    Output
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    ```
    
* Install Any IDE of your choice such as **SQL Developer** or **TOAD**.
    
* Data modeling software (**optional**). SQL Developer can be used for ERD visualization.
    

### Uninstall APEX (if already installed) :

* ```sql
    -- Check APEX Version from APEX_RELEASE Table:
    SELECT * FROM APEX_RELEASE;
    
    -- Check APEX Installation Status from DBA_REGISTRY Table:
    -- If APEX is installed, you should see a row with COMP_ID as 'APEX'
    
    SELECT * FROM DBA_REGISTRY WHERE COMP_ID = 'APEX';
    ```
    
* If you see any row indicating APEX is already installed, change the working directory to APEX using `cd apex`. Start SQL\*Plus and connect to the pluggable database where APEX is installed as SYS, specifying the SYSDBA role, and execute `@apxremov.sql`. Then exit SQL\*Plus and reconnect before attempting a new install using `apexins.sql`.
    

### [Fresh APEX Installation:](https://apex.oracle.com/en/learn/documentation/)

1. Download and unzip APEX from [Oracle's official website](http://www.oracle.com/technetwork/developer-tools/apex/downloads/index.html).
    
2. This will create a folder named '**apex24\_2**', and you should navigate to the 'apex' folder using `cd apex`.
    
3. Start SQL\*Plus and make sure you connect to your PDB, not the "root" of the container database, since APEX should not be installed there.
    
    ```sql
    
    sqlplus / as sysdba
    
    --create PDB named DEMO
    create pluggable database demo admin user demo_admin identified by <password for pdb> file_name_convert=('pdbseed', 'demo');
    
    -- Chnage container to created DEMP pdb
    ALTER SESSION SET CONTAINER = DEMO;
    
    -- Create APEX tablespace
    create tablespace apex datafile 'E:\app\oradata\ORCL\demo\apex.dbf' size 300m autoextend on next 10m;
    
    -- Install APEX lowcode environment
    @apexins.sql APEX APEX TEMP /i/
    
    Note only for runtime environment run @apxrtins.sql. usually in PROD environment.
    -- Alternatively, utilize the below command:
    sqlplus sys@//localhost:port/pdb as sysdba @apexins sysaux sysaux temp /i/
    ```
    
    **This will take some time**.....  
    
4. Upon execution of the `apexins.sql` or `apxrtins.sql` , a log file generated in the apex directory, adhering to the format `installYYYY-MM-DD_HH24-MI-SS.log`. In the event of a successful installation, the log file will display the message: "***Thank you for installing Oracle APEX. Oracle APEX is installed in the APEX\_240200 schema"***
    
      
    Note that few errors in log does not necessarily indicate a failed installation.  
    
5. **Unlocking the** [**APEX\_PUBLIC\_USER**](https://medium.com/@techtutorsti/apex-public-user-f06073ffa914#:~:text=Configuration%20with%20ORDS%3A%20The%20APEX_PUBLIC_USER,the%20database%20through%20web%20services.) **Account:**
    
    ```sql
    alter user apex_public_user identified by oracle account unlock;
    ```
    
6. Execute `@apxchpwd.sql` to configure and update the instance administrator username and password. Ensure to provide a robust password; otherwise, the script will prompt repeatedly until a strong password is provided and the process is successful.  
    
7. To check instance administrator user (default ADMIN ) details -
    
    ```sql
    select * from APEX_240200.WWV_FLOW_FND_USER;
    ```
    
    <div data-node-type="callout">
    <div data-node-type="callout-emoji">💡</div>
    <div data-node-type="callout-text">Let's take a quick look at the "WWV_FLOW" tables:</div>
    </div>
    
    The "WWV" prefix stands for "Web Warrior Virtual." It's a common naming style in Oracle APEX, used for internal components and objects.
    
    When you install Oracle APEX, a user is created (like APEX\_230200, which can change with different versions). This user holds the "WWV\_FLOW" tables, which store important metadata and runtime data for APEX apps. For example:
    
    * WWV\_FLOW\_USERS: Stores user information for APEX. Example query: SELECT \* FROM APEX\_230200.WWV\_FLOW\_USERS;
        
    * WWV\_FLOW\_SESSION: Keeps track of session details for APEX apps. Example query: SELECT \* FROM APEX\_230200.WWV\_FLOW\_SESSION;
        
    * WWV\_FLOW\_FILES: Manages files related to APEX apps. Example query: SELECT \* FROM APEX\_230200.WWV\_FLOW\_FILES;
        
8. ### APEX Installation Verification
    
    * Check APEX installation:
        
        ```sql
        SELECT * FROM DBA_REGISTRY WHERE COMP_ID = 'APEX';
        If APEX is installed, you should see a row with COMP_ID as 'APEX'.
        ```
        
    * Check APEX release version:
        
        ```sql
        SELECT * FROM APEX_RELEASE;
        ```
        
    * Verify instance administrator user:
        
        ```sql
        SELECT * FROM APEX_240200.WWV_FLOW_FND_USER;
        ```
        
    * Prevent **ADMIN** from changing the password on first login:
        
        ```sql
        UPDATE APEX_240200.WWV_FLOW_FND_USER SET CHANGE_PASSWORD_ON_FIRST_USE='N';
        ```
        
    
    **<mark>Now let's move to ORDS installation.</mark>**
    

### First Uninstall ORDS (if already installed):

### ORDS Installation: ([Official Getting Started](https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/24.4/index.html))

1. Verify if ORDS already installed `ords --version`
    
2. To uninstall ORDS run : `ords uninstall`
    
3. Now download the latest ORDS, unzip it, and navigate to the ords directory using `cd E:\ords\`.
    
4. Add ords bin to the environment PATH; otherwise, you will need to use the absolute path to run ords.
    
5. Create a system environment variable **ORDS\_CONFIG** and assign it a folder that will be used for ORDS configuration (ensure this folder is not inside ords directory). for use ORDS\_CONFIG = E:\\ord\_config
    
6. Lets install in standalone mode ( interactively) : `ords install`  
    **Note : during installation in option #9 for apex static file path give //(double slash in path separator) insted of /(single slash) else / will not be interpreted correctly and merged to a single string.**
    
7. After installation validate the version -`ords --version`
    
8. `SELECT * FROM DBA_USERS WHERE USERNAME LIKE '%ORDS%'`
    
    ORDS\_PUBLIC\_USER  
    ORDS\_METADATA  
    ORDSYS
    
9. To start `ords serve`
    
10. That's it!! You should now be able to login [http://localhost:8080/ords/](http://localhost:8080/ords/)  
    
    The structure of the link to the Oracle APEX Administration Services is as follows: [http://localhost:8080/ords/apex\_admin](http://localhost:8080/ords/apex_admin)  
    
    The structure of the link to the Oracle APEX development environment is as follows: [http://localhost:8080/ords/apex](http://localhost:8080/ords/apex)  
    
    **Workspace:** internal  
    **Username:** admin  
    **Password:** &lt;passwd you had provided&gt;
    
    ![APEX Login Page](https://cdn.hashnode.com/res/hashnode/image/upload/v1680796697102/ef9416cc-060e-43ec-ab56-40a22e3226c8.png?auto=compress,format&format=webp&auto=compress,format&format=webp align="left")
    
11. Now, the challenge is that we need to manually start ORDS using the "*ords serve*" command every time we want to use APEX. To solve this, we should deploy the ords.war file into Tomcat, so ORDS starts automatically when Tomcat initializes during a system reboot. **Let's explore the process of installing and configuring Tomcat for ORDS deployment.**
    
12. Download and set up [Tomcat](https://tomcat.apache.org/download-90.cgi), configuring it to utilize port 8080
    
13. Visit [http://localhost:8080/](http://localhost:8080/) to ensure Apache Tomcat is up and running.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707292753506/dcddaf4b-969b-4535-865e-22393f6f9904.png align="center")
    
14. Copy apex images folder as i **(~\\apex\\images)** to Tomcat webapps folder **(C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\webapps\\i)**
    
15. Copy the **ords.war** file to the Tomcat webapps directory **(~\\webapps)**, and note that you can rename it to any name you choose, but you must use the same name after host:port.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707293173734/c660cc61-ec76-4f54-9419-3cdfeadde7f8.png align="center")
    
16. Restart the ORDS application from the Apache server .
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707293229181/7f75269e-214e-486f-b679-48d1ff6b2356.png align="center")
    
17. Set the system environment variable JAVA\_TOOL\_OPTIONS to -Dconfig.url=E:\\app\\config\_ords -Xms1024M -Xmx1024M (representing the ORDS Config path).
    
18. Modify the Apache Tomcat service startup type to Automatic and reboot the machine. Following this, everything should be operational.
    
19. If a 503 error (Service Unavailable) or ORA-28000 error occurs, unlock the following accounts:
    
    * APEX\_REST\_PUBLIC\_USER
        
    * APEX\_INSTANCE\_ADMIN\_USER (ignore if an error occurs for this user)
        
    * APEX\_PUBLIC\_USER
        
    * APEX\_LISTENER
        
20. Now you can always access Apex at [http://localhost:8080/ords](http://localhost:8080/ords)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707292491998/5c55962d-a82a-46a2-9f15-db0ef2d93b82.png align="center")
    

## Some valuable links for additional information:

* To delve deeper into ORDS installation and configuration, consult the Oracle [Oracle ORDS official Quick Start Guide](https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/23.4/ordig/installing-and-configuring-oracle-rest-data-services.html#GUID-B6661F35-3EE3-4CB3-9379-40D0B8E24635)
    
* For further exploration of ORDS details and resources, visit the [official Oracle Page](https://www.oracle.com/database/technologies/appdev/rest.html) dedicated to ORDS.
    
* If you're interested in installing ORDS on Tomcat for Linux systems (ORDS Version 22.1 onward), you can find guidance [here](https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-installation-on-tomcat-22-onward).
    
* Similarly, for Windows users looking to install ORDS on Tomcat, refer to this resource [here](https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-installation-on-tomcat-windows).
    
* For older version ords install you can refer to [this](https://joelkallman.blogspot.com/2017/05/apex-and-ords-up-and-running-in2-steps.html) or watch this short [video](https://youtu.be/amF01SpNLUo).
    

## FAQ

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>How to create a pdb?</strong></div>
</div>

Example : create pluggable database demo admin user demo\_admin identified by &lt;password for pdb&gt; file\_name\_convert=('pdbseed', 'demo');

```sql
SQL> show user con_name
USER is "SYS"

CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
SQL> create pluggable database demo admin user demo_admin identified by <password for pdb> file_name_convert=('pdbseed', 'demo');

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
         4 DEMO                           READ WRITE NO
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>How to create a tablespace?</strong></div>
</div>

Before creating tablespace - check if OMF is enabled for your database,  
`SELECT name, value FROM v$parameter WHERE name = 'db_create_file_dest';`

If the query returns a not null value for 'db\_create\_file\_dest', OMF is enabled,  
`create tablespace apex datafile size 200M autoextend on next 10m maxsize unlimited;`

If it returns a null value for 'db\_create\_file\_dest', OMF is not enabled,  
`create tablespace apex datafile 'E:\app\oradata\ORCL\demo\apex.dbf' size 300m autoextend on next 10m;`

that parameter names and values may vary based on the Oracle Database version and configuration.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>Difference between a Full and runtime apex environment installation?</strong></div>
</div>

Full Development Environment:

Comprehensive Toolset: Equipped with Application Builder, SQL Workshop, and Team Development, empowering developers with robust capabilities for application creation, customization, and collaborative development.

Development Lifecycle Hub: Serves as the central workspace for iterative prototyping, extensive testing, and meticulous debugging, facilitating efficient application development from inception to deployment readiness.

To install the Full Development Environment, execute the following command:

```sql
@apexins.sql tablespace_apex tablespace_files tablespace_temp images
```

Parameters:

* `tablespace_apex`: Name of the tablespace for the Oracle APEX application user.
    
* `tablespace_files`: Name of the tablespace for the Oracle APEX files user.
    
* `tablespace_temp`: Name of the temporary tablespace or tablespace group.
    
* `images`: Virtual directory for Oracle APEX images.
    

Example:

```sql
@apexins.sql SYSAUX SYSAUX TEMP /i/
```

If encountering the error SP2-0310: unable to open file "apexins.sql", exit SQL\*Plus and ensure the working directory is correctly set to the installation file location.

Runtime Environment:

Production Deployment Hub: Exclusively focused on deploying and serving APEX applications to end-users, ensuring seamless user experiences and optimal application performance.

Secure Execution Realm: Stripped of development tools, it prioritizes application security, scalability, and resource optimization, safeguarding production environments while granting controlled access to application functionalities and underlying database assets.

To install the Runtime Environment, execute the following command:

```sql
@apxrtins.sql tablespace_apex tablespace_files tablespace_temp images
```

Parameters:

* `tablespace_apex`: Name of the tablespace for the Oracle APEX application user.
    
* `tablespace_files`: Name of the tablespace for the Oracle APEX files user.
    
* `tablespace_temp`: Name of the temporary tablespace or tablespace group.
    
* `images`: Virtual directory for Oracle APEX images.
    

Example:

```sql
@apxrtins.sql SYSAUX SYSAUX TEMP /i/
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>Which users were created during apex installations?</strong></div>
</div>

During Oracle APEX installation, several database accounts are created to manage different aspects of the application:

* APEX\_240200: Owns the Oracle APEX schema and metadata.
    
* FLOWS\_FILES: Owns the uploaded files within Oracle APEX.
    
* APEX\_PUBLIC\_USER: A minimally privileged account utilized for Oracle APEX configuration with ORDS. In upgrades, it is created if absent.
    
* Additional accounts:
    
    * APEX\_REST\_PUBLIC\_USER: Used for invoking RESTful Services definitions stored in Oracle APEX.
        
    * APEX\_LISTENER: Used to query RESTful Services definitions stored in Oracle APEX.
        

---
