Tag Archives: apache

Installing MSSQL driver for PHP on Ubuntu

The driver used is FreeTDS, TDS stands for Tabular Data Stream which is an application layer protocol, used to transfer data between a database server and a client. It was initially developed by Sybase Inc. (that’s where the name of the package comes from, for those curious) and later by Microsoft for their relational SQL databases.

In most cases this should work:

sudo apt-get install php5-sybase freetds-common libsybdb5

but if it doesn’t, you probably need to change the TDS version that is in use by the driver. The configuration file is named freetds.conf, and should be in your /etc/ folder.

There are 2 ways for this:

  • Change the global settings, uncomment the global version and set it to the desired one, e.g.
    • tds version = 8.0
  • Or make a new server and set the version explicitly
    • [exampleServer]
      host = server.com
      port = 1433 (this is default MSSQL port)
      tds version = 7.0
If you picked the latter way, then just use exampleServer as the host, e.g.
mssql_connect("exampleServer\\SQLEXPRESS", "user", "password");

Ow, if it still isn’t working, then you have probably forgotten to allow remote connections on your server. From the start menu find and open “SQL Server Surface Area Configuration” then “Surface Area Configuration for Services and Connections”. Find your instance, expand the “Database Engine” tab, select “Remote Connections” and choose the “Using both TCP/IP and Named Pipes” option. After applying, you must restart your instance for the settings to take effect.

For info on TDS versions used in specific MSSQL version you can go here, or just use the direct link and download [MS-TDS].pdf and go to Appendix A. (or just use the newest version, think it’s 8.0 at the moment, it should work fine)

Tagged , , , ,

Apache mod_rewrite setup

This module provides a rule-based rewriting engine to rewrite requested URLs on the fly. Let’s see how to set it up and working in a few steps.

It comes bundled with Apache HTTP Server. To install Apache server on Linux:

apt-get install apache2

or

yum install apache2

then enable the mod (not enabled by default)

a2enmod rewrite

Now we are going to enable application specific settings on the apache server.

  1. Go to /etc/apache2/sites-available/
  2. Open default for editing.
  3. Replace AllowOverride None with AllowOverride All
<Directory /var/www/>
	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Order allow,deny
	allow from all
</Directory>

All left is to check if it’s working. Since we’re going to need PHP install it and restart apache.

apt-get install php5 libapache2-mod-php5
/etc/init.d/apache2 restart

Enter the root directory of the web app you want to use mod_rewrite with.
Make index.php:

<?php
	echo "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
?>

Open/Make a file .htaccess and add the following lines:

RewriteEngine on
RewriteRule ^.*$ index.php

This rule will redirect everything that comes to your web app to index.php inside the same app, and print the full address.

E.g.
A good mod_rewrite cheat sheet can be found here. (courtesy of AddedBytes)

Tagged , ,