LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > tix
User Name
Password

Notices


Rate this Entry

FreetTDS + Libiodbc (iodbc) + PHP (7.4.21) on Slackware Current (5.13.5)

Posted 07-27-2021 at 03:25 AM by tix
Updated 07-27-2021 at 08:38 AM by tix (EDIT - so that Apache (httpd) can see FreeTDS driver when running PHP scripts with calls to the driver)

FREETDS + LIBIODBC + PHP (7.4.21) - Written Kiptoo Kibowen (tkibowen@gmail.com) - 26/July/2021
README FIRST BEFORE YOU GIVE UP ON SLACKWARE LINUX!!!
==================================================================================================== ====
a) This Document is distributed under the GNU GPL Licence or whatever other free licence is avaiable out there
b) This document is meant for educational purposes only, don't blame me if you really mess up your system
c) Comments, suggestions and corrections are most welcome
d) Our distribution of choice is Slackware Linux (www.slackware.com) - Linux for the Sub-Genius, Phear the Penguin, ... /etc LOL!

Tunawakilisha +254 ... (we are representing the +254) (^_^)
==================================================================================================== ===========

After many hours of frustration and reading through many blogs and forums not to mention several manuals

"Alright boys and girls, get your recorders ready ...."


ASSUMPTIONS:
============
1) Your are using Slackware Linux -- 32 Bit or 64 Bit - best if it has been fully updated using slackpkg
2) You have drink, drunk and drunken enought coffee
3) You are somewhat sane (half insane to be accurate - people of sound mind cannot sit and hackaway at computers)
4) You have a bottle of your favourite drink to celebrate - "Welcome to Victory Lane! ..."
5) Your Microsoft SQL server is running MSSQL Express 2017 and details of the server are:
i) Username = sa
ii) Password = mylamepassword
iii) IP Address = 192.168.1.7
iv) MSSQL Port Listening on default port 1433
v) Database = SALES
6) You have root privileges - need them to install and configure freetds (hahhahhhahahahahahah!!!) LOL!
7) You can login as regular user called jack
8) You have correctly configure you Apache web server via (/etc/httpd/httpd.conf) and enabled:
i) userdir access (using public_html in user folder as their userdir to be accessed by Apache)
ii) php support (u are usin' -> php 7.4.21 which seems to drop support for unixodbc in favor of the native libiodbc)
9) Apache web server is running
10) You don't mind gaining some extra weight ~

REQUIREMENTS:
=============
1) Freetds - download the Slackware packages for your system (32 bit or 64 bit) and install using pkgtool - do source install only if you know what you are doing
2) libiodbc - comes with Slackware by default and has the tools iodbctest and iodbctestw
3) Cup of freshly brewed coffee
4) Another cup of freshly brewed coffee in case the first one runs out (aaahhahhahhahahah!!! heehehehehehehh!!!! = )
5) Donuts, definately, definately, plenty of Donuts -

CAUTION!!! CAUTION!!! CAUTION!!! CAUTION!!! CAUTION!!! CAUTION!!! CAUTION!!!
==============================================================================
1) If you install unixodbc it will conflict wit' libiodbc and really mess up your system - if you have to remove unixodbc then also remove libiodbc, REBOOT, then reinstall libiodbc - (NO GUARANTEES IT WILL WORK - MAY NEED TO REINSTALL SLACKWARE FROM SCRATCH)
2) PHP as of php 7.4.21 uses libiodbc by default when making PDO connection - unlike previous versions of PHP which used unixodbc and ignored libiodbc (~_~)

"Let me show you how deep this rabbit hole goes ..."

LETS ROCK!!!
=============

STEP 1 - DOWNLOAD AND INSTALL FREETDS (USE PKGTOOL) - COMPILE AND INSTALL FROM SOURCE ONLY IF YOU KNOW WHAT YOUR ARE DOING
---------------------------------------------------------------------------------------------------------------
a) Goto (LOL!) /etc/freetds/ and open the freetds.conf file using your favourite editor - mine is Joe's own editor
b) (As root user) --> From Assumption No. 5, add the following to the freetds.conf file (take note of the tds version) - in my case 7.0 worked - you may have to comment out "tds version = auto" at the top of freetds.conf by adding ; (semicolon) before it

[MSSQL]
host = 192.168.1.7
port = 1433
tds version = 7.0

c) Save the file

d) Test using tsql (as regular user jack or even as root user) = (for successful connection you should not see any error and should only see 1> ) (^_^)

jack@ndovu:/etc/freetds$ tsql -S MSSQL -U sa -P mylamepassword
locale is "LC_CTYPE=en_US;LC_NUMERIC=en_US;LC_TIME=en_US;LC_COLLATE=C;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_P APER=en_US;LC_NAME=en_US;LC_ADDRESS=en_US;LC_TELEPHONE=en_US;LC_MEASUREMENT=en_US;LC_IDENTIFICATION= en_US"
locale charset is "ISO-8859-1"
using default charset "ISO-8859-1"
1>

e)At the 1> prompt, Press CTRL+C to quit or just type quit and press enter
f) Remember -> on 32 bit Slackware Linux, the driver for using FreeTDS is in "/usr/lib/libtdsodbc.so" but in 64 bit Slackware Linux it is in "/usr/lib64/libtdsodbc.so"

LETS ROLL!!!
=============

STEP 2 - SETUP IODBC - (WE IS NOT USIN' UNIXODBC HERE = ) --- DRINK AND DRUNKEN SOME COFFEE AND MUNCH ON SOME DONUTS
-------------------------------------------------------------------------------------------------------------------------------
1) Login as regular user, in our example - jack (see Assumption 7 above)
2) Goto to your home directory, ~/jack by typing "cd" command at the command prompt

jack@ndovu:/etc/freetds$ cd
jack@ndovu:~$
3) Create a file called .odbc.ini (take note of the dot . before odbc.ini --> .odbc.ini)

jack@ndovu:~$ touch .odbc.ini
jack@ndovu:~$ joe .odbc.ini
4) Put the following contents in the file

[ODBC Data Sources]
MSSQL = Connection to MSSQL Server

[MSSQL]
Description = Connection to HRMS Server VIA FreeTDS
Driver = /usr/lib64/libtdsodbc.so
Server = 192.168.1.7
Username = sa
UID = sa
Database = SALES
Port = 1433

5) Save the file
6) Export the environment variable ODBCINI to point to this file --> (.odbc.ini) by typing dis' at de' command prompt:
jack@ndovu:~$ echo 'export ODBCINI=$HOME/.odbc.ini' >> .bashrc

7) Create .odbcinst.ini so as to define our drive {FreeTDS} -> will need it later when using PHP to acces MSSQL using new PDO construct (take note of the dot . before odbcinst.ini --> .odbcinst.ini) & type these in the file

jack@ndovu:~$ cd
jack@ndovu:~$
jack@ndovu:~$ touch .odbcinst.ini
jack@ndovu:~$ joe .odbcinst.ini

[ODBC Drivers]
FreeTDS=Installed

[FreeTDS]
Description=FreeTDS Driver for Linux
Driver = /usr/lib64/libtdsodbc.so
UsageCount=2

8) Save the file && Lets test iodbctest ---> drinken and druken more coffee - dwan' farget' the donuts man!

jack@ndovu:~$ iodbctest
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.1015.0210

Enter ODBC connect string (? shows list): ?

DSN | Driver
------------------------------------------------------------------------------
MSSQL | Connection to HRMS SQL Server

Enter ODBC connect string (? shows list): DSN=MSSQL;UID=sa;PWD=mylamepassword
Driver: 01.00.0009 (libtdsodbc.so)

SQL>quit

Have a nice day.
jack@ndovu:~$

9) Drink more coffee!!! Celebrate with the drink of choice --> but don't drink too much --> don't drinken and hackaway at your computer!! (*_*)

10) Lets test the one liners from command prompt - first using the DSN

jack@ndovu:~$ iodbctest "DSN=MSSQL;UID=sa;PWD=mylamepassword;DATABASE=SALES"
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.1015.0210
Driver: 01.00.0009 (libtdsodbc.so)

SQL>quit

Have a nice day.
jack@ndovu:~$

11) Test by specifiying the driver and IP address of the server (DSN less) - LOL!!! haahhahahahh!!! (sugar & coffee high) --> (needed for accessing via PHP) -> done 7) above --> .odbcinst.ini

jack@ndovu:~$ iodbctest "Driver={FreeTDS};Server=192.168.1.7;Port=1433;UID=sa;PWD=mylamepassword;DATABASE=SALES"
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.1015.0210
Driver: 01.00.0009 (libtdsodbc.so)

SQL>quit

Have a nice day.

jack@ndovu:~$

This calls for a celebration ..... toast to your dog, your cat and most importantly to Tux who lives inside your computer running Slackware Linux

===================================BEGIN :::: COMMERCIAL BREAK - Now a word from our sponsors===============================================
Tunawakilisha +254 ... (we are representing the +254) - (^_^)

OK!

In case you get some funny looking errors when testing using iodbctest, such as:
1) libssl... not found
2) libcrypt... not found
3) ...libtdsodbc.so....sk_pop_free....

You know that you need to update your freetds installation.
The available Slackware package at the time of writing this document was freetds-1.00.9-x86_64-1_slonly.txz from https://pkgs.org/download/freetds and it was for Slackware 14.2 not for Slackware Current (5.x.x)

i) Using pkgtool - remove freetds package
ii) Download the stable version for freetds which at the time of writing this document was freetds-1.3.tar.gz available from freetds.org - you can also guugle freetds.tar.gz
iii) Copy freetds.tar.gz to a convenient folder --> /tmp/
iv) Uncompress the freetds.tar.gz (which should happen without any error being spit back at youz guyz! )
jack@ndovu:/tmp$ tar -xvzf freetds-1.3.tar.gz
v) Change to the newly uncompressed folder
jack@ndovu:/tmp$ cd freetds-1.3
jack@ndovu:/tmp/freetds-1.3$
vi) Change to superuser (root) -- hahahahahahahh! LOL!
jack@ndovu:/tmp/freetds-1.3$ su
Password: <my super duper root password here>
vii) Run configure script --> remember we are building against libiodbc and not unixodbc (hopefully by this point you have already uninstalled unixodbc ~ )
-> libiodbc lives inside the /usr directory by default (unless it was compiled somewhere else LOL!)

root@ndovu:/tmp/freetds-1.3# ./configure --with-iodbc=/usr

(should run without spitting back error at youz guyz!)

viii) Run make
root@ndovu:/tmp/freetds-1.3# make

(should run without spitting back error at youz guyz!)

ix) Run make install
root@ndovu:/tmp/freetds-1.3# make install

(should run without spitting back error at youz guyz!)

x) IMPORTANTE - reboot!!

xi) After reboot, run the command tsql to know where it lives and it's view of the world
jack@ndovu:~$ tsql -C

Compile-time settings (established with the "configure" script)
Version: freetds v1.3
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: auto
iODBC: yes
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
OpenSSL: yes
GnuTLS: no
MARS: yes

xii) So your freetds.conf file should live in /usr/local/etc --> change to superuser and go to the new directory hosting freetds.conf
jack@ndovu:~$ su
Password: <my super duper root password here>

root@ndovu:/home/jack# cd /usr/local/etc

root@ndovu:/usr/local/etc# ls
freetds.conf locales.conf pool.conf

xiii) Open the freetds.conf using your favourite editor (mine is Joe's own editor) and put the contents similar to STEP 1 above
root@ndovu:/usr/local/etc# joe freetds.conf

[MSSQL]
host = 192.168.1.7
port = 1433
tds version = 7.0

xiv) Save and exit and also exit from super user
root@ndovu:/usr/local/etc# exit
jack@ndovu:~$


xv) Test using tsql (as regular user jack or even as root user) = (for successful connection you should not see any error and should only see 1> ) (^_^)

jack@ndovu:~$ tsql -S MSSQL -U sa -P mylamepassword
locale is "LC_CTYPE=en_US;LC_NUMERIC=en_US;LC_TIME=en_US;LC_COLLATE=C;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_P APER=en_US;LC_NAME=en_US;LC_ADDRESS=en_US;LC_TELEPHONE=en_US;LC_MEASUREMENT=en_US;LC_IDENTIFICATION= en_US"
locale charset is "ISO-8859-1"
using default charset "ISO-8859-1"
1>

xvi) Remember that in STEP 2, libtdsodbc.so lives in /usr/lib64/libtdsodbc.so, but now after source install, it lives somewhere else, specifically /usr/local/lib/libtdsodbc.so
--> OPEN .odbc.ini and change /usr/lib64/libtdsodbc.so to /usr/local/lib/libtdsodbc.so
jack@ndovu:~$ joe .odbc.ini
[ODBC Data Sources]
MSSQL = Connection to MSSQL Server

[MSSQL]
Description = Connection to HRMS Server VIA FreeTDS
Driver = /usr/local/lib/libtdsodbc.so
Server = 192.168.1.7
Username = sa
UID = sa
Database = SALES
Port = 1433

xvii) Save and exit the file, the open .odbcinst.ini and do the same as .odbc.ini

jack@ndovu:~$ joe .odbcinst.ini

[ODBC Drivers]
FreeTDS=Installed

[FreeTDS]
Description=FreeTDS Driver for Linux
Driver = /usr/local/lib/libtdsodbc.so
UsageCount=2

xviii) Save and exit the file

xix) test with iodbctest using DSN

jack@ndovu:~$ iodbctest "DSN=MSSQL;UID=sa;PWD=mylamepassword;DATABASE=SALES"
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.1015.0210
Driver: 01.03.0000 (libtdsodbc.so)

SQL>quit

Have a nice day.
jack@ndovu:~$

11) Test by specifiying the driver and IP address of the server (DSN less) - LOL!!! haahhahahahh!!! (sugar & coffee high) --> (needed for accessing via PHP) -> done 7) above --> .odbcinst.ini

jack@ndovu:~$ iodbctest "Driver={FreeTDS};Server=192.168.1.7;Port=1433;UID=sa;PWD=mylamepassword;DATABASE=SALES"
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.1015.0210
Driver: 01.03.0000 (libtdsodbc.so)

SQL>quit

Have a nice day.

jack@ndovu:~$

TUSHEREKEE!! -- (LET US CELEBRATE!!)

Kata Keki, leo ni siku yako --- (Cut the cake, for today is your day!)
===================================END :::: COMMERCIAL BREAK - Now a word from our sponsors===============================================



STEP 3 - TEST FROM PHP :::: ahaahahahahahahahahahh!!! heehehehehehehehehehh!!!! hihihihihihihhiihihihi!!! (there is notin' such as too much coffee!!) -
-----------------------------------------------------------------------------------------------------------------------------------------------------------
1) Go to home directory of jack

jack@ndovu:~$ cd
jack@ndovu:~$ cd public_html
jack@ndovu:~/public_html$

2) Create file called testconnect.php and open the file using your favourite editor (mine is Joe's own editor )

jack@ndovu:~/public_html$ touch testconnect.php
jack@ndovu:~/public_html$ joe testconnect.php

3) Put the following in the file

<?php
#TRY IS PART OF THE PDO CONSTRUCT
try { //odbc SUCCESS try OPEN
$dbCon = new PDO("odbcriver={FreeTDS};Server=192.168.1.7;Port=1433;UID=sa;PWD=mylamepassword;DATABASE=SALES"); #using IP and PORT - useful in most progys' ahhaahahh!! LOL!

//$dbCon = new PDO("odbc:MSSQL", 'sa', 'mylamepassword'); #using DSN in .odbc.ini directly also works - remove the // before this line to test


echo "SUCCESS!";
} //odbc SUCCESS try CLOSE
catch (PDOException $e)
{ //odbc FAILURE try OPEN
echo $e->getMessage();
} //odbc FAILURE try OPEN

?>

4) Save the file and test the PHP connection tot your database from the command prompt =

jack@ndovu:~/public_html$ php -f testconnect.php
SUCCESS!
jack@ndovu:~/public_html$

5) CELEBRATE!!!!!!! ("Welcome to Victory Lane! ...")


===================================BEGIN :::: COMMERCIAL BREAK - Now a word from our sponsors===============================================
Ata wazee wa zamani walisema kazi na dawa... --- (Even the men of old said work and medicine)

In case you run the php command above and get a nasty error:
jack@ndovu:~/public_html$ php -f testconnect.php
segmentation fault
jack@ndovu:~/public_html$

Before you reinstall your whole system, consider your best friend --> slackpkg

i) Connect to the internet

ii) Change to root user
jack@ndovu:~$ su
Password: <my super duper root password here>

root@ndovu:/home/jack#

iii) Go to where slackpkg configuration files live
root@ndovu:/home/jack# cd /etc/slackpkg
root@ndovu:/etc/slackpkg# ls
blacklist mirrors slackpkg.conf templates

iv) Open the file of interest called mirrors using your favourite editor (mine is Joe's own editor)
root@ndovu:/etc/slackpkg# joe mirrors

(select the mirror you want -> only 1 mirror at a time -> by removing hash from the front of the mirror definition)

NOTE:
Slackware Current -> upgrades slackware brings you to Slackware 5.x.x
Slackware 14.2 -> simply updates the slackware living in your box and remains Slackware 4.x.x

(most of the segmentation fault problems in php occur when people upgrade to Slackware Current -> 5.x.x)

v) Update you Slackpkg package lists and many other things prior to actual update to your system
root@ndovu:/etc/slackpkg# slackpkg update

(after some time bring you back to the command prompt -> ensure you are connected to high speed and reliable internet connection)

root@ndovu:/etc/slackpkg#

vi) Install the new packages first
root@ndovu:/etc/slackpkg# slackpkg install-new

(go through the prompts and update begins and after a while brings you back to the command prompt)

vii) Upgrade all your packages
root@ndovu:/etc/slackpkg# slackpkg upgrade-all

(go through the prompts and update begins and after a while brings you back to the command prompt)

root@ndovu:/etc/slackpkg#

viii) LILO LILO LILO LILO LILO LILO LILO LILO --> run LILO!
root@ndovu:/etc/slackpkg# lilo
.....

root@ndovu:/etc/slackpkg#

ix) Clean up your system - removes all your old packages
CAUTION -> custom installed packages that you installed that were not part of the original Slackware installation will be removed, e.g. Chromium, VLC music player, XZ, ....

root@ndovu:/etc/slackpkg# slackpkg clean-system

x) REBOOT!

xi) Kindly note that you may have to uninstall your freetds.1-3 and reinstall it:
jack@ndovu:~$ su
Password: <my super duper root password here>

jack@ndovu:/home/jack# cd /tmp/freetds-1.3

jack@ndovu:/tmp/freetds-1.3# make uninstall
......

xii) REBOOT!

xiii) Remove the freetds-1.3 installation folder that you previously installed and uninstalled from
jack@ndovu:~$ su
Password: <my super duper root password here>

jack@ndovu:/home/jack# cd /tmp/

jack@ndovu:/tmp/# rm -Rf freetds-1.3

xiv) Uncompress the freetds-1.3.tar.gz file again and go into the uncompressed folder
jack@ndovu:/tmp/# tar -xvzf freetds-1.3.tar.gz
root@ndovu:/tmp# cd freetds-1.3
root@ndovu:/tmp/freetds-1.3#

(COPIED FROM PREVIOUS COMMERCIAL BREAK)
xv) Run configure script --> remember we are building against libiodbc and not unixodbc (hopefully by this point you have already uninstalled unixodbc )
-> libiodbc lives inside the /usr directory by default (unless it was compiled somewhere else LOL!)

root@ndovu:/tmp/freetds-1.3# ./configure --with-iodbc=/usr

(should run without spitting back error at youz guyz!)

xvi) Run make
root@ndovu:/tmp/freetds-1.3# make

(should run without spitting back error at youz guyz!)

xvii) Run make install
root@ndovu:/tmp/freetds-1.3# make install

(should run without spitting back error at youz guyz!)

xviii) IMPORTANTE - reboot!!

xix) ---> >>>CONFIGURE YOUR FREETDS-1.3 AS PER PREVIOUS COMMERCIAL BREAK<<< <---


xx) Run your php script from above
4) Save the file and test the PHP connection tot your database from the command prompt =

jack@ndovu:~/public_html$ php -f testconnect.php
SUCCESS!
jack@ndovu:~/public_html$

5) CELEBRATE!!!!!!! ("Welcome to Victory Lane! ...")

Jambo, Jambo bwana, habari gani, mzuri sana --- (Hi, Hi sir, how are you, I am very fine)
===================================END :::: COMMERCIAL BREAK - Now a word from our sponsors===============================================

HOPES THIS HELPS SOMEONE OUT THERE!!

Slackware Linux -> Linux for the Sub-Genius

Tunawakilisha +254 - (Representing the +254) - (^_^)

------------------------------------------------------------------------------
BEGIN :::: EDIT :::: July 27th, 2021 - system wide configuration for apache
------------------------------------------------------------------------------
In case you knew or did not know, the default location for odbc configuration files
odbc.ini and odbcinst.ini is /etc/

So as root user, simply copy the .odbc.ini and .odbcinst.ini from jacks home folder (see example above) to /etc
That is:

jack ----> /etc/
===================================
/home/.odbc.ini ----> /etc/odbc.ini
/home/.odbcinst.ini ---> /etc/odbcinst.ini

Restart your box and try running you php script that has calls to MSSQL server using FreeTDS and libiodbc

------------------------------------------------------------------------------
END :::: EDIT :::: July 27th, 2021 - system wide configuration for apache
------------------------------------------------------------------------------
Posted in Uncategorized
Views 1424 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 11:26 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration