Sunday, November 16, 2008

Install mysql in PowerPC Mac Mini and make php-mysql works

The problem for mysql server in Mac OS X powerpc platform is that there is no binary build for package format (.dmg) for Leopard and the tar.gz binary does not work with the default php5 which uses the unix socket at /var/mysql/mysql.sock plus there is no LaunchDaemon plist. Either you have to change the etc/php.ini or build the mysql server from source.

This guide shows how to build from source

(1) Choose the mirror site and download the source tar.gz file

(2) untar and unzip it

tar -xzvf mysql-5.1.29-rc.tar.gz

(3) config, make and install (make sure you have Xcode installed already)

cd mysql-5.1.29-rc

scipt: Select all

CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer \
-felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
--with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile \
--enable-shared --with-unix-socket-path=/var/mysql/mysql.sock \

sudo make install

(4) create database

sudo chgrp -R mysql /usr/local/mysql
cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var

(5) create unix-socket directory

sudo mkdir -p /var/mysql
sudo chown -R mysql /var/mysql

(6) create LaunchDaemons in /Library/LaunchDaemons/com.mysql.mysqld.plist so that it can autostart

sudo vi /Library/LaunchDaemons/com.mysql.mysqld.plist

and put this in the file

com.mysql.mysqld.plist: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

(7) start mysql server and restart apache server

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo apachectl restart

and if you want to manually stop the mysql server

sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

(8) create path in ~/.bash_login

vi ~/.bash_login

and put this

export PATH="/usr/local/mysql/bin:$PATH"

run this

. ~/.bash_login

(9) create root password with mypassword
mysqladmin -u root password mypassword

(10) create databse in mysql

mysql -u root -p
> CREATE DATABASE database_name DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
> GRANT ALL PRIVILEGES ON database_name.* TO username@localhost IDENTIFIED BY 'password';

Wednesday, November 5, 2008

[How-to] Install Ubuntu 8.1 in Virtual PC2007

Install Ubuntu in Virtual PC 2007 may have screen display problem (similar to Fedora) and fail during installation.

Here are the steps to successfully install Ubuntu in VPC2007 and this is the easiest method (as there are many tricks to do it in the past) that I discovered.

(1) Setup the new Virtual Machine in VPC 2007 and mount the iso image (ubuntu-8-1.10-desktop-i386.iso).

Please check the size and MD5 Sum to ensure the iso image is successfully downloaded.

MD5 (ubuntu-8-1.10-desktop-i386.iso) = 24ea1163ea6c9f5dae77de8c49ee7c03
ubuntu-8.10-desktop-i386.iso 699M

(2) Inside the Ubuntu Install Screen, first Press "F4" and Select "Safe Graphics mode"

(3) Then press down arrow and highlight the menu "Install Ubuntu". (highlight only and don't press Enter)

(4) Press "F6" to bring up the "Other Options"
Then type "vesa vga=771" at the end of the option line
Then Press "Enter", the installation will start instantly.

Note: If you want other resolution, you can try say vga=791 instead of vga=771

I did not try all these, some of them might not work. The codes are listed out for reference only.

vga=769 means 600x480 8 bits color
vga=785 means 600x480 16 bits color
vga=786 means 600x480 24 bits color
vga=771 means 800x600 8 bits color
vga=788 means 800x600 16 bits color
vga=789 means 800x600 24 bits color
vga=773 means 1024x768 8 bits color
vga=791 means 1024x768 16 bits color
vga=792 means 1024x768 24 bits color

(5) After installation, it will prompt to restart. But the restart might not work and you have to manually reset the VM in VPC 2007 as in step (6) below

(6) Then release the mounted iso image and in VPC 2007 menu to reset the VM in VPC 2007, that is, VPC menu choose -> Action -> Reset

(7) Enjoy using Ubuntu in VPC 2007, and you can start installing other packages / sdks for development following my other guides in this blog

(8) To solve the sound problem, start the Terminal in Ubuntu and type

sudoedit /etc/rc.local

At the end of the # lines, but before “exit 0″, type on a new line (again without quotes) “modprobe snd-sb16″
Ctrl + O to write out, enter to accept the name, Ctrl + X to close.

Monday, November 3, 2008

Personal Installation Guide for Ubuntu 8.10 in VMWare for iPhone / Android SDK development

(1) Download ubuntu-8-1.10-desktop-i386.iso (32 bit Intel i386 Desktop)
MD5 (ubuntu-8-1.10-desktop-i386.iso) = 24ea1163ea6c9f5dae77de8c49ee7c03

Installation is very easy just mount the iso image in the VMWare, and everything goes default. then install VMWare tools. If network does not work try command "sudo dhclient"

If you want to install Ubuntu 8.10 in Virtual PC 2007
see this guide

(2) VMWare Settings : Harddisk Size 8G, Ram 512MB

(3) Purpose : sdk development on iPhone / Android
Allows samba mount, ssh / scp access
apache2 server with php5 support for sqlite3 db

(4) Add root access for useraccount without password (this does not work, I don't know why, so you still need password)
Ubuntu default root disabled, so you can disable password input by editing etc/sudoers
sudo visudo
Add this line (e.g. sdkuser is the default user account)

(5) install build essential packages so that you can compile llvm-gcc for iPhone toolchain SDK2.0

sudo apt-get update
sudo apt-get install build-essential bison flex

(6) install server packages so that you can have local webserver and ssh and samba server

sudo apt-get install apache2 php5 libapache2-mod-php5 php5-cli php5-common php5-cgi php5-sqlite openssh-server samba

Install php5-sqlite3
sudo apt-get install php-db php-pear
sudo dpkg -i php-sqlite3_0.5-1_i386.deb

(7) Create Project folder for smb mount (guest login ok) so that you can use windows / smb mount the virtual machine folder

(assume sdkuser is the default user account)

mkdir -p /home/sdkuser/Projects
chmod 777 /home/sdkuser/Projects

sudoedit /etc/samba/smb.conf

and add the followings at the end

smb.conf: Select all

comment = Projects Folder Share
writable = yes
locking = no
path = /home/sdkuser/Projects
public = yes
browseable = yes
guest ok = yes
create mask = 0666
directory mask = 0777

Note : you have to restart samba server to make the new configuration effective
sudo /etc/init.d/samba restart

Update for Ubuntu 9 /10
You have to edit
sudo vi /etc/apt/sources.list
and uncomment these in order to install sun-java6-jdk
deb maverick partner
deb-src maverick partner

(8) install jdk6 so that you can compile Andriod app

sudo apt-get update
sudo apt-get install sun-java6-jdk

(9) Download Android SDK from

install in ~/Android/

mkdir -p ~/Android/
sudo unzip ~/Desktop/ -d ~/Android/
sudo chown -R sdkuser:sdkuser ~/Andriod

Update for android-sdk 2.0 or above

mkdir -p ~/Android/
tar xzvf ~/Downloads/android-sdk_r12-linux_x86.tgz
~/Android/tools/android update sdk

create sd card & test emulator

~/Android/android-sdk-linux_x86-1.0_r1/tools/mksdcard -l SD500M 500M ~/Android/sd500m.img

~/Android/android-sdk-linux_x86-1.0_r1/tools/emulator -datadir ~/Android -scale 0.7 -sdcard ~/Android/sd500m.img &

(10) Download and Install Eclipse 3.4.1 (you can't use the debian package eclipse which is 3.2 only)

install in /usr/lib

cd /usr/lib; sudo tar -xzvf ~/Desktop/eclipse-java-ganymede-SR1-linux-gtk.tar.gz

Update for eclipse-java-helios

mkdir -p ~/Android/
cd /usr/lib; sudo tar -xzvf ~/Downloads/eclipse-java-helios-SR2-linux-gtk.tar.gz

Add main menu & icon for eclipse in GNOME

sudoedit /usr/share/applications/eclipse.desktop

and save this

eclipse.desktop: Select all

[Desktop Entry]
Comment=Develop applications in a variety of different programming languages

There is no eclipse icon in the download file eclipse-java-ganymede-SR1-linux-gtk.tar.gz. You can get it from eclipse 3.2.2 package
and install it manually

download the eclipse 3.2.2 package

extract the package and copy the icons to /usr/share/pixmaps/
dpkg -x eclipse_3.2.2-5ubuntu2_i386.deb tmp
sudo cp tmp/usr/share/pixmaps/* /usr/share/pixmaps/
rm -fr tmp

Install Android sdk plug-in for Eclipse
(based on
add this site and install in Eclipse

Edit Eclipse's preference for Andriod (Window -> Preferences -> Android)

SDK location

emulator options
-scale 0.7 -sdcard /home/sdkuser/Android/sd500m.img

Test HelloActivity in Eclipse
(a) Create a New Android Project in Eclipse (File -> New -> Project... -> Android -> Android Project)
(b) Choose Create project from existing source and browse to ~/Android/android-sdk-linux_x86-1.0_r1/samples/HelloActivity
(c) Run HelloActivity as Android Application
(d) Then the emulator will start Hello, World! will be on the emulator screen

Note: Please don't set the workspace of Eclipse to the sample project folder
or else you will get error when importing project from existing source

Update for iphone toolchain4 for SDK4.x+
You need to install clang 2.7 or above in Ubuntu 8.10


(11) Install iPhone llvm-gcc and toolchain SDK2.0
Refer to this article and download the file UpgradeToolChain2.tgz and build the llvm-gcc for iPhone

Install ldid in Linux, so that you can fake codesign it

cd ~/Projects
tar -zxf ldid-1.0.476.tgz
cd ldid-1.0.476
g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c
sudo cp -a util/ldid /usr/bin

or here

updated ldid source

Updates : If you compiled it in cgywin, you need to add (uint32_t) in the source code ldid.cpp that has ambiguous overload call error message like this

error: call of overloaded 'Swap(int)' is ambiguous

If you need to codesign the iPhone binary in Linux add this to your build script

export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)

(12) test apache2 and php so that you can see the php info page in the local webserver

In Firefox browser of Ubuntu enter this address

enable php5 (sometimes you need this)
a2enmod php5

restart apache server
sudo /etc/init.d/apache2 restart

create this test.php script in /var/www

sudo chown -R sdkuser:sdkuser /var/www
echo "<?php phpinfo(); ?>" > /var/www/test.php

and see the php info in Firefox browser of Ubuntu

(13) create sqlite3 db
sqlite3 test.db: Select all

sudo chown -R sdkuser:sdkuser /var/www
cd /var/www
sqlite3 test.db
sqlite> create table test (id integer primary key, value text);
sqlite> insert into test (value) values('eenie');
sqlite> insert into test (value) values('meenie');
sqlite> insert into test (value) values('miny');
sqlite> insert into test (value) values('mo');
sqlite> select * from test;
sqlite> .exit

and test sqlite3 & php5-sqlite3 by using testdb.php script to test the access to sqlite3 db on webserver

(14) testdb.php
testdb.php: Select all

<// Version 0.01
<head><meta http-equiv="Content-Type" content="text-html; charset=UTF-8" /></head>
<title>iPhone Database</title>

$ip_dbpath[] = '/var/www/test.db';

// $ip_dbpath[] = '/var/www/sms.db';
// $ip_dbpath[] = '/var/www/call_history.db';
// $ip_dbpath[] = '/var/www/notes.db';
// $ip_dbpath[] = '/var/www/AddressBook.sqlitedb';
// $ip_dbpath[] = '/var/www/Calendar.sqlitedb';

// db location in iPhone /private/var/mobile/Library/SMS/sms.db
// db location in iPhone /private/var/mobile/Library/CallHistory/call_history.db
// db location in iPhone /private/var/mobile/Library/Notes/notes.db
// db location in iPhone /private/var/mobile/Library/AddressBook/AddressBook.sqlitedb
// db location in iPhone /private/var/mobile/Library/Calendar/Calendar.sqlitedb

$ip_dbdesc[] = 'test';

// $ip_dbdesc[] = 'SMS';
// $ip_dbdesc[] = 'Call History';
// $ip_dbdesc[] = 'Notes';
// $ip_dbdesc[] = 'Address Book';
// $ip_dbdesc[] = 'Calendar';

$ip_query[] = 'SELECT * from test order by 1';
// $ip_query[] = 'SELECT date, address, text FROM message order by 1 desc, 2;';
// $ip_query[] = 'SELECT date, address, duration FROM call order by 1 desc;';
// $ip_query[] = 'SELECT creation_date, data, title FROM Note inner join note_bodies on Note.ROWID = note_bodies.note_id order by 1;';
// $ip_query[] = 'SELECT First, Last, Middle, CreationDate, ModificationDate FROM ABPerson;';
// $ip_query[] = 'SELECT start_date, end_date, summary, location, description FROM Event order by 1, 2;';

// $dbcount = sizeof($ip_dbpath);
// if you uncomment the above db & query and add copy the iPhone db , you can list out the content of sqlitedb of iPhone
$dbcount = 1;

for ($dbnum=0;$dbnum<$dbcount;$dbnum++){

try {
$dbpath = $ip_dbpath[ $dbnum ];
$dbh = new PDO('sqlite:'.$dbpath);
$query = $ip_query[ $dbnum ];
$stmt = $dbh->prepare($query);
catch (PDOException $e) {
die("Could not open database" . $e->getMessage());
$colcount = $stmt->columnCount();
echo "<h1>". $ip_dbdesc[ $dbnum ] . "</h1>";
echo "<table cellpadding=10 border=1>";

for ($i=0;$i<$colcount;$i++) {
$meta = $stmt->getColumnMeta($i);
echo "<td>".$meta["name"]."</td>";

while ($row = $stmt->fetch()) {
echo "<tr>";
for ($i=0;$i<$colcount;$i++) {
$meta = $stmt->getColumnMeta($i);
if ($meta["native_type"] == "null") {
echo "<td> </td>";
elseif (preg_match("/date$/i", $meta["name"])) {
echo "<td>". date("j M Y D g.i a", $row[$i])."</td>";
elseif (preg_match("/[call|sms]$/i", $meta["name"]) && $meta["name"] == "address" && strlen(rtrim($row[ $i])) == 8) {
echo "<td><A href='Tel:".$row[$i]."'>".$row[$i]."</A></td>";
else {
echo "<td>".$row[ $i]."</td>";
echo "</tr>";
echo "</table>";

(15) Enjoy building app
Why to install apache2, php5 and php5-sqlite3 in Ubuntu ?

Because both iPhone and Andriod SDK use sqlite3 as database engine.
Webserver can be served for many purposes when testing including http get/post access and cydia repository as well.

Additional Notes
If you need to install flash plugin in firefox
sudo apt-get install flashplugin-nonfree

If you need to install java plugin in firefox
sudo apt-get install sun-java6-plugin

If you need to install xpdf
sudo apt-get install xpdf-reader

If you need to install jedit
sudo apt-get install jedit

If you want to install mysql, it will promot you to enter the root password of mysql during installation
sudo apt-get install mysql-server php5-mysql

use this to login mysql
mysql -u root -h localhost -p

To change sql root password from oldpassword to newpassword
mysqladmin -u root -poldpassword password newpassword

Create a new database (newsdb) and new user (newsuser) with password (newspassword)

mysql -u root -p
> GRANT ALL PRIVILEGES ON newsdb.* TO newsuser@localhost IDENTIFIED BY 'newspassword';