Let's get right to it, starting with Oracle XE.
Installing Oracle XE
This is actually quite straightforward, assuming you have followed the prerequisite steps in part one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install Oracle XE 11g on CentOS | |
# assumes the installation file has already been copied to /u01/download | |
# create Oracle user and groups | |
groupadd oinstall | |
groupadd dba | |
useradd -g oinstall -G dba,oinstall oracle | |
chown -R oracle:oinstall /u01 | |
# change the password | |
passwd oracle | |
# unzip the installation files | |
cd /u01/download | |
unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip | |
cd /u01/download/Disk1 | |
# run installation | |
rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm | |
# run the configuration script | |
# accept the defaults (unless you know what you are doing!) | |
/etc/init.d/oracle-xe configure | |
As part of the installation, we created a user called oracle. It is useful to set up the default environment of this user to include the path to the sqlplus executable, so we can start sqlplus from anywhere.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup Oracle environment in bash profile to be able to access sqlplus from anywhere | |
# http://stackoverflow.com/questions/16823591/how-to-add-lines-to-end-of-file-linux | |
# this adds the Oracle environment variables to the "oracle" user, but you may also want to add it to root or any other users | |
echo '. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh' >> /home/oracle/.bash_profile |
Now, let's log in to Oracle as SYS and check that everything looks OK:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initial test of Oracle XE database after install | |
# become the "oracle" user | |
su - oracle | |
# connect to database | |
sqlplus /nolog | |
connect sys as sysdba | |
-- basic query to see stuff working | |
select sysdate, sys_context('userenv', 'server_host') from dual; | |
-- check components and versions | |
select comp_id, version, status | |
from dba_registry; | |
-- check users | |
select username, account_status | |
from dba_users | |
order by 1; |
At this point you have an Oracle XE instance running, which also includes Apex 4.0 and the Embedded PL/SQL Gateway (EPG) running on port 8080. That is nice, but it's an old Apex version and the EPG web server is not really suited for heavy usage. We want the latest Apex version, and we want to use ORDS. Read on...
Installing Java
ORDS and Tomcat are both Java applications, so we need to install Java. Actually, we need the Java JDK (Java Development Kit), as opposed to just the Java JRE (Java Runtime Environment). There may already be something called the OpenJDK on the CentOS server, but we want the Oracle-supplied JDK, so let's remove OpenJDK and install the JDK that we downloaded from Oracle:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install Oracle Java JDK | |
# see http://stackoverflow.com/questions/20901442/how-to-install-jdk-in-centos | |
# remove OpenJDK | |
yum remove java* | |
# assume .rpm file is already copied to /u01/download | |
cd /u01/download | |
rpm -ivh jdk-7u79-linux-x64.rpm | |
# see the java_env.sh script for how to add the Java environment to the bash profile | |
# check the java version installed | |
java -version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup Java environment in bash profile to be able to access java from anywhere | |
# http://stackoverflow.com/questions/16823591/how-to-add-lines-to-end-of-file-linux | |
# http://www.davidghedini.com/pg/entry/install_tomcat_7_on_centos | |
echo "JAVA_HOME=/usr/java/latest" >> /root/.bash_profile | |
echo "export JAVA_HOME" >> /root/.bash_profile | |
echo "PATH=$JAVA_HOME/bin:$PATH" >> /root/.bash_profile | |
echo "export PATH" >> /root/.bash_profile | |
Installing Tomcat
To install Tomcat, we will download the installation file directly to the server using the wget command, and then unzip it. Create a tomcat user to run the tomcat process.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download and install Tomcat | |
cd /u01/download | |
# see https://tomcat.apache.org/download-70.cgi for latest version | |
wget "http://www.eu.apache.org/dist/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0.64.zip" | |
# copy file and unzip it | |
cp apache-tomcat-7.0.64.zip /usr/share/apache-tomcat-7.0.64.zip | |
cd /usr/share | |
mkdir tomcat7 | |
unzip apache-tomcat-7.0.64.zip -d tomcat7 | |
# make a symbolic link so we can reference the latest version using /latest instead of a specific version | |
cd /usr/share/tomcat7 | |
ln -s apache-tomcat-7.0.64 latest | |
# create tomcat group and user | |
groupadd tomcat | |
useradd -s /bin/bash -g tomcat tomcat | |
chown -Rf tomcat:tomcat /usr/share/tomcat7/apache-tomcat-7.0.64/ | |
# set password | |
passwd tomcat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Connector port="8090" protocol="HTTP/1.1" | |
connectionTimeout="20000" | |
maxThreads="400" | |
compression="on" | |
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript" | |
redirectPort="8443" | |
server="whateverFakeName" | |
URIEncoding="UTF-8" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# description: Tomcat Start Stop Restart | |
# processname: tomcat | |
# chkconfig: 234 20 80 | |
JAVA_HOME=/usr/java/latest | |
export JAVA_HOME | |
PATH=$JAVA_HOME/bin:$PATH | |
export PATH | |
CATALINA_HOME=/usr/share/tomcat7/latest | |
case $1 in | |
start) | |
/bin/su tomcat $CATALINA_HOME/bin/startup.sh | |
;; | |
stop) | |
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh | |
;; | |
restart) | |
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh | |
/bin/su tomcat $CATALINA_HOME/bin/startup.sh | |
;; | |
esac | |
exit 0 |
Then we need to set up the above script to run automatically if the server is rebooted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assumes you have created a service script at /etc/init.d/tomcat | |
cd /etc/init.d/ | |
# make the script executable | |
chmod 755 tomcat | |
# set to start at boot time | |
chkconfig --add tomcat | |
chkconfig --level 234 tomcat on | |
# verify it | |
chkconfig --list tomcat | |
# start tomcat | |
service tomcat start | |
# note: this gave error "Cannot find /usr/share/tomcat7/latest/bin/catalina.sh | |
# The file is absent or does not have execute permission" | |
# see http://louis-sawtell.com/content/tomcat-cannot-find-bincatalinash | |
cd /usr/share/tomcat7/latest/bin | |
chmod +x *.sh | |
chmod +x *.jar | |
# stop tomcat | |
service tomcat stop | |
# restart tomcat | |
service tomcat restart | |
# check logfile and look for any errors | |
cat /usr/share/tomcat7/latest/logs/catalina.out |
Installing ORDS
The Oracle Rest Data Services (ORDS) installation consists of unzipping the installation file, running the configuration to specify database details, and then copying the ords.war file into the Tomcat webapps folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install Oracle Rest Data Services (ORDS) | |
# assumes you have already downloaded ORDS from the Oracle website | |
# and copied the ORDS zip file to the server | |
# unzip the files, and move them into a dedicated directory | |
cd /u01/download | |
mkdir ords210 | |
unzip ords.2.0.10.289.08.09.zip -d ords210 | |
mv /u01/download/ords210 /u01/ords | |
# Run the ORDS configuration before deployment | |
cd /u01/ords | |
java -jar ords.war | |
# the ORDS configuration "wizard" will now start | |
# when prompted for ORDS configuration directory, enter /u01/ords/config | |
# then provide the necessary connection info (server, port, sid, passwords, etc) | |
# the values get stored in /u01/ords/config/defaults.xml and may be modified there | |
# IMPORTANT: "RESTful Services" is required by Apex 5, | |
# so enable this by specifying passwords for the APEX_LISTENER and APEX_REST_PUBLIC_USER when prompted | |
# for a DEV environment, open the config file and set "debug.printDebugToScreen" to "true" to get detailed errors on screen | |
# for a production environment, this setting should be left as "false" | |
# the "tomcat" user (created as part of Tomcat install) needs write access to the /config/ folder | |
chown -R tomcat:tomcat /u01/ords/config | |
# copy the .war into the webapps folder | |
cp ords.war /usr/share/tomcat7/latest/webapps/ords.war | |
# restart Tomcat to deploy the .war | |
service tomcat restart | |
# if using Tomcat standalone, copy the Apex image files to Tomcat "i" folder | |
# NOTE: no need to do this if using Apache as web server in front of Tomcat | |
# cp -r /u01/download/apex/images /usr/share/tomcat7/latest/webapps/i/ |
Installing Apache
The last step in completing our web stack is to install the Apache HTTP server and place it "in front of" Tomcat. This means that all requests to the server go to Apache first. Requests for static files (images, Javascript and CSS) is served directly by Apache. Requests for dynamic content (ie the actual HTML pages generated by Apex via ORDS) is served by Tomcat, using Apache as a proxy.
Installing Apache is very straightforward:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install Apache on CentOS | |
# see https://www.linode.com/docs/websites/apache/apache-2-web-server-on-centos-6 | |
# install | |
yum install httpd -y | |
# start the server | |
service httpd start | |
# set to start automatically on boot | |
chkconfig httpd on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# customized Apache configuration | |
# add this to the end of /etc/httpd/conf/httpd.conf | |
# or put it in a separate file such as /etc/httpd/conf.d/apex.conf | |
# disable sensitive version info | |
ServerSignature Off | |
ServerTokens Prod | |
# standard alias for Apex image files | |
Alias /i/ "/var/www/apex/images/" | |
# forward dynamic (ORDS) requests to Tomcat | |
<VirtualHost *:80> | |
ProxyRequests Off | |
ProxyPreserveHost On | |
<Proxy *> | |
Order deny,allow | |
Allow from all | |
</Proxy> | |
ProxyPass /ords ajp://localhost:8009/ords | |
ProxyPassReverse /ords ajp://localhost:8009/ords | |
</VirtualHost> | |
# enable compression of static content | |
<IfModule mod_deflate.c> | |
SetOutputFilter DEFLATE | |
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript | |
</IfModule> | |
# enable client caching of static content | |
<IfModule mod_expires.c> | |
ExpiresActive On | |
ExpiresByType image/gif "access plus 7 days" | |
ExpiresByType image/jpeg "access plus 7 days" | |
ExpiresByType image/png "access plus 7 days" | |
ExpiresByType text/css "access plus 7 days" | |
ExpiresByType text/javascript "access plus 7 days" | |
ExpiresByType application/javascript "access plus 7 days" | |
ExpiresByType application/x-javascript "access plus 7 days" | |
</IfModule> | |
Installing (upgrading to) latest Apex version
Finally, we need to upgrade the Apex installation that came bundled with Oracle XE to the latest and greatest Apex version (version 5.0 at the time of writing).
This is done by unzipping the Apex installation file, then running the Apex installation script via sqlplus. There are two different Apex installations to choose from: Either a full installation that includes the Application Builder (suitable for a development environment), and a more lightweight and secure "runtime-only" installation (suitable for test and production environments). Running the full installation on the standard 1GB server at DigitalOcean should take about 12-15 minutes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install (or upgrade) Apex on Oracle XE on CentOS | |
# change to the "oracle" user (created as part of XE installation) | |
su - oracle | |
# assumes you have already copied Apex installation file to server | |
cd /u01/download | |
unzip apex_5.0.1_en.zip | |
cd apex | |
# start sqlplus and run the installation script | |
sqlplus /nolog | |
# connect sys as sysdba | |
# -- run the following for a full installation (including the Application Builder) | |
# @apexins.sql SYSAUX SYSAUX TEMP /i/ | |
# -- run the following for a runtime-only installation (for production environments) | |
# @apxrtins.sql SYSAUX SYSAUX TEMP /i/ | |
# check the installation log (last 200 lines) | |
tail -n 200 *.log | |
# rename the folder so we can have multiple versions downloaded (apex501, apex502, apex60, etc) | |
cd /u01/download/ | |
mv apex apex501 | |
# now remember to copy the Apex images files into the web server "/i/" folder |
We also need to make sure the apex_public_user schema is unlocked (and stays that way!).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- run as SYS | |
-- set up service profile to avoid expiring passwords | |
create profile web_service_profile | |
limit password_life_time unlimited; | |
alter user apex_public_user profile web_service_profile; | |
alter user apex_listener profile web_service_profile; | |
alter user apex_rest_public_user profile web_service_profile; | |
-- unlock the apex public user and set a password | |
alter user apex_public_user account unlock; | |
alter user apex_public_user identified by pick_a_password; | |
-- remove previous versions of Apex, if desired | |
-- drop user apex_040000 cascade; | |
-- drop user apex_040100 cascade; | |
-- drop user apex_040200 cascade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copy the Apex image files to corresponding Apache web folder | |
# assumes you have unzipped the Apex files already | |
mkdir -p /var/www/apex/images | |
cp -rf /u01/download/apex501/images/ /var/www/apex | |
# note: make sure you have set up an Apache alias "/i/" to the /images folder above |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# configure ORDS RESTful Services for Apex | |
# see https://docs.oracle.com/cd/E59726_01/install.50/e39144/listener.htm#HTMIG29335 | |
su - oracle | |
cd /u01/download/apex501 | |
sqlplus /nolog | |
connect sys as sysdba | |
@apex_rest_config.sql |
http://servername/ords/apex
If everything works, you should see this familiar page:
Did it work? Great, now enjoy Apex 5! But wait, we are not fully done yet! In the next part of this series, I will describe various additional configuration that you should perform for a more secure and scalable server.
Stay tuned!