cooperl22 / laravel-db2

laravel-db2 is a simple DB2 service provider for Laravel. It provides DB2 Connection by extending the Illuminate Database component of the laravel framework.
Other
59 stars 64 forks source link

[OFF] Ubuntu/CentOS ODBC Driver #40

Closed douglasjunior closed 5 years ago

douglasjunior commented 6 years ago

I was able to work with this library on Windows (XAMPP) with the ODBC Driver iSeries.

Now I need to deploy the project in production, and I would like it to be on Linux. The company support team only has one Ubuntu 11 VM with the ODBC Driver installed successfully. According to them it was not possible to install the driver in newer versions or other distributions.

My question: What is the ODBC Driver, and which Linux distribution/version are you using?

My server is an AS/400 late 2009.

wolojonathan commented 6 years ago

Hi Douglas,

I've been struggling for the past weeks with the ODBC drivers on Linux. Personally, I succeeded to install the iSeries ODBC on a CentOS 7 VM, and I've been using the old "iSeriesAccess-6.1.0" driver.

It's working up to some extent, and it might work in scope of laravel-db2. However, the SQL relay I'd like to set up (my other personal project) is not compatible with that driver version. because of some faulty behavior in some cases. According to what I found on the web, I need the new one called "iAccess" (IBM_i_Access_ClientSolutions-_Linux_AP_LCD8).

If by any chance, you have an access to the IBM ESS with a product giving you access to that new client, could you please send me an email ? I'm really desperate to find that one for a long time already

If you need the drivers I'm using for CentOS, please contact me by email as well, I'll be glad to share.

Have a nice day

bironeaj commented 6 years ago

Hello,

Just a question, why are you guys using the ODBC driver and not the PHP PDO? The only reason I can think of is licensing?

Anyway, the PDO is much easier to configure. I created a gist with my install script for the IBM driver and the PDO. You can find that script here. The script was made for Ubuntu/Laravel Forge but it should be a good starting point.

Hope this helps!

nulele commented 5 years ago

Hi @bironeaj, I'm interested in your approach. Can you please post what's your database.php configuration for ibmi connection? Many thanks!

bironeaj commented 5 years ago

@nulele here you go https://gist.github.com/bironeaj/4008e98921dddde46792488c21cb91a1

douglasjunior commented 5 years ago

@wolojonathan, in the end I was able to update Ubuntu 11 where there was the old ODBC already installed. So I did not need to reinstall the driver.

@bironeaj, what do I need to install on Linux to work this way? Is your DB2 an as400?

bironeaj commented 5 years ago

@douglasjunior I wanted to let you know the driver will run on the latest Ubuntu and CentOS. As mentioned before, here is the install steps I go thru for setting up a Laravel Forge server. You should be able to adapt it for your needs. It is an iSeries/AS400.

douglasjunior commented 5 years ago

Thanks, I think the issue can be closed now.

douglasjunior commented 5 years ago

Just to document, I'll add the script here. Thanks @bironeaj!

# Install Dev Package
sudo apt install php7.2-dev
# CD Home
cd ~
# Get CLI
wget -q -O CLI.tar.gz https://iwm.dhe.ibm.com/sdfdl/v2/regs2/smkane/IDSOC/Xa.2/Xb.bL-snMrfTDtX6PgwwuXqAdeiFX6UY09DUuicweVTRlk/Xc.ibm_data_server_driver_for_odbc_cli_linuxx64_v11.1.tar.gz/Xd./Xf.LPr.D1vk/Xg.9810279/Xi.swg-idsoc97/XY.regsrvs/XZ.42v0ODLDocGa6RjgsAKBjJobG6U/ibm_data_server_driver_for_odbc_cli_linuxx64_v11.1.tar.gz
# Get PDO
wget -q -O PDO.tar.gz https://pecl.php.net/get/PDO_IBM-1.3.5.tgz
# Unpack Files & Cleanup
tar -zxf CLI.tar.gz
rm CLI.tar.gz
tar -zxf PDO.tar.gz
rm PDO.tar.gz
# Install CLI
sudo mkdir /opt/ibm/
sudo mv clidriver /opt/ibm/cli
sudo cp -r /opt/ibm/cli/lib /opt/ibm/cli/lib64
# Set CLI ENV Variables
sudo bash -c 'cat <<EOT>> /etc/profile
DB2_CLI_DRIVER_HOME=/opt/ibm/cli
DB2CLIINIPATH=/opt/ibm/cli/cfg
PATH=\$PATH:/opt/ibm/cli/bin
LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/opt/ibm/cli/lib64
EOT'
source /etc/profile
sudo bash -c 'cat <<EOT>> /etc/ld.so.conf.d/db2.conf
/opt/ibm/cli/lib64
EOT'
sudo ldconfig
# Configure CLI
db2cli writecfg add -dsn (WRKRDBDIRE entry) -database (WRKRDBDIRE entry) -host XXX.XXX.XXX.XXX -port 446 -parameter "IsolationLevel=32"
db2cli bind "/opt/ibm/cli/bnd/@db2cli.lst" -dsn (WRKRDBDIRE entry) -user USER -passwd PASS -options "blocking all grant public"
# Install PDO
cd ~/PDO_IBM-1.3.5
sudo phpize7.2
sudo mkdir -p include/php/20170718/ext
sudo cp -r /usr/include/php/20170718/ext/. include/php/20170718/ext/
sudo ./configure --with-pdo-ibm=/opt/ibm/cli
sudo make
sudo make install
# Cleanup
cd ~
sudo rm -rf PDO_IBM-1.3.5
sudo rm package.xml
# Edit php.ini extension=pdo_ibm.so
sudo bash -c 'cat <<EOT>> /etc/php/7.2/cli/php.ini
extension=pdo_ibm.so
EOT'
sudo bash -c 'cat <<EOT>> /etc/php/7.2/fpm/php.ini
extension=pdo_ibm.so
EOT'
# Restart PHP
sudo service php7.2-fpm restart
# Restart nginx
sudo service nginx restart
bironeaj commented 5 years ago

@douglasjunior No problem. The URL on line 6 will need updated. IBM signs the download URL. You will have to login to IBM and get a new URL.

nulele commented 5 years ago

@nulele here you go https://gist.github.com/bironeaj/4008e98921dddde46792488c21cb91a1

Thank you @bironeaj!!

Just on doubt... if you already define IP, username and password in the script, why declaring them again in the laravel driver configuration?

bironeaj commented 5 years ago

@nulele Different developers have different logins... Helps maintain the Laravel way of doing versioning on the DB tables