User Tools

Site Tools


databases:install_apex_with_glassfish

Install APEX with Glassfish on Linux

This page details how to install APEX 4.2.2 (Oracle Application Express) on a Linux Server running Oracle Database 11gR2.

In this guide, we use the open source version of Oracle's Glassfish application server.

Prerequisites

You must have a CentOS machine already set up in accordance with the the Install CentOS 6 guide and then set up the Oracle Database server in accordance with the “Install Oracle 11gR2” guide.

Prepare Filesystem

We have to have a home for the APEX files and for the Glassfish files so we create /oracle/apex and /oracle/glassfish.

lvcreate -L 4G datavg -n glassfish
lvcreate -L 4G datavg -n apex
mkfs -t ext4 /dev/mapper/datavg-apex
mkfs -t ext4 /dev/mapper/datavg-glassfish

mkdir /oracle/apex
mkdir /oracle/glassfish
chown oracle:oinstall /oracle/apex
chown oracle:oinstall /oracle/glassfish

FILENAME=/etc/fstab
echo '/dev/mapper/datavg-apex /oracle/apex                     ext4    defaults        1 2' >> $FILENAME
echo '/dev/mapper/datavg-glassfish /oracle/glassfish           ext4    defaults        1 2' >> $FILENAME

mkdir /oracle/apex/listener
chown -R oracle:oinstall /oracle/apex
chown -R oracle:oinstall /oracle/glassfish
chown root:root /oracle/apex/lost+found
chown root:root /oracle/glassfish/lost+found

Download Installation Files

Having installed Oracle Standard One 11gR2 (11.2.0.3) on a CentOS 6 x86_64 machine, download the following * Oracle APEX (4.2.2 at the time of writing. We got the 'English' only.) [http://www.oracle.com/technetwork/developer-tools/apex/downloads/index.html download] * Oracle APEX Listener (2.0.2 at the time of writing) [http://www.oracle.com/technetwork/developer-tools/apex-listener/downloads/index.html download] * GlassFish Server Open Source Edition (4.0 at the time of writing) [http://glassfish.java.net/download.html download] We assume for this guide that the files are called apex_4.2.2_en.zip, apex_listener.2.0.2.133.14.47.zip and glassfish-4.0.zip.

Assuming that the files have been placed in /tmp, you can use the following command to copy them from the mounted directory.

cp /tmp/glassfish-4.0.zip /oracle/glassfish
chown oracle:oinstall /oracle/glassfish/glassfish-4.0.zip
cp /tmp/apex_listener.2.0.2.133.14.47.zip /oracle/apex/listener
chown oracle:oinstall /oracle/apex/listener/apex_listener.2.0.2.133.14.47.zip
cp /tmp/apex_4.2.2_en.zip /oracle/apex
chown oracle:oinstall /oracle/apex/apex_4.2.2_en.zip

Install Glassfish

Log in as root and then, as oracle, unzip the glassfish zip file. It is important that this is done as the user 'oracle'. First time I tried this, I created a seperate user called 'glassfish'. While the glassfish server worked, I couldn't get APEX to deploy properly because of file permissions (APEX was owned by the user 'oracle'). The solution is to run glassfish as the user 'oracle'.

su - oracle
cd /oracle/glassfish
unzip glassfish-4.0.zip
chown -Rf oracle:oinstall /oracle/glassfish/glassfish4
exit

Now, back as the root user, we want to create an init script that will be used to start glassfish automatically on boot.

rm -f /etc/init.d/glassfish
cat << EOF >> /etc/init.d/glassfish
#!/bin/bash
# description: Glassfish Start Stop Restart
# processname: glassfish
# chkconfig: 234 20 80
JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
GLASSFISH_HOME=/oracle/glassfish/glassfish4/glassfish
GLASSFISH_USER=oracle

case $1 in
start)
echo "Starting Glassfish" >> /var/log/glassfish
su $GLASSFISH_USER -c "sh $GLASSFISH_HOME/bin/asadmin start-domain domain1"
echo "Done" >> /var/log/glassfish
;;
stop)
echo "Stopping Glassfish" >> /var/log/glassfish
su $GLASSFISH_USER -c "sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1"
echo "Done" >> /var/log/glassfish
;;
restart)
echo "Stopping Glassfish" >> /var/log/glassfish
su $GLASSFISH_USER -c "sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1"
echo "Done" >> /var/log/glassfish
echo "Starting Glassfish" >> /var/log/glassfish
su $GLASSFISH_USER -c "sh $GLASSFISH_HOME/bin/asadmin start-domain domain1"
echo "Done" >> /var/log/glassfish
;;
esac
exit 0
EOF


chown root:root /etc/init.d/glassfish
chmod 755 /etc/init.d/glassfish
chkconfig --add glassfish
chkconfig glassfish on

service glassfish start

Now we need to open up the firewall. As we are going to run Glassfish as the non-privilaged user 'oracle', we can't listen on a port lower than 1024. Therefore, we listen on port 8080 and forward port 80 to port 8080. Also, we open up port 4848 so we can access the admin console of Glassfish.

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 4848 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080
service iptables save
service iptables restart

Configure Glassfish

The default page to access stuff is at http://hostname. However, remember that you won't really see anything until you start deploying applications.

The Admin Console is at http://hostname:4848/. However, by default, remote access to this port is disabled. To enable it, you will have to log in locally. Also, before enabling remote access, the first thing to do is set up a password. # Log into the machine as the user oracle on the local console. # Start up Firefox and go to http://localhost:4848. # Click “Domain” on the tree. # Click the Administrator Password tab. # Enter and confirm your password and click Save. # Click “Server (Admin Server)” on the tree. # Click the “Secure Administration…” button and then 'OK' when the pop up appears. # Follow the instructions to return to the login page.

For your information, the first password save will create a file, .asadminpass, in the home directory of the user you are running the service under.

Alternatively, you can set the admin password via the CLI using.

$GLASSFISH_HOME/bin/asadmin change-admin-password

Prep APEX Install Files

su - oracle
cd /oracle/apex
unzip apex_4.2.2_en.zip
cd /oracle/apex/listener
unzip apex_listener.2.0.2.133.14.47.zip

Install APEX

Run the following as the user oracle.Run the following as the user oracle.

PASSWD=put-sys-passwd-here
echo "ALTER SYSTEM SET SHARED_POOL_SIZE='200M' SCOPE=spfile;" | sqlplus sys/${PASSWD}@database as sysdba

Restart database

dbshut
dbstart

Run a preparation script.

sqlplus sys/$PASSWD@database @"$ORACLE_HOME/ctx/admin/defaults/drdefgb.sql"

Install the Full development environment. The following command will take about 20 minutes.

sqlplus sys/$PASSWD@database @"/oracle/apex/apex/apexins.sql SYSAUX SYSAUX TEMP /i/"

FYI * SYSAUX - is the name of the tablespace for the Oracle Application Express application user. * SYSAUX - is the name of the tablespace for the Oracle Application Express files user. * TEMP - is the name of the temporary tablespace or tablespace group. * /i/ - is the virtual directory for Oracle Application Express images. To support future Oracle Application Express upgrades, define the virtual image directory as /i/

Change the admin password

sqlplus sys/$PASSWD@database @"/oracle/apex/apex/@apxchpwd.sql"

Restart the server</code>

Post Install APEX Config

Run the following as the oracle user

PASSWD=put-sys-passwd-here
APEX_PUB_PASSWD="\"Passwd\""
echo "ALTER USER APEX_PUBLIC_USER ACCOUNT UNLOCK;" | sqlplus sys/${PASSWD}@database as sysdba
echo "ALTER USER APEX_PUBLIC_USER IDENTIFIED BY ${APEX_PUB_PASSWD};" | sqlplus sys/${PASSWD}@database as sysdba
echo "CREATE PROFILE APEX_PUBLIC_USER_PROFILE LIMIT PASSWORD_LIFE_TIME UNLIMITED;" | sqlplus sys/${PASSWD}@database as sysdba
echo "ALTER USER APEX_PUBLIC_USER PROFILE APEX_PUBLIC_USER_PROFILE; " | sqlplus sys/${PASSWD}@database as sysdba

Install APEX Listener

cd /oracle/apex/listener/
mkdir /oracle/apex/listener/conf
# Configure APEX Listener
java -jar apex.war configdir /oracle/apex/listener/conf

# We need this line as the original apex server was https://server/pls/htmldb/REPORT_ID. If we don't do this, we will only be able to access https://server/apex/REPORT_ID
mkdir -p /oracle/apex/listener/conf/pls
cp -R apex pls/htmldb
java -jar apex.war

Example output is

#...
#Enter the location to store configuration data:/oracle/apex/listener/conf
#Enter the name of the database server [localhost]:
#Enter the database listen port [1521]:
#Enter 1 to specify the database service name, or 2 to specify the database SID [1]:2
#Enter the database SID [xe]:sidney
#Enter the database user name [APEX_PUBLIC_USER]:
#Enter the database password for APEX_PUBLIC_USER:
#Confirm password:
#Enter 1 to enter passwords for the RESTful ... 3 to skip this step [1]:3
#Enter 1 if you wish to start in standalone mode or 2 to exit [1]:2
java -jar apex.war static /oracle/apex/apex/images

Deploy APEX Listener

# Browse to http://hostname:4848/. If nothing shows run 'service glassfish start' as root. # In the navigation tree, click 'Applications'. # Click the Deploy button. # Click 'Local Packaged File or Directory That Is Accessible from GlassFish Server. # Click Browse Files and find apex.war (In /oracle/apex/listener. Then click 'Choose file' to load it ## Type: Web Application ## Context Root: pls/htmldb (originally we set it to apex but then we realised that the original server used pls/htmldb so we had to use the same) ## Application Name: apex ## Status: Enabled ## Description: Application Express Listener ## Accept all other default settings and click OK. # Click Browse Files and find i.war (In /oracle/apex/listener. Then click 'Choose file' to load it ## Type: Web Application ## Context Root: Clear the Context Root field so that the context root set in the sun-web.xml is used ## Application Name: apex ## Status: Enabled ## Description: Application Express Listener ## Accept all other default settings and click OK.

FYI. If something goes wrong. The server.log file is at

/oracle/glassfish/glassfish4/glassfish/domains/domain1/logs/server.log

You should now be able to log in as the admin at http://hostname/apex/apex_admin

When you log in, you will have to change the password that was set when you ran the 'java -jar apex.war' command.

Once the password has been set, you can also log in at http://hostname/apex/

Default Workspace: INTERNAL
Username: Admin
Password: Whatever

Make APEX Default Page

We want to ensure that if people just browse to the machine 'apex' in a web browser, they get to the APEX page.

Edit the URLs in the HTML file as appropriate.

su - oracle
mv /oracle/glassfish/glassfish4/glassfish/domains/domain1/docroot/index.html /oracle/glassfish/glassfish4/glassfish/domains/domain1/docroot/index.html/index.html.backup
cat << EOF > /oracle/glassfish/glassfish4/glassfish/domains/domain1/docroot/index.html
<!DOCTYPE HTML>
<html lang="en-GB">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="1;url=https://apex.example.com/pls/htmldb/">
        <script type="text/javascript">
            window.location.href = ""
        </script>
        <title>Page Redirection</title>
    </head>
    <body>
        <!-- Note: don't tell people to 'click' the link, just tell them that it is a link. -->
        If you are not redirected automatically, follow the <a href='https://apex.example.com/pls/htmldb/'>link to example</a>
    </body>
</html>
EOF

Setup SSL

Finally, you will need to setup the SSL certificate for apex.example.com (if you are replacing the current apex server). See Setup APEX SSL

databases/install_apex_with_glassfish.txt · Last modified: by 127.0.0.1