Once in a while in my high level application stack, web development world, I am thrown for a loop, and I have to venture down into the bowls of the LAMP stack, or MAMP stack in my case.Â A client for the company I work for jWeb has a desktop application that their entire company uses all day every day.Â This application is a win32 desktop application that is tied to a SQL Server 2005 database.Â We are tasked with building a web application that ties directly to this database, and adds our own custom special sauce to the mix.Â Needless to say the Microsoft Development platform is very windows centric, so I looked to an open source solution.Â As I usually do when I search for a software solution to my problems, I found a champion, FreeTDS.Â This software library allows linux (and therefore Mac OSX... freebsd is not linux I know) to be able to connect directly, not through ODBC, to SQL Server and execute sql statements (Stored Procedures too!!)
To give context to this solution, here is my current developer web server setup:
- Mac Powerbook G4 running OSX 10.4.11
- PHP 5.2.5
- MySql 5.0.18
And here is my SQL Server Set Up
- Windows XP SP3
- SQL Server 2005 Developer Edition
Couple of pitfalls to watch out for here with regards to your SQL Server Development machine:
- Make sure that SQL Server is running an listening via TCP/IP.
- There are multiple ways of running SQL Server (Shared Memory, Named Pipes, TCP/IP, VIA), and it is essential that you have TCP/IP ENABLED.Â I don't know if it comes by default with TCP / IP disabled, but it was on mine so this will kill you before you start if you dont have this sorted out.
- Change these settings by going to Start > Programs > Microsoft SQL Server 2005 > Configuration Tools > SQL Server Configuration Manager
- Click on SQL Server 2005 Network Configuration
- Make sure that TCP / IP is enabled.Â You might have to restart SQL Server from the Services Panel in Windows Control Panel.
- Make sure that you have Windows Firewall allowing port 1433 (default sql server port) or whatever you have it set to.
- Here is the dooosey.Â If you have a Cisco VPN client installed on this machine, there comes with it a Firewall, that will kill all port traffic.Â This runs even when the VPN client is not currently connected.Â To disable this, bring up the VPN client connection window.Â A System tray icon will pop up for Cisco VPN, there is an option for "Stateful Firewall, (Always On)"Â make sure this is UNCHECKED.
Ok, before we can upgrade to FreeTDS and compile it with connections to SQL Server we need to download the FreeTDS library.
Download from here (ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz).
Run these commands:
- cd /usr/local/src
- wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
- tar zxf freetds-stable.tgz
- cd freetds-0.82
- sudo make install
This will install FreeTDS to you /usr/local directory.Â It is important to put it in this location, cause of the following next steps.
Ok now, lets upgrade to 5.2.6 PHP.
Grab the source code from PHP.net.
Follow these steps:
- cd /usr/local/src
- wget http://us2.php.net/get/php-5.2.6.tar.gz/from/us.php.net/mirror
- tar zxf php-5.2.6.tar.gz
- cd php-5.2.6
Ok now here is the fun fun fun.
FreeTDS decided in release 0.82 to change the way that it installs its compiled libs.Â PHP (as of 5.2.6) has not release an official update to this problem.Â FreeTDS.org/news.html has recommended adding dummy files to allow the PHP extensions (mssql, pdo_dblib) to compile correctly.Â This soution is not really solving the problem, so I looked to the PHP developers to see if there is a better solution.
Low and behold, there was!
Two different links:
These two sites discuss the problem in depth.Â The great news, they provided a Patch to solve the problem!
Download it here. (http://overlays.gentoo.org/proj/php/browser/patches/php-patches/5.2.6/php5/freetds-compat.patch?rev=3488&format=raw)
Copy the patch file to your php src directory (/usr/local/src/php-5.2.6).
Run these commands:
- patch -p0 -iÂ /usr/local/src/php-5.2.6/freetds-compat.patch
- Since it is in interactive mode type these two file locations
This will patch the source code problems with FreeTDS 0.82 and PHP 5.2.6
Now compile php (based off of my settings):
- './configure' '--prefix=/usr/local/apache2/php' '--with-zlib' '--with-dom=/sw/' '--with-libxml-dir=/sw/' '--with-xsl=/sw/' '--with-jpeg-dir=/sw' '--with-libtiff-dir=/sw' '--with-png-dir=/sw' '--with-mysql=/usr/local/mysql/' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-curl' '--enable-exif' '--with-ttf' '--with-freetype-dir=/usr/X1186' '--enable-bcmath' '--with-iconv' '--with-gd' '--with-t1lib=/sw' '--enable-gd-native-ttf' '--with-xpm-dir=/usr/X11R6/lib' '--with-openssl=/sw/' '--enable-ftp' '--enable-soap' '--with-xmlrpc' '--with-mysqli=/usr/local/mysql/bin//mysql_config' '--with-mssql=/usr/local' '--enable-zip' '--with-imap=/usr/local/imap' '--with-imap-ssl=/sw' '--with-kerberos' '--enable-mbstring' '--with-mcrypt=/sw' '--with-pdo-mysql=/usr/local/mysql/bin/mysql_config' '--with-pdo-dblib=/usr/local' '--enable-pdo'
- sudo make install
You are off to the races!!!
You can now install open source tools such as:
I plan to use both, but Symfony will allow me to read the schema directly from the SQL Server, and build out ORM objects based on their schema!!!
P.S. Dont forget to restart Apache!!! PHP lives in memory based on the last apache restart, so you wont see changes reflected until you force restart apache.
If the title of this blog post doesn't explain it enough here it is.
This evening, well early morning, I was trying to get XML_RPC to install as the native extension.Â I had previously install PHP 5.1.6 with the mbstring extension enabled to make a pesky phpMyAdmin error about it go away.
Well this time it caught up with me.Â I tries to compile PHP with the same previous settings, now adding XML_RPC.Â Well thank heavens for the bug tracking system at PHP, I found out why I failed.
Here is the link to why it failed.
Hope this can help someone out there! Until next time, happy coding, and remember, always practice safe hex.
I posted earlier on how to Get Rich with PHP5.
In that article Rasmus Lerdorf writes about how to use a certain set of debugging tools as well as PECL packages and database modifications to really tweak some serious speed out of your PHP web application.
I use a powerbook G4 for my PHP hackery, so some of the tools he mentioned are not available with a deault OSX 10.4 installation.Â So I thought, hey lets write a how to install to make this work!!
First lets get a little tool called http_load. Get it here.
Untar the file.
tar zxvf http_load-12mar2006.tar.gz
I recommend copying http_load to a directory like /usr/local/bin or /usr/local/sbin ... basically somewhere in your path
Now lets install kcachegrind.Â For that, follow this link over to the stray notes blog.
Stray Notes Â» Blog Archive Â» Running Kcachegrind on Mac OSX 10.4
Running Kcachegrind on Mac OSX 10.4
Now with both of those installed, you should be ready to go!
Debug your hearts out people!