I personally choose not to use Micro$oft products when it is possible, but sometimes the choice is not given. For these unfortunate who have to deal with SQL Server 2008 (or 2005), here is how to get around without too many swear words and avoid licensing costs.
Requirements
- Windows Vista (Win XP should do also)
- .Net Framework 3.5 SP1
- Windows Installer 4.5
- Windows PowerShell 1.0
- MS Core XML Services (MSXML) 6.0
Note: You need to have genuine windows copy to download PowerShell from Microsoft website; however it is possible to find it elsewhere if you google around.
Setup SQL Server
- Download and install MS SQL Server Express 2008 with Advanced Services and choose the following options:
- Single instance Install (not clustered !)
- Name the instance “SQLExpress”
- In the options box choose “SQL Server”, and “Management Studio” (do not install full-text search, as it requires clustering)
- Set the Server Service Account Name to “NT AUTHORITY\NETWORK SERVICE”, auto
- Set the SQL Server Browser to “NT AUTHORITY\NETWORK SERVICE”, manual
- Choose mixed mode authentication
- Set SQL Server to listen on TCP port.
- Start “SQL Server Configuration Manager”
- Network Configuration -> Protocols : enable “Named Pipes” and “TCP/IP”
- Right-click “TCP/IP” -> Listen All = Yes”
- In tab “IP addresses” -> Section IPAll -> TCP Dynamic Ports = 1433
- Repeat these steps for SQL Native Client.
- Restart SQL Server
- Create your database and set the owner to user ‘sa’, and change the user sa password.
Setup PHP
This assumes you have wamp installed, otherwise just change the path.
- Download the good version of ntwdblib.dll (2000.80.194.0)
- Overwrite C:\wamp\bin\apache\apache2.2.8\bin\ntwdblib.dll
- Overwrite C:\wamp\bin\php\php5.2.6\ntwdblib.dll
- Enable php_mssql.dll in
php.ini
Restart Apache
$server = 'BANGKOK\SQLEXPRESS'; // The format is "HOST\SERVERNAME[,PORT]" $username = 'sa'; mssql_connect($server, $username, $password);
Debugging
- You can test if SQL Server is listening on port 1433 by using NMap/Zenmap for Windows to do an “Intense scan, all TCP ports” on localhost, and you should see port 1433 open.
- When trying to log within PHP you should see an entry in the log file:
c:\program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Log\ERRORLOG
I hope this will save you some time and swears!