HOWTO : CakePHP 1.3.7 and Hiawatha 7.4 on Ubuntu Desktop 10.10

This tutorial shows you how to configure a development environment of CakePHP on Ubuntu Desktop 10.10. It can also be used in production for Ubuntu Server 10.10.



Step 0 :



Follow this link to install Hiawatha 7.4 on Ubuntu Desktop 10.10. The security options can be skipped.



Step 0a :



sudo nano /etc/hiawatha/hiawatha.conf



Add the following to "hiawatha.conf".

UrlToolkit {

   ToolkitID = cakephp

   Match ^/app/webroot/ Skip 2

   Match ^/app/(.*) Rewrite /$1 Continue

   Match ^/(.*) Rewrite /app/webroot/$1 Continue

   RequestURI exists Return

   Match (.*)\?(.*) Rewrite $1&$2 Continue

   Match ^/app/webroot/(.*) Rewrite /app/webroot/index.php?url=$1

}




UrlToolkit {

   ToolkitID = cakephp_apps

   Match ^/webroot/ Skip 2

   Match ^/(.*) Rewrite /$1 Continue

   Match ^/(.*) Rewrite /webroot/$1 Continue

   RequestURI exists Return

   Match (.*)\?(.*) Rewrite $1&$2 Continue

   Match ^/webroot/(.*) Rewrite /webroot/index.php?url=$1

}




Step 0b :



sudo nano /etc/hiawatha/enable-sites/mysite



VirtualHost {

   Hostname = localhost, 127.0.0.1

   WebsiteRoot = /var/www/mysite

   StartFile = index.php

   AccessLogfile = /var/log/hiawatha/access.log

   ErrorLogfile = /var/log/hiawatha/error.log

   TimeForCGI = 15

   #UseFastCGI = PHP5

   UseToolkit = cakephp_apps

   DenyBody = ^.*%3Cscript.*%3C%2Fscript%3E.*$

   ExecuteCGI = yes

   PreventCSRF = yes

   PreventSQLi = yes

   PreventXSS = yes

}




Step 1 :



Install CakePHP for github.

sudo apt-get install git



cd /var/www



sudo git clone https://github.com/cakephp/cakephp.git



Step 1a :



sudo nano /etc/environment



Add the following to the end of the line, but within in the " ".



:/var/www/cakephp/cake/console



Step 1b :



. /etc/environment



To see if the captioned path is included or not :



echo $PATH



Step 2 :



Create databases and tables according to your project requirement.



mysql -u root -p



When done, type the following :



quit



Step 3 :



cd /var/www



sudo su



cake bake project myproject



Follows the instruction on the screen.



cd /var/www/myproject



cake bake model all

cake bake controller all

cake bake view all




Exit from the root.

exit



Step 4 :



cd /var/www/myproject/config



sudo cp database.php.default database.php



Change the "login", "password" and "database" accordingly to the MySQL root and password as well as database that you just created.



Step 5 :



Now you can open Firefox to browse your application by typing "localhost" at the address field.



Step 6 :



To configure localization for the application.



sudo apt-get install libwxgtk2.8-dev libwxbase2.8-0 wx-common wx2.8-headers libwxgtk2.8-0



Go to http://www.poedit.net to download the current version 1.4.6.1.



tar -xvzf poedit-1.4.6.1.tar.gz

cd poedit-1.4.6.1




./configure

make

sudo make install




Reboot your computer when necessary.



Step 6a :



cd /var/www/myproject



sudo su



cake i18n



Select "E" and follows the instruction on screen. Then, select "I".



Now, a "default.pot" file is created at the /var/www/myproject/locale.



Exit from the root.

exit



Execute "poedit" and open the file "default.pot". Translate the content to Traditional Chinese and then save to "default.po". A "default.mo" will also be created.



Step 6b :



sudo mkdir /var/www/myproject/locale/zh_TW

sudo mkdir /var/www/myproject/locale/zh_TW/LC_MESSAGES



sudo cp /var/www/myproject/locale/default.* /var/www/myproject/locale/zh_TW/LC_MESSAGES/



Step 6c :



cd /var/www/myproject/config

sudo nano core.php



Append the following line to the core.php :



Configure::write('Config.language', 'zh_TW');



Restart Hiawatha :

sudo /etc/init.d/hiawatha restart



For example :

Open the browser and type "localhost/users", the content will be changed to Traditional Chinese.



*Where "users" is a Controller and table of a database that you just create. "users" is just an example.



That's all! See you.