Results 1 to 5 of 5

Thread: setting Apache2 environment variables

  1. #1
    cwrightrkkengineerscom NNTP User

    Default setting Apache2 environment variables

    I've successfully install oci8 so I can code php to access Oracle databases on my opensuse 10.3 server with apache2 and php5. One requirement is to set the variable LD_LIBRARY_PATH. I set it to /opt/oracle/instantclient_10_2 from the command line by typing:
    LD_LIBRARY_PATH = /opt/oracle/instantclient_10_2
    EXPORT LD_LIBRARY_PATH

    I then restart apache2. All is well - oracle database links are fine.

    However if I restart the server, the oracle stuff won't work until I reset LD_LIBRARY_PATH. I stop apache2, set the variable again and restart apache2. This must be easier!

    I found a thread that instructed me to enable env for apache2. I did this through yast, network services, http server, server modules. This changed the line APACHE_MODULES to include 'env'. Then I added a file called oci8.conf in the /etc/apache2/conf.d directory. In this file I tried:

    SetEnv LD_LIBRARY_PATH = /opt/oracle/instantclient_10_2

    and also
    <Directory "/srv/www/htdocs">
    SetEnv LD_LIBRARY_PATH = /opt/oracle/instantclient_10_2
    </Directory>

    I restart Apache and still oracle doesn't work. I know apache is reading this file because it won't start if I put a typo in the file.

    Any help appreciated.

  2. #2
    ab@novell.com NNTP User

    Default Re: setting Apache2 environment variables

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Wild guess.... is the module 'mod_env' instead of just 'env'? I haven't
    played with it but everything else you've mentioned looks correct to me:

    http://httpd.apache.org/docs/2.2/mod/mod_env.html

    Good luck.





    cwrightrkkengineerscom wrote:
    > I've successfully install oci8 so I can code php to access Oracle
    > databases on my opensuse 10.3 server with apache2 and php5. One
    > requirement is to set the variable LD_LIBRARY_PATH. I set it to
    > /opt/oracle/instantclient_10_2 from the command line by typing:
    > LD_LIBRARY_PATH = /opt/oracle/instantclient_10_2
    > EXPORT LD_LIBRARY_PATH
    >
    > I then restart apache2. All is well - oracle database links are
    > fine.
    >
    > However if I restart the server, the oracle stuff won't work until I
    > reset LD_LIBRARY_PATH. I stop apache2, set the variable again and
    > restart apache2. This must be easier!
    >
    > I found a thread that instructed me to enable env for apache2. I did
    > this through yast, network services, http server, server modules. This
    > changed the line APACHE_MODULES to include 'env'. Then I added a file
    > called oci8.conf in the /etc/apache2/conf.d directory. In this file I
    > tried:
    >
    > SetEnv LD_LIBRARY_PATH = /opt/oracle/instantclient_10_2
    >
    > and also
    > <Directory "/srv/www/htdocs">
    > SetEnv LD_LIBRARY_PATH = /opt/oracle/instantclient_10_2
    > </Directory>
    >
    > I restart Apache and still oracle doesn't work. I know apache is
    > reading this file because it won't start if I put a typo in the file.
    >
    > Any help appreciated.
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFIrsof3s42bA80+9kRAtrOAJ4sqKvp8jEaWxvYWCoO2i/4whJb3ACff7V9
    LnJDxktDJKYyrMw7leu98ro=
    =ljP1
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: setting Apache2 environment variables

    Environment Variables in Apache - Apache HTTP Server says:

    Although these variables are referred to as environment variables, they are not the same as the environment variables controlled by the underlying operating system.
    Now it turns out that these Apache envvars do turn into OS envvars but only for CGI or SSI scripts. Scripts executed by mod_php5 don't qualify.

    So the way to do it is to export these variables to the apache server when it starts. The place to look is /etc/init.d/apache2. Here we find an interesting line:

    Code:
    . /usr/share/$pname/load_configuration
    So it seems that you could set the variables using /usr/share/$pname/load_configuration. $pname expands to apache2, from looking a bit above. So the file is /usr/share/apache2/load_configuration. The entire contents of the file are:

    Code:
    #!/bin/bash
    
    : ${sysconfig_apache:=/etc/sysconfig/apache2}
    
    #
    # load the configuration, but only if it hasn't been done already
    #
    if [ -z "$APACHE_MODULES" ]; then
            . $sysconfig_apache
    fi
    Aha, so we are intended to put our environment assignments in /etc/sysconfig/apache2. Let's test it by adding something at the bottom:

    Code:
    export SOME_ENV_VAR=something
    Restart Apache and run a PHP script that does this:

    Code:
    <?php
            system('echo $SOME_ENV_VAR');
    ?>
    And voila it works. So the conclusion is that if you put your exports in /etc/sysconfig/apache2 and start apache, they will be inherited by apache and children processes.

    Knowing the thoroughness of the SUSE developers, I would say this is entirely intentional and probably documented somewhere. I just reverse engineered it and learnt something myself in the process.

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: setting Apache2 environment variables

    Quote Originally Posted by ab@novell.com View Post
    Wild guess.... is the module 'mod_env' instead of just 'env'?
    You can omit the mod_ in the list of modules.

  5. #5
    cwrightrkkengineerscom NNTP User

    Default Re: setting Apache2 environment variables

    Hey ken_yap,

    I added export LD_LIBRARY_PATH to the end of /etc/sysconfig/apache2, restarted apache2 and it worked!

    Thanks for the answer and a providing me a little better understanding of how things work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •