<<<<<<< .mine

How to compile MSSQL support into PHP in Ubuntu Dapper Drake

=======

How to compile MSSQL support into PHP in Ubuntu Dapper Drake

>>>>>>> .r7754

This information is specific to Ubuntu Dapper Drake, but it may work on other versions of the software. This will allow you to connect to Microsoft’s SQL Server 2000 to use Apache and PHP to connect to a MSSQL database.

  • Install support packages
sudo aptitude install freetds-dev
sudo aptitude install tdsodbc
  • Modify the Freetds file to access the server: sudo nano /etc/freetds/freetds.conf (not sure if this is necessary)
# Our SQL Server
[FSData]
host = 192.168.x.x
port = 1433
tds version = 8.0
  • Tell UnixODBC where to find the FreeTDS driver and give it a name:
    • Modify /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS 0.61-5 Deb
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
FileUsage = 1
CPTimeout = 5
CPReuse = 5
    • Modify the odbc.ini file: sudo nano /etc/odbc.ini
[Products]
Description = Products on Our MSSQL Server
Driver = FreeTDS
Servername = FSData
Database = Products
  • Download dpkg
sudo aptitude install dpkg-dev
  • Download php-src
sudo aptitude source php5
  • Go into the new php5 directory
  • Edit the debian/rules file - add the following to the common config sudo nano debian/rules
--with-mssql
  • build dependencies
sudo aptitude build-dep php5
  • build the package
sudo dpkg-buildpackage
  • install the new PHP w/ MSSQL
sudo dpkg -i php5_5*.deb
  • copy the new libphp5.so to the correct directory (otherwise it will still use the old one)
sudo cp ~/php5-*/apache2-build/libs/libphp5.so /usr/lib/apache2/modules/libphp5.so
  • restart Apache
sudo /etc/init.d/apache2 restart

15 Responses to “How to compile MSSQL support into PHP in Ubuntu Dapper Drake”

  1. Jose says:

    Hi!

    Well I did all the steps, but I have got a problem, when I’m trying to execute Stored Procedures, well all the stored proc, that I’ve got don’t run, but in windows they’re working.

    Even when I compiled apache php freetds from sources It worked, but now with this method (don’t using .tar.gz packages). don’t. :’(

    Did someone have the same problem?

    Thanks, and sorry if my english is bad!

  2. Corey says:

    Thanks, worked as promised, but before I could do:

    $> sudo apt-get source php5

    I had to:

    $> sudo apt-get install dpkg-dev

    YMMV.

  3. Colin says:

    Thanks for the feedback Corey. I added in the line to install dpkg just in case. Also, I changed to use aptitude rather than apt-get. Aptitude is better at managing dependencies, and should now be used in place of apt-get.

  4. Matt says:

    Hi, I try and build the package and it says…

    root@linux:~/php5-5.1.6# sudo dpkg-buildpackage
    dpkg-buildpackage: source package is php5
    dpkg-buildpackage: source version is 5.1.6-1ubuntu2.1
    dpkg-buildpackage: source changed by Martin Pitt
    dpkg-buildpackage: host architecture i386
    dpkg-buildpackage: source version without epoch 5.1.6-1ubuntu2.1
    debian/rules clean
    : No such file or directory
    ‘. Stop. No rule to make target `

  5. Matt says:

    I’m not sure why this one didn’t work for me but this tutorial worked..

    http://panthar.org/2006/06/15/php-with-mssql-on-ubuntu-606/

    I did have to delete the following files before I could do that tutorial above because it was interfering with the install.

    /etc/odbcinst.ini
    /etc/freetds/freetds.conf
    /etc/odbc.ini

    good luck.

    ~MN

  6. Sanchya says:

    mssql.so could not found anywhere in system that’s why my connection is not working .. It is givin error of not founding mssql.so..:-(

  7. staarit says:

    hi
    can someone give a suggestion; i followed all of the aboved but when i execute dpkg-buildpackage….at the end it errors:
    cp: cannot stat ‘apache2-build/.libs/libphp5.so’: no such file or directory
    make: *** [install] error 1

  8. jameswillisisthebest says:

    This is my first post
    just saying HI

  9. None says:

    Hi there. Is there anyone out there who’s managed to actually connect Linux and Php to MsSql WITHOUT compiling php5 from source? I use latest Debian Testing and don’t really want to have the struggle to maintain production enviroment servers at work with anything else than Debian packages. I’ve installed php5-sybase and freetds-dev package and tried different approaches. Any tips are appreciated!

  10. None says:

    Fixed it :)
    apt-get install php5-odbc tdsodbc php5-sybase –yes

    in /etc/odbcinst.ini
    [FreeTDS]
    Description = TDS driver (Sybase/MS SQL)
    Driver = /usr/lib/odbc/libtdsodbc.so
    Setup = /usr/lib/odbc/libtdsS.so
    CPTimeout =
    CPReuse =
    UsageCount = 1

    and /etc/odbc.ini
    [Intranet]
    Description = TDS MSSQL (PUSDATIN)
    Driver = FreeTDS
    Servername = Intranet
    Database = HD
    Port = 1433

    worked like a charm. In php it works with odbc_connect and mssql_connect functions.

  11. Sean says:

    You can also just install the package php5-sybase:

    apt-get install php5-sybase

    worked for me!

  12. Iain says:

    Hi,

    Great guide. Had same problem as Corey; arrived at similar solution. But this was a huge help. Thanks for taking time to put it on the Internets.

    I.

  13. Hi!
    Your file is with svn conflicts :)

    It is being showed in the title:

    <<<<<<>>>>>> .r7754

  14. Alastair says:

    Belter of an article!

Leave a Reply