The Way Of Life: Ubuntu-Apache-PHP-FreeTDS-MSSQL

Friday, March 30, 2012


This article is part two of my previous articles that is Android-PHP-Microsoft SQL Server. This time i will share, how to make web server in the "real life", this web server used Linux Ubuntu as operating system. Why I call "real life", because we are not used XAMPP again like on Windows at development phase. We will make real web server on Linux to handle data from SQL Server to our android application. Using the web server as a link between the android and MSSQL has several problems that we must understand.

You must understand that web server respond is not as fast ADO connection on desktop programming. Second, web server used internet connection that have up and down speed connection that we cannot guarantee. With that problems, you must learn how to make a several query in SQL that handle several process on android, and make on one "single shoot" to Microsoft SQL Server to reach "Speed of Light". The point is how to make minimum data traffic between Android and MS SQL Server. And the last you need to secure data path with cryptographic protocol (SSL) to prevents Man In The Middle Attack.

Okay, lets began our project, first we must collecting our tools :
1. Linux Ubuntu ver 11.10 you can download the ISO here, and burn to CD.
2. Apache Web Server for Linux.
3. PHP.
4. FreeTDS, to get PHP seeing Microsoft SQL Server.
5. Microsoft SQL Server as database server.

First, we must fresh install Linux Ubuntu on our Linux Box. I think I do not need to explain on this part.

And then , we must install apache web server on our Linux Box, with several command on terminal windows.

# sudo su
# apt-get install apache2

then install PHP 5

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

Install FreeTDS to get PHP seeing Microsoft SQL Server, i found really good and simple tutorial and i was added several steps, as below:

1. mkdir source and then cd source
2. apt-get source php5
3. tar -xf php5_5.3.6.orig.tar.gz
4. cd /php-5.3.6/ext/mssql
5. apt-get install freetds-dev

6. apt-get install php5-dev
7. phpize
8. ./configure –with-mssql
9. make
10. php -i grep | extension_dir

10. cp /modules/ /usr/lib/php5/20090626+lfs
11. nano /etc/php5/apache2/php.ini and add on a new line the following ; extension = then save
12. /etc/init.d/apache2 restart

13. nano /etc/freetds/freetds.conf and add this on the end of the file :

host =
port = 1433
tds version = 8.0 

14. and test your mssql_connect , on my php script i was select sysobjects table on Microsoft SQL Server, and if it return values from mssql_rows_affected then display "SUCESS" as the picture below.

Have Fun! Someday i will show you real android application that i make. There are many uses of Android Applications, such as mobile POS, e-prescribing, if your are a doctor, you can prescribed from anywhere in the world with android apps, if you are a boss you can check the balance sheet and income statement in the Hawaiian beach with drinking coconut ice with android apps.If you have any questions, you can email me at , or via comments on this blog.

picture take from here
related links:

Android - PHP - Microsoft SQL Server

How Fast is JSON on Android? 

Could Not Find

A Beginner’s Guide to SQL: A MySQL Tutorial

Labels: , , , ,


Anonymous Anonymous said...

I follow all your instructions and mssql only works from command line using php5 command with www-data user but no works with browser.

What is wrong?

I have checked filesystem permissions in freetds directory

12:37 AM  
Blogger boed said...

Plz send me your php script, if the connection(php command) is works,it will works on the browser.

7:52 AM  
Blogger boed said...

email from mito:


I uninstall manual installation of freetds and installed from apt-get only freetds-dev then I compilled PHP again

Thank you so much.


6:04 AM  
Anonymous Anonymous said...

You are a superman. thanks.

4:49 AM  

Post a Comment

<< Home