It is easier to get PHP on Ubuntu to connect to MSSQL than it is to get PHP on Windows.
I would not normally believe such a thing until I tried to setup a pre-existing install of PHP on Windows missing any MSSQL extensions. Looking through Google to find information was less than quick and I found myself wanting to go back to my old faithful Ubuntu server, but how?
Here are my 10 quick steps to get PHP seeing MSSQL:
There are some basic software we will need to grab using apt-get, then we will install them and modify the php.ini file to update the new extension. I will go over the process below on how to install and in what order but before we do that I will give you a brief description of what we are doing.
We will need to get the source for PHP, we will also need the PHP Development packages. We will be installing FreeTDS and then editing our php.ini file. Lastly restarting Apache to complete the process.
For the rest of this we will assume you have ( sudo su -) so you do not need to sudo each cmd, but if not then add sudo where it applies. We are also assuming you already have a working php system and only need to add MSSQL functionality.
- apt-get source php5 – This will install the PHP source in the the current directory that you are in.
- cd php5-5.3.2/ext/mssql – This will place you in the PHP source directory for MSSQL. You may need to edit the directory path as 5.3.2 was the version as of this document and may not be the same version you are installing.
- apt-get install freetds-dev – This installs the extra libraries we will need for MSSQL
- apt-get install php5-dev – This installs the application (phpize) which we will use next to help build the MSSQL extension.
- phpize – Run this while inside the (/ext/mssql ) directory
- ./configure –with-mssql – This creates the MakeFile we will need to build the extension from source.
- make – This cmd builds the extension.
- cd modules – move in to the module directory.
- cp mssql.so /usr/lib/php5/20090626 – Here you will need to pay close attention to the last directory here. This will very based on your version so change the numbers to fit what you have in your (/usr/lib/php5) directory.
- vi /etc/php5/apache2/php.ini – We want to go down to where you will find (Dynamic Extensions) and add on a new line the following -> extension = mssql.so then save and close the vi session ( Esc : wq)
You are all done, just restart Apache and test your mssql_connect