Wednesday, March 11, 2009

Install FreeTDS on Ubuntu

I've been struggling to install FreeTDS on Ubuntu. Fortunately, google is still the best friend. I found the link below and manged to install it.

http://ubuntuforums.org/showthread.php?p=6823026

I copied the posting here as well. Thanks for Mahalie for the post.

-----------------------------------------------------------------------------------------------
After a lot of doc reading at PHP.net, FreeTDS and here and trying and then backing out of several attempts to get my Ubuntu Lamp on Dapper Drake LTS to connect via ODBC to a Microsoft SQL Server on our corporate network I found a step-by-step tutorial that worked for me here:http://benlinus.blogspot.com/2007/08...module-in.html

Here is how I did it - already running working LAMP with PHP5. 

Code:
sudo apt-get install freetds-dev sudo apt-get source php5 cd php5-5.1.2/ext/mssql sudo apt-get install php5-dev sudo phpize sudo ./configure --with-mssql sudo make cd modules cp mssql.so /usr/lib/php5/20051025 sudo vi /etc/php5/apache2/php.ini
add the following line:
Code:
extension = mssql.so
Code:
sudo /etc/init.d/apache2 restart
To confirm if MSSQL support is available, create a new php file and execute phpinfo() function. 

To test my connection tried code from PHP.net using MSSQL_CONNECT
PHP Code:
// Server in the this format: \ or  
// , when using a non default port number 

$server 'DBSERVERNAME.corp.DOMAIN.com'

$link mssql_connect($server'UserName''UserPassword'); 

if(!
$link

    die(
'Something went wrong while connecting to MSSQL'); 

?> 

Test

If you don't have errors, it's working. If you have 'cannot open default DB' then make sure your permissions for the user is set property on the MS SQL server and that their default database is the one you are pointing at.

1 comment:

Bryan said...

Don't get in the bad habit of sudo for configure or make (or phpize).

The only time you should sudo in this case is when you have to install something into the OS, such as "make install".