Monday, February 21, 2011

HOWTO : Drupal 6.2 or 7 with Hiawatha 7.4 WebServer on Ubuntu Server/Desktop 10.10

I am going to setup a development environment of Drupal 6.2 or 7 with Hiawatha 7.4 on Ubuntu Desktop 10.10. However, this setting is also suit for production environment on Ubuntu Server 10.10 with a little bit changing.

Step 0 - Installation of Hiawatha

Follow this link to install required packages. You can omit the optional security settings at the moment.

Step 1 - Configuration of Hiawatha

Change the following section to the /etc/hiawatha/hiawatha.conf.

Binding {
   Port = 80
   #Interface = 127.0.0.1
   MaxKeepAlive = 30
   TimeForRequest = 3,20
   MaxRequestSize = 8192
   MaxUploadSize = 30
}


Add the following section to the /etc/hiawatha/hiawatha.conf.

UrlToolkit {
   ToolkitID = drupal7
   RequestURI exists Return
   Match /favicon.ico Return
   Match .* Rewrite /index.php
}


or/and

UrlToolkit {
   ToolkitID = drupal6
   RequestURI exists Return
   Match ^/favicon.ico$ Return
   Match /(.*)\?(.*) Rewrite /index.php?q=$1&$2
   Match /(.*) Rewrite /index.php?q=$1
}


Step 2 - Configuration of virtual host

sudo nano /etc/hiawatha/enable-site/drupal7

Drupal 7 :

VirtualHost {
   Hostname = localhost, 127.0.0.1
   WebsiteRoot = /var/www/drupal7
   StartFile = index.php
   SecureURL = false
   AccessLogfile = /var/log/hiawatha/access.log
   ErrorLogfile = /var/log/hiawatha/error.log
   TimeForCGI = 120
   #UseFastCGI = PHP5
   UseToolkit = drupal7
   #DenyBody = ^.*%3Cscript.*%3C%2Fscript%3E.*$
   ExecuteCGI = yes
   PreventCSRF = yes
   PreventSQLi = yes
   PreventXSS = yes
   TriggerOnCGIstatus = no
}


or

sudo nano /etc/hiawatha/enable-site/drupal6

Drupal 6 :

VirtualHost {
   Hostname = localhost, 127.0.0.1
   WebsiteRoot = /var/www/drupal6
   StartFile = index.php
   SecureURL = false
   AccessLogfile = /var/log/hiawatha/access.log
   ErrorLogfile = /var/log/hiawatha/error.log
   TimeForCGI = 120
   #UseFastCGI = PHP5
   UseToolkit = drupal6
   #DenyBody = ^.*%3Cscript.*%3C%2Fscript%3E.*$
   ExecuteCGI = yes
   PreventCSRF = yes
   PreventSQLi = yes
   PreventXSS = yes
   TriggerOnCGIstatus = no
}


Step 2a :

sudo /etc/init.d/hiawatha restart

Step 3 : Preparation of installation of Drupal

Download the Drupal from her official site. Extract the downloaded file and copy to /var/www/.

sudo tar -xzvf drupal-6.20.tar.gz

or

sudo tar -xzvf drupal-7.0.tar.gz

Step 3a :

Create a directory under /var/www/.

sudo mkdir /var/www/drupal6

or

sudo mkdir /var/www/drupal7

Step 3b :

Copy the files to the /var/www/.

sudo cp ~/drupal-6.20/* /var/www/drupal6

or

sudo cp ~/drupal-7.0/* /var/www/drupal7

Step 3c :

cd /var/www/drupal6

or

cd /var/www/drupal7

Step 3d :

sudo chmod a+w sites/default
sudo mkdir sites/default/files
sudo chmod a+w sites/default/files


sudo cp sites/default/default.settings.php sites/default/settings.php
sudo chmod a+w sites/default/settings.php


Step 3e :

mysql -u root -p

After entered the password, create a database for the installation.

create database drupal;

After that, then quit MySQL.

quit

Step 3f :

Open the browser and type "localhost" at the address field to continue the installation. The database name is "drupal".

When the installation is completed, carry out the following commands.

sudo chmod go-w sites/default
sudo chmod go-w sites/default/settings.php


sudo chmod a-r CHANGELOG.txt

Step 4 : Complete the installation

Drupal 6.2

sudo crontab -e

Add the following :

0 * * * * wget -O - -q -t 1 http://localhost/cron.php

or

Drupal 7

Administration -- Configuration -- System -- Cron

Get the Cron key at Administration -- Reports -- Status report -- Cron maintenance tasks.

sudo crontab -e

0 * * * * wget -O - -q -t 1 http://localhost/cron.php?cron_key=YOURKEY

Step 5 : Localization (Optional)

Download the required localization .po file at the following links.

http://localize.drupal.org/download
http://drupal.org/localize

That's all! See you.

Sunday, February 13, 2011

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.