DISQUS

DISQUS Hello! Panthar's Lair is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Panthar's Lair

Adventures of a Professional Computer Tamer
Jump to original thread »
Author

HOWTO: PHP with MSSQL on Ubuntu 6.06

Started by panthar · 10 months ago

I recently set up an Ubuntu server that needed to access a MSSQL database. The php5-sybase package sort of worked (the queries appeared to work, but data was missing). So, I set out to build some .deb packages with MSSQL support built in.

First make sure you have the Debian package deve ... Continue reading »

38 comments

  • Hi, thanks for this guide... everything compiled, linked and built ok. I restarted apache2 (which I installed via adept) and when I tried to load a page that connects to mssql, I got the following error message: Fatal error: Call to undefined function mssql_connect() in /var/www/conection.php on line 18 ... do you know why? I already configured freetds and tested it with tsql -S 192.168.0.1 -U sa and it connected. So, I'm al little bit stuck since I still don't know if there are other configuration steps than the ones you gave us in your guide to be able to connect and use mssql functions.

    I would appreciate your help very much, indeed.
  • Please ignore my last post... I know now why It didn't work: I think I entered dpkg -i php5_*.deb and that did not install the mssql deb... i explicitly installed the mssql deb and it worked... thanks
  • Don't you love the naming? Some have the dash, some the underscore. Glad this was helpful to you :)
  • OK... dpkg-buildpackage is running, so I have some time to kill. I have a couple questions now, may have more later...

    Do I need to uninstall php5 before installing this custom version?

    If not, how do I let dpkg/apt/synaptic know that I don't want to overwrite my custom php5 when a php5 update hits the ubuntu repositories?

    Thanks,

    Robert Aldridge
  • You do not have to uninstall your older PHP packages - this will overwrite/upgrade it (it won't mess with your config files)

    To keep this from being upgraded automatically, you should "pin" it. There is a good reference for that over at: http://www.debian.org/doc/manuals/apt-howto/ch-...
  • Did anybody have character problems. When I pull data from Northwind, Customers table I get the following:
    I get the question marks in the html source as well.

    What I'm getting on ubuntu box:

    ALFKI - Alfreds Futterkiste - Maria Anders
    ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
    ANTON - Antonio Moreno Taquer?a - Antonio Moreno
    AROUT - Around the Horn - Thomas Hardy
    BERGS - Berglunds snabbk?p - Christina Berglund

    What I should get (I get this when run on windows):

    ALFKI - Alfreds Futterkiste - Maria Anders
    ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
    ANTON - Antonio Moreno Taquería - Antonio Moreno
    AROUT - Around the Horn - Thomas Hardy
    BERGS - Berglunds snabbköp - Christina Berglund
  • Deko
    I had this too. The solution is to add the line client charset = UTF-8 to the freetds.conf.file
    I use a windows 2k server so I had
    [MyServer2k]
    host = 192.168.1.14
    port = 1433
    tds version = 8.0
    client charset = UTF-8
  • Hello,

    when I write apt-get build-dep php5
    I have a problem of dependancies. What will I have to do ?

    Thank you
  • Great skills on this: it works perfectly...

    Thank you, it saved our team masses of time...
  • Thanks a lot. These instructions saved me a few days of research.
  • Very nice article! Thank you.
  • Ranouf, I have the same problem....

    root@linux:~/php5-5.1.6# 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
    dpkg-checkbuilddeps: error: per-package paragraph 23 in control info file is missing Package line
    dpkg-buildpackage: Build dependencies/conflicts unsatisfied; aborting.
    dpkg-buildpackage: (Use -d flag to override.)
  • sorry... Ignore my last post... It was due to extra spaces after I pasted into the control file... I do have another problem through. After I try to do a dpkg-build package I get the following. This will be the second tutorial that this has happened to me on. I'm not sure why either.

    root@linux:~/php5-5.1.6# 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 `

    I think i'm going to try and use an older verison of PHP.
  • great stuff, just finished my 4th build of this on a different machine over the past 6 weeks!

    Matt: If you move up to the parent folder the php5-mssql extension should have been built anyway, just install it with dpkg -i, worked perfectly for me!
  • Hello,

    I did exactly as you describe above, but while running "dpkg-buildpackage" I get the following error:

    configure: error: unrecognized option: -–with-mssql=shared,/usr
    Try `../configure --help' for more information.
    make: *** [configure-apache2-stamp] Error 1

    Any suggestion?

    Thank you!
  • Thanks for these instructions!

    This is a much *cleaner* way than I was going to do it... compiling all from source and manually figuring out the dependencies... say 3-6 hours of work getting things right, as opposed to 15-30 minutes.

    Once again - much thanks!
  • Thanks for the instructions, best I've found. Anyone know why debian/ubuntu don't include the module by default? Seems that would _really_ solve the issue
  • When i compile i get this error:
    [CODE]

    =/usr/share/file/magic.mime --with-exec-dir=/usr/lib/php5/libexec \
    --without-mm \
    --with-curl=shared,/usr \
    --with-zlib-dir=/usr \
    --with-gd=shared,/usr --enable-gd-native-ttf \
    --with-jpeg-dir=shared,/usr \
    --with-xpm-dir=shared,/usr/X11R6 \
    --with-png-dir=shared,/usr \
    --with-freetype-dir=shared,/usr \
    --with-ttf=shared,/usr \
    --with-t1lib=shared,/usr \
    --with-ldap=shared,/usr \
    --with-mhash=shared,/usr \
    --with-mssql=shared,/usr \
    configure: WARNING: you should use --build, --host, --target
    configure: WARNING: invalid host type:
    checking for grep that handles long lines and -e... /bin/grep
    checking for egrep... /bin/grep -E
    checking for a sed that does not truncate output... /bin/sed
    checking build system type... i486-pc-linux-gnu
    checking host system type... i486-pc-linux-gnu
    checking target system type... config.sub: missing argument
    Try `config.sub --help' for more information.
    configure: error: /bin/sh ../config.sub failed
    make: *** [configure-apache2-stamp] Error 1
    [/CODE]
  • Just to emphasise a point Matt makes above. I recently rebuilt php and at first I got an error when compiling. It turns out that you musn;t have a blank line in the section added to the control file after the first line Package: php5-mssql
    The next line must follow without an intervening blank line, and not as shown in the article as below.

    Package: php5-mssql

    Architecture: any
    Depends: ${shlibs:Depends}, ${misc:Depends}, ${php:Depends}, php5-common (= ${Source-Version})
    ..............

    Remove the blank line and it works.
    Perhaps the article could be amended to make this clear.

    I would also add my voice the the question, why can't Ubuntu build this into the source as standard? It is a pain (even with the excellent instructions of this article) to have to go back and recompile it every so often to allow for other upgrades to the php5 package.
  • Thank you Matt and Robin for catching the extra blank line in the control file. When I first wrote this, it worked as in this article, but when updating my PHP installation on 6.10 more recently, I came across the same issue. I just forgot to update it in this article - thank you for reminding me, and I have fixed the code above.
  • Great Job!
    Thanks a lot for this, very useful guide and easy to follow up.
  • Worked perfectly on a Debian Etch amd64 install too.
    Great Job.
  • Hi Everyone. I went through this tutorial, and all went as expected. However after installation, I ran the following:

    -- Installed the newly compiled packages
    dpkg -i php5-mysql_5.1.6-1ubuntu2.4_i386.deb
    dpkg -i php5-mysqli_5.1.6-1ubuntu2.4_i386.deb
    -- Restarted Apache services
    /etc/init.d/apache2 restart

    This is all on Ubuntu 6.10 Server setup with LAMP during installation. Next I tried to run the follow script to test this, of course I plugged in my server's IP Address and login info, plus a valid database and table.:



    ", "sa", "");
    mssql_select_db ("", $con);
    $sql= "SELECT * FROM ";
    $rs= mssql_query ($sql, $con);
    echo "The field number one is: ";
    echo mssql_result ($rs, 0, 0);
    mssql_close ($con);
    ?



    And now here's what I get:


    Fatal error: Call to undefined function mssql_connect() in /home/webuser/public_html/test.php on line 4

    Any suggestions? Is there anyway to to verify the new packages are installed correctly?

    Thanks for any suggestions.
    Sam Alexander
    samalex@gmail.com
  • Hmm, it jumbled up my code. I pulled the sample code http://us.php.net/mssql , search for comments by "marcos1979ar at yahoo dot com dot ar".

    Thanks --

    Sam
  • @Sam Alex:

    I noticed that you installed "dpkg -i php5-mysql_5.1.6-1ubuntu2.4_i386.deb".
    You need to install the .deb with "mssql" in the name, not "mysql", if you need to get mssql functionality.
    It gets built into its own package, not bundled in with mysql.
    Hope this solves your problem!

    -Robert
  • is this also application to sybase. i'm having problem with sybase_connect. with this solution, do i have to install sybase openclient or the ase packages?
  • Someone please help :)

    I'm getting "configure: error: recode extension can not be configured together with: imap mysql". Apt-get remove php5-imap says the package is not installed. Any help would be greatly appreciated.

    Thanks
  • Aiden, make sure that you don't have any extra spaces or line feeds right after you insert the text in the rules file. I had the same problem using one text editor. I used a different text editor (gedit) and tried it again and it worked.

    Great article, by the way. I've been trying to figure out how to compile GMP with PHP5 in Ubuntu to create a PHP5-GMP package, and this worked perfectly.
  • Thanks for the tips, this method works perfectly on Debian etch as you'd expect. I just switched from Fedora Core 6 and let me assure you, the process for introducing MSSQL functions was just as fiddly! However thanks to your article I was able to find the answer in minutes.
  • I'm getting the following error message:
    tkn@tkn-laptop:~$ sudo apt-get source php5
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to find a source package for php5
    tkn@tkn-laptop:~$

    Any ideas?
    (I'm running Ubuntu 7.10)
  • This worked for me with Ubuntu 7.04. Thank you so much!
  • Hey, many, MANY thanks! How else would I know that Debian ships PHP w/o MSSQL support? Website now works great!

    Regarding the "And go get something to eat." part: On my machine (2 CPUS, 350MHz each, 320MB of RAM) the "eating" part takes over 3 (nearly 4) hours :)))
  • Thanks !
  • Hi I am having problems to use FreeTDS do I need to have a ODBC installed to use with PHP or not?
  • Hi, problem with the `apt-get build-dep php5` step:
    (I'm running Ubuntu 7.10 server with LAMP installed - this is a fresh install, so there's not much else on it.) Linux is a pretty fresh install in my head too.

    When I run `$ sudo apt-get build-dep php5` I get the following errors:
    E: Package libsnmp10-dev has no installation candidate
    E: Failed to process build dependencies

    I had ignored this and proceeded with the rest of the instructions (which are well written and easy to follow - thanks!) so when I ran `sudo dpkg-buildpackage` I got the following:

    dpkg-checkbuilddeps: Unmet build dependencies: [...list omitted...]
    dpkg-buildpackage: Build dependencies/conflicts unsatisfied; aborting.

    Any suggestions?
  • so I poked and prodded and got it sorted out:

    I entered:
    $ sudo apt-get install libsnmp-dev

    ...then tied this again:
    $ sudo apt-get build-dep php5

    ...and followed the rest of the instructions and everything worked! I was very glad to have an excellent guide. Thanks Robert!
  • This was extremely helpful, thank you for taking the time to share it :)
  • A couple of other additions for the rank tyros:

    The debian build directory in PowerPC 6.06.x is:
    /usr/bin/php5-5.2.4/debian

    If editing with vi, while in the rules file, use the command "yy" to YANK the mysql line and the "p" command to copy it again. Edit the copied line. This will help preserve formatting, whitespace, tabs, returns, linefeeds, etc.

Add New Comment

Returning? Login