Friday, July 31, 2009

Quick guide on setting up a CakePHP project

Read the updated version for CakePHP 1.3 here

Create the database

First we create a database called authcake. Rename it as needed, but be sure to change it in the examples below.

user@host:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 385
Server version: 5.0.67-0ubuntu6 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database authcake;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
-> ON authcake.*
-> TO 'authcake'@'localhost' IDENTIFIED BY 's3cr3t';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Download CakePHP

Next we download the latest CakePHP from http://cakephp.org/. The version used in this example is 1.2.3.8166 Stable and the file cake_1.2.3.8166.tar.gz is placed in the homedir.

Extract download

CakePHP will be installed in the ~/public_html/authcake directory, which is served using mod_userdir. The directory will be available at the URL http://yourhost/~username/authcake . Of course it is possible to install it to another location, but be sure to change the locations in the commands below accordingly.

Make sure mod_rewrite is working and that the AllowOverride property for ~/public_html is set to All.

user@host:~$ cd ~/public_html
user@host:~/public_html$ tar xvzf ~/cake_1.2.3.8166.tar.gz
cake_1.2.3.8166/
..........
.  SNAP  .
..........
user@host:~/public_html$ mv cake_1.2.3.8166/ authcake
user@host:~/public_html$ cd authcake/

Configure Database

Rename the default database config and change the values to match those on your system.

user@host:~/public_html/authcake$ mv app/config/database.php.default app/config/database.php
user@host:~/public_html/authcake$ vi app/config/database.php

Update Configuration

Change the setting Security.salt in the core.php file

user@host:~/public_html/authcake$ vi app/config/core.php

Set Permissions

The tmp dir needs write permissions. Use chmod -R 777 only in development environments. In production environments the owner of the files need to be the user running the webserver.

user@host:~/public_html/authcake$ cd app/
user@host:~/public_html/authcake/app$ chmod -R 777 tmp/
user@host:~/public_html/authcake/app$ cd ..

The CakePHP installation should now ready and available.

The result in the browser should look like this:


Friday, July 10, 2009

Easily create a RAM-disk in Linux

This command creates a 2GB RAM-disk and mounts it to /tmp/space.
$ mkdir /tmp/space
$ sudo mount -t tmpfs tmpfs /tmp/space -o size=2G,nr_inodes=200k,mode=01777
You should now have an extra 2GB storage device.
 $ df -h | grep space
$ tmpfs                 2.0G     0  2.0G   0% /tmp/space
You access the temporarily device by it's mountpoint /tmp/space. Needless to say, once you unmount this volume (for instance, with a reboot), the data on it will be gone. Use with care! :) Tested on Ubuntu, should work with any 2.4 or 2.6 kernel...