问题
How can I password encrypt the database server connections from PHP to Sybase ASE?
The PHP connection to ASE fails when net password encryption reqd = 1
.
How can we make a PHP DB connection to ASE with password encryption? Is there a PHP keyword or parameter that we need to set on the client side connection?
回答1:
Below is a solution to this problem in term of able to connect from a Linux 64 bit base machine with PHP version 5.3.6 and Sybase driver from Sybase CTISQL Utility/15.7/P-EBF19975 ESD #3/DRV.15.7.0.3
. While we got this to work, we need to have Apache to work in addition to this, I am hoping Sybase support is able to help us with that as well as they have with solution below to our question. I am posting this here for everyone benefit. Note: AFAICT, this is not a supported solution by Sybase. Please use it as your own risk.
Few things need to happen for this to work:
- I've use the latest Debian Stable 6.05 squeeze 64 bit
- I've install ebf19977(developer kit with open client, yes the number is off, that's not a mistake, you will see when you install it) downloaded from Sybase
- Download PHP 5.3.6 from php.net website to be compile from source.
Step 1) I am assume one should easily set this up. Make sure you have sudo access
Step 2) To install the developer kit you need to type the whole path to where the setup.bin file is locate like so type in sudo /home/btran/ebf19977/setup.bin , this will start the setup, pretty much follow instructions there to to install OpenClient and its associate tools. Make sure that Open Client, and PHP library are install.
Once you done the install there are a few other steps to do:
Set all Sybase environments variables by executing the SYBASE.sh in the root directory at /opt/sybase
sudo cat /opt/sybase/SYBASE.sh >> /etc/profile , if necessary source /etc/profile
This will set most of the variables, but you need to add a couple variable that is not there:
PHPRC=/opt/sybase/OCS-15_0/config
LD_LIBRARY_PATH=/opt/sybase/OCS-15_0/php/php536_64/lib:/opt/sybase/OCS-15_0/lib
Your /ect/profile should look something like this:
# ------------------------------------
# Sybase Product Environment variables
# ------------------------------------
SYBASE="/opt/sybase"
export SYBASE
SYBASE_OCS="OCS-15_0"
export SYBASE_OCS
INCLUDE="/opt/sybase/OCS-15_0/include":$INCLUDE
export INCLUDE
LIB="/opt/sybase/OCS-15_0/lib":$LIB
export LIB
PATH="/opt/sybase/OCS-15_0/bin":$PATH
export PATH
LD_LIBRARY_PATH="/opt/sybase/OCS-15_0/php/php536_64/lib:/opt/sybase/OCS-15_0/lib:/opt/sybase/OCS-15_0/lib3p64:/opt/sybase/OCS-15_0/lib3p":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
PHPRC="/opt/sybase/OCS-15_0/config"
export PHPRC
JAVA_HOME="/opt/sybase/jre32"
export JAVA_HOME
RIBO_HOME="/opt/sybase/jutils-3_0/ribo"
export RIBO_HOME
# ------------------------------------
Then, you will also need to made modification to the interfaces file located at root directory /opt/sybase to look something like this, please do not use this, use your info:
dev
master tcp ether dev.company.com 4425
query tcp ether dev.company.com 4425
prod
master tcp ether prod.company.com 4425
query tcp ether prod.company.com 4425
ribo
master tcp ether testhost.company.com 5005
query tcp ether testhost.company.com 5005
You will also need to made modification to the ocs.cfg to get PHP to initiated correctly, this located in the folder /opt/sybase/OCS-15_0/config
to look like this:
;;;;;;;;;;;
; This is the default external configuration definition file. Feel free
; to add your own customizations.
;
[DEFAULT]
; This is the default section loaded by applications that use
CS_SEC_ENCRYPTION = CS_TRUE
[ANSI_ESQL]
; This section defines configuration which an ANSI conforming
CS_CAP_RESPONSE = CS_RES_NOSTRIPBLANKS
CS_EXTRA_INF = CS_TRUE
CS_ANSI_BINDS = CS_TRUE
CS_OPT_ANSINULL = CS_TRUE
CS_OPT_ANSIPERM = CS_TRUE
CS_OPT_STR_RTRUNC = CS_TRUE
CS_OPT_ARITHABORT = CS_FALSE
CS_OPT_TRUNCIGNORE = CS_TRUE
CS_OPT_ARITHIGNORE = CS_FALSE
CS_OPT_ISOLATION = CS_OPT_LEVEL3
CS_OPT_CHAINXACTS = CS_TRUE
CS_OPT_CURCLOSEONXACT = CS_TRUE
CS_OPT_QUOTED_IDENT = CS_TRUE
; End of default sections
[isql]
CS_SEC_ENCRYPTION = CS_TRUE
[PHP]
CS_SEC_ENCRYPTION = CS_TRUE
; This is a sample section showing how you might alter configuration
; properties for you Embedded SQL application.
[SAMPLE_ESQL]
; use most of the ANSI properties defined above
include = ANSI_ESQL
; but override some default properties
CS_OPT_CHAINXACTS = CS_FALSE ; run in autocommit mode
;;;;;;;;;
Note: Very Critical to check for the existence of the php.ini file in the same directory as well /opt/sybase/OCS-15_0/config
(this pointing the exention file, look at the environment variable LD_LIBRARY_PATH="/opt/sybase/OCS-15_0/php/php536_64/lib
)
you php.ini should read like this:
extension=/opt/sybase/OCS-15_0/php/php536_64/lib/sybaseasephp.so
Step 3) compile PHP from source, again Sybase call for 64 bit.
I down load the source to /opt/php-5.3.6
for persistent with where most app install for Linux.
cd to /opt/php-5.3.6
./configure
VERY IMPORTANT to note, this is where we ran into a snag, if I choose any other configure option and not default ./configure, PHP will fail to load with error below:
btran@sls-baonix:/opt/php-5.3.6$ php ~/test-dev.php
PHP Warning: PHP Startup: Unable to load dynamic library
'/opt/sybase/OCS-15_0/php/php536_64/lib/sybaseasephp.so' -
/opt/sybase/OCS-15_0/php/php536_64/lib/sybaseasephp.so: undefined
symbol: executor_globals in Unknown on line 0
Fatal error: Call to undefined function sybase_connect() in
/home/btran/test-dev.php on line 10
]
Reason we need other options is we need it also to work with Apache. We got it now to work with PHP, but we need to be able to initiate PHP from website so the dependencies is that PHP beside support Sybase, it also need to support Apache. If any PHP expert out there has solution to this please jump in and help us out.
来源:https://stackoverflow.com/questions/11144100/why-does-the-connection-to-ase-fail-when-password-encryption-is-required