<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dotvoid.com &#187; freetds</title>
	<atom:link href="http://www.dotvoid.com/tag/freetds/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotvoid.com</link>
	<description>Experiments and thoughts in PHP and javascript</description>
	<lastBuildDate>Tue, 25 May 2010 21:53:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding support for MS SQL Server to PHP in Linux</title>
		<link>http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/</link>
		<comments>http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 14:47:17 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[freetds]]></category>
		<category><![CDATA[mssql]]></category>

		<guid isPermaLink="false">http://www.dotvoid.com/?p=431</guid>
		<description><![CDATA[Adding support for MS SQL Server in PHP is not very difficult. Searching (Google/Bing/whatever) reveals lots of information on how to do this with Windows &#8211; naturally &#8211; but very little on how to go about it using Linux. Most people use precompiled PHP installations and I will show how to add MS SQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>Adding support for MS SQL Server in PHP is not very difficult. Searching (Google/Bing/whatever) reveals lots of information on how to do this with Windows &#8211; naturally &#8211; but very little on how to go about it using Linux. Most people use precompiled PHP installations and I will show how to add MS SQL Server support to a precompiled PHP installation here. Those of you compiling PHP yourselves will probably understand what to do and what not based on the information here as well.</p>
<h2>1. Install FreeTDS</h2>
<p>First download and install FreeTDS from <a href="http://www.freetds.org">freetds.org</a>. Use the following build commands to enable support for MS SQL Server (as root or using sudo).</p>
<pre>./configure --enable-msdblib --prefix=/usr/local/freetds
make &amp;&amp; make install</pre>
<p>Unfortunately you need to tweak the installation somewhat as PHP still checks for files in FreeTDS that is no longer part of the installation. Just make sure these files exist (empty) by issuing the below commmands. (If you use another <em>&#8211;prefix</em> path above you will need to change the path accordingly)</p>
<pre>touch /usr/local/freetds/include/tds.h
touch /usr/local/freetds/lib/libtds.a</pre>
<h2>2. Get the PHP source and compile the mssql extension</h2>
<p>Yes &#8211; you need the <a href="http://www.php.net/downloads.php">complete PHP source</a> even though you already have a precompiled PHP installed. You will not touch your PHP installation and we are not going to compile all of PHP. We need the source to be able to compile the mssql extension.</p>
<p><strong>It is advised to always use the source of the same PHP version you have installed!</strong></p>
<p>Unpack the source and compile the mssql extension. Remember again to change the path accordingly if you installed freeTDS in another location.</p>
<pre>cd php*/ext/mssql
phpize
./configure --with-mssql=/usr/local/freetds
make</pre>
<p>The extension should now be compiled and ready to install. You will find the binary in the immediate sub directory <em>modules</em>.</p>
<h2>3. Install the extension</h2>
<p>Find out where PHP expects to find extension libraries. The simplest way to check this is through the command line.</p>
<pre>php -i | grep extension_dir</pre>
<p>Some distributions use different php.ini files for command line PHP and the PHP web server module. So it might be good to double check using the function <a href="http://www.php.net/phpinfo">phpinfo()</a> in a php script loaded through the web server (using your browser is easiest).</p>
<pre>&lt;?php phpinfo();</pre>
<p>Then search for <em>extension_dir</em> in the configuration information displayed. For example, on my laptop running Ubuntu, the path is <em>/usr/lib/php5/20060613+lfs</em>.</p>
<p>Continuing from above without having moved away from the directory where you compiled your mssql extension.</p>
<pre>cp modules/mssql.so /usr/lib/php5/20060613+lfs/</pre>
<p>The extension is in the right place and all you have to do now is to make sure PHP actually loads it. To do this add the extension somewhere in the php.ini file. For example in the section Dynamic Extensions to keep it somewhere logical.</p>
<pre>extension=mssql.so</pre>
<p>3. Restart the web server</p>
<p>If using the Apache 2 web server you would normally issue</p>
<pre>/etc/init.d/apache2 restart</pre>
<h2>4. Post installation</h2>
<p>Well that&#8217;s about it. You should have a workable mssql extension added to your PHP installation. You should be able to continue using your platforms chosen way of upgrading PHP without affecting the MS SQL Server support.</p>
<p>However, you might need to dig into the <em>freetds.conf</em> file. If you have followed my steps without altering the installation path you will find the freetds.conf file in <em>/usr/local/freetds/etc/freetds.conf</em>.</p>
<p>Sometimes it is difficult getting the connection work without adding it to the the freetds.conf. Especially since you may have to use different values for the tds version directive depending on the MS SQL Server version. Examples:</p>
<pre>[logisticsServer]
host = ntmachine.localdomain
port = 1433
tds version = 7.0

[intranetServer]
host = 192.168.1.145
port = 1433
tds version = 4.2</pre>
<p>Again. Check that you are using the correct freetds.conf file and that you are using the correct tds version! More information on this at <a href="http://www.freetds.org">freetds.org</a>. This and the above mentioned &#8220;missing files&#8221; that PHP is looking for are the two most common pitfalls.</p>
<p>Good luck!</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/&amp;title=Adding+support+for+MS+SQL+Server+to+PHP+in+Linux" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/&amp;t=Adding+support+for+MS+SQL+Server+to+PHP+in+Linux" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/&amp;title=Adding+support+for+MS+SQL+Server+to+PHP+in+Linux&amp;summary=Adding%20support%20for%20MS%20SQL%20Server%20in%20PHP%20is%20not%20very%20difficult.%20Searching%20%28Google%2FBing%2Fwhatever%29%20reveals%20lots%20of%20information%20on%20how%20to%20do%20this%20with%20Windows%20-%20naturally%20-%20but%20very%20little%20on%20how%20to%20go%20about%20it%20using%20Linux.%20Most%20people%20use%20precompiled%20PHP%20installations%20and%20I%20will%20show%20how%20to%20add%20MS%20SQL%20&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/&amp;title=Adding+support+for+MS+SQL+Server+to+PHP+in+Linux" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Adding+support+for+MS+SQL+Server+to+PHP+in+Linux+-+http://b2l.me/wt3t2&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2010/01/adding-support-for-ms-sql-server-to-php-in-linux/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
