Installing Oracle Database XE in CentOS 7

Posted by Jose Estudillo on December 24, 2014

Installing Oracle Database XE in CentOS 7

Getting the binaries

The binaries can be found in the link Oracle Database XE

At the time of this writing the name of the file is oracle-xe-11.2.0-1.0.x86_64.rpm.zip in linux this can be extracted using:

unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip

Supposing the file have been extracted to /tmp the rpm file will be at /tmp/Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm

#run as super user, su/sudo
rpm -Uvh oracle-xe-11.2.0-1.0.x86_64.rpm 

Output:

Preparing...                          ################################# [100%]
Updating / installing...
   1:oracle-xe-11.2.0-1.0             ################################# [100%]
Executing post-install steps...
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `echo ~(unknown)'
You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.

Notice that despite the post-install script errors the installation is successful. I haven’t done much research about this yet.

After installing the app run:

/etc/init.d/oracle-xe configure #run as super user

Oracle Database XE has a webapp associated to it, be default the offered port is 8080 but I will use 11521 to avoid conflict with other applications. For the database listener, I’ll keep 1521.

Output:

[root@localhost Disk1]# /etc/init.d/oracle-xe configure

Oracle Database 11g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 11g Express 
Edition.  The following questions will determine whether the database should 
be starting upon system boot, the ports it will use, and the passwords that 
will be used for database accounts.  Press <Enter> to accept the defaults. 
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:11521

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of 
different passwords for each database account.  This can be done after 
initial configuration:
Confirm the password:

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y

Starting Oracle Net Listener...Done
Configuring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.

Managing the service

The service file is located in /etc/init.d/oracle-xe and be started / stopped using:

    
service oracle-xe start / service oracle-xe stop

Opening Ports for external access

firewall-cmd --permanent --zone=public --add-port=11521/tcp
firewall-cmd --permanent --zone=public --add-port=1521/tcp
firewall-cmd --reload

First use

Assuming we are using the same box to access to the webapp, we could use localhost:11521 and login as SYSTEM. You’ll notice that even typing the right password, the login won’t be successful, just cancel the login, and you will be redirected to a different URL, this only happens the first time.

Creating a workspace

Once in APEX localhost:11521 go to home -> Application express and create a workspace (Application express workspace it will be the name of the workspace)

creating oracle workspace

then connect to it using the interface next to the previous one to access to the newly created workspace

log into workspace

Connecting from Java

To connect from Java the oracle database driver is required, the oracle drivers are not hosted in Maven, so the easiest way to get it is from:

/u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar

To install one the drives to make it accessible from Maven check this. With Oracle driver added to the classpath, the connection URL for this example would look as follows:

jdbc:oracle:thin:@localhost:1521:xe

And very quick chunk of code to test the connection:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "dbuser", "YOUR_PASSWORD");
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT 1 FROM Dual");
if(resultSet.next()) {
    System.out.println("Success");
}