Linux – Cannot connect to oracle using oci_connect() on reboot

apache-2.2linuxoraclePHP

I am trying to setup a local development box. The box's on Linux Mint. Installed apache, php and mysql without any problem, then I proceeded to install Oracle Xpress Edition as my newest project requires.

Obtained the oci8.so through pecl and modified php.ini.

The problem is, everytime I reboot and tries to connect to oracle using oci_connect() call, it will give me this error:

oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME is set and points to the right directory 

I've already checked the ORACLE_HOME at the time the error arises and it seems to contain the correct value.

Now, I can get around this problem by going to terminal and

$ su
$ apache2ctl stop
$ apache2ctl start

That's the ONLY way of getting it fixed (i.e. not sudo apache2ctl restart, not sudo apache2ctl {stop,start}, not su
apache2ctl restart
).

I know this is a minor problem and I could probably live with it. But if someone out there can point me on getting this work, I'd very much appreciate it.

Best Answer

Another option is to set ORACLE_HOME in the apache httpd.conf or in the virtual host that uses it.

Add:

SetEnv ORACLE_HOME "/path/to/oracle/home"

to httpd.conf (or inside the virtual host config file /etc/apache2/hosts-enabled/...)

That has the advantage of not needing to mess up with system scripts.