Hi everyone, today I will explain you how to setup a working copy of the CakePHP framework.
The guide in the cookbook isn't that clear as it should be.
What you should already have:
- A working HTTP server, supporting sessions with mod_rewrite working.
- A working PHP version. (At least 4.3.2)
- A database server.
After installing everything, you need to download the latest CakePHP version. You can dowload it from cakephp.org. Within this tutorial, I am using version 1.3 stable.
3. The installation
Unpack the download .zip file to your webroot directory (the htdocs folder with Apache). Now, check localhost for the result.
If everything went alright, you should get something like this:
You could also get the following:
This means that mod_rewrite is not activated. You should fix this if you want to continue.
4. The configuration
A common website is nothing without a database. That something we are going to do in this chapter: configuring the database connecion.
So, first go to /<webroot>/app/config and rename database.php.default to database.php.
Then open it with your favorite text editor.
To go the end of the file, you should change your settings in here:
var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'user', 'password' => 'password', 'database' => 'database_name', 'prefix' => '' );
Driver can be postgres, sqlite, mssql, mysql, mysqlidb2, or oracle
Persistent means CakePHP should use persistent database connections
Host is the hostname or the IP adress of your database server, this might be localhost as well as 127.0.0.1
Login is the username to log in into your database
Password is the password to log in into your database
Database is the name of the database you are using
Prefix is the prefix of the tables you wish to use. This if only of any use if you are limited to 1 database, and there are also tables who aren't used by CakePHP
Now save that file.
Go to localhost again.
It should give you this:
If you get something else, you might have misnamed or misplaced the database file. Check wether it is in /<webroot>/app/config and it is named database.php. (not database.php.default)
At this moment, you should only have two errors left:
- Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE\cake\libs\debugger.php, line 684]
- Notice (1024): Please change the value of 'Security.cipherSeed' in app/config/core.php to a numeric (digits only) seed value specific to your application [CORE\cake\libs\debugger.php, line 688]
Open /<webroot>/app/config/core.php with your favorite texteditor and search for the following lines:
Change the second parameter to something random. You really should, else it is the same as all the other sites who are using CakePHP.
Do the same now, but only use numbers this time.
This should be your homepage right now:
5. The end
So, I hope you learnt something today, and that you will enjoy the use of CakePHP in the future.