Skip to content

Ingres and Apache on Redhat Enterprise Server

Introduction

Getting web applications to connect to Ingres via Apache on UNIX/Linux can be quite fiddly. Here is a simple guide on the setup steps needed to allow the Ingres PHP, Python and Ruby drivers to work with Apache on RedHat Enterprise Linux, CentOS and Fedora Linux. I’ve also published articles on doing the same for Debian/Ubunutu and Novell SLES/OpenSUSE in the Ingres Community Wiki.

Pre-requisites

It is assumed that you have the following installed:

  • Ingres 2006 or newer ( Ingres >= 9.0.4 )
  • RedHat Enterprise Linux 5.4, CentOS 5.4 and Fedora Linux 11
    • These steps might apply to earlier releases as well
  • Apache 2.2.8
    • The steps here apply to other releases of Apache from 1.3 onwards
    • mod_env – An Apache module which modifies the environment which is passed to CGI scripts and SSI pages

Disabling SELinux

As of writing this Ingres and SELinux do not interact very well. To use Ingres on an SELinux enabled system, SELinux needs to be placed in permissive or disabled modes. To determine the current state of SELinux run the following:

sestatus

sample output:

$ sudo /usr/sbin/sestatus
SELinux status:                 disabled

If the status is enforcing then SELinux must be disabled using the command:

setenforce 0
# or to disable SELinux but log exceptions to policy to /var/log/secure
setenforce Permissive

This will only disable SELinux until the next reboot of the server. To make the change permanent edit /etc/sysconfig/selinux, changing SELINUX to disabled or permissive.

Enabling Ingres for Apache

Any user that connects to Ingres must be a known (defined) user. Specifically a user account must be created within Ingres using CREATE USER .... In the case of web applications served by Apache, Tomcat or whatever, the server process owner is the user that Ingres will initially see. To determine the process owner for Apache execute the following:

ps -fe | grep httpd | grep -v grep

On my system I get the following:

[grant@uksl-grant-rhel64 ~]$ ps -fe | grep httpd | grep -v grep
root      3331     1  0 Apr08 ?        00:00:02 /usr/sbin/httpd
apache   23356  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23357  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23358  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23359  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23360  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23361  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23362  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd
apache   23363  3331  0 Apr11 ?        00:00:00 /usr/sbin/httpd

Which shows two user accounts for Apache. The root account can be ignored since it is a monitor/control process that starts up and shuts down servers as required. The processes run under the apache account will be used to connect to Ingres.

To add apache to Ingres run the following, as the ingres administrator:

sql iidbdb <<EOSQL
create user apache\g
commit\g
\q
EOSQL

You should see something similar to:

ingres@esva-suse:~> sql iidbdb <<EOSQL
> create user apache\g
> commit\g
> \q
> EOSQL
INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation
Ingres Linux Version II 9.2.0 (a64.lnx/143)NPTL login
Tue Apr 13 23:33:18 2010
continue
* Executing . . .
continue
* Executing . . .
continue
* Ingres Version II 9.2.0 (a64.lnx/143)NPTL logout
Tue Apr 13 23:33:18 2010

Now the Ingres DBMS is setup for the Apache web server.

Enabling Apache for Ingres

  1. Edit, (as root), /etc/sysconfig/httpd to include the following:
     II_SYSTEM=/opt/Ingres/IngresII
     LD_LIBRARY_PATH=/opt/Ingres/IngresII/ingres/lib:/opt/Ingres/IngresII/ingres/lib/lp32
     ODBCSYSINI=/opt/Ingres/IngresII/ingres/files
     export II_SYSTEM LD_LIBRARY_PATH ODBCSYSINI

    NoteODBCSYSINI is only needed for the Python driver or applications based on ODBC

  2. Create a new config file (as root), /etc/httpd/conf.d/ingres.conf, adding the following:
  3. PassEnv II_SYSTEM LD_LIBRARY_PATH ODBCSYSINI
  4. Restart apache (as root):
    service httpd restart

Verifying the setup

To see that the environment variables are visible the following code snippets can be executed through Apache through PHP and mod_python.

PHP

  • Code:
    < ?php
      echo "II_SYSTEM is :" .$_SERVER["II_SYSTEM"] . "<br/>\n";
      echo "LD_LIBRARY_PATH is :" .$_SERVER["LD_LIBRARY_PATH"] . "<br />\n";
    ?>
  • Sample Output:
    II_SYSTEM is :/opt/Ingres/IngresII
    LD_LIBRARY_PATH is :/opt/Ingres/IngresII/ingres/lib:/opt/Ingres/IngresII/ingres/lib/lp32
    

Python

  • Code, save as python_env.py:
  • from mod_python import apache
    def environment(req):
        req.content_type = "text/html"
        req.add_common_vars()
        env_vars = req.subprocess_env.copy()
        req.write('< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')
        req.write('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">')
        req.write('<head><title>mod_python.publisher</title></head>')
        req.write('<body>')
        req.write('<h2>Environment Variables</h2>')
        req.write('<table border="1">')
        req.write('<tr><td>%s</td><td>%s</td></tr>' % ("II_SYSTEM", env_vars['II_SYSTEM']))
        req.write('<tr><td>%s</td><td>%s</td></tr>' % ("LD_LIBRARY_PATH", env_vars['LD_LIBRARY_PATH']))
        req.write('</table>')
        req.write('</body>')
        req.write('</html>')
    
  • Ouput from http://localhost/env.py/environment:
     Environment Variables
     II_SYSTEM	/opt/Ingres/II
     LD_LIBRARY_PATH	/lib:/usr/lib:/usr/local/lib:/opt/Ingres/II/ingres/lib:/opt/Ingres/II/ingres/lib/lp32
    

If you have any comments feel free to post them below.

Updated Apr 14, 2010 9:50 to include SELinux information

Popularity: 88% [?]

  • Share/Bookmark

Related Posts

One Comment

  1. nike shox wrote:

    This blog is very good!

    Saturday, June 12, 2010 at 12:04 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
blog comments powered by Disqus