How to install cakephp on wamp server


July 31, 2012

How to install cakephp on wamp server

Downloading – Stable or Alpha Version

Step one is downloading CakePHP . The first problem that you’ll run into is that there are two (2) versions to pick from: ** Stable 1.1 and Alpha 1.2 **. When I first started out, I needed to use CakePHP for a project instantly, so I decided to with the stable version because the word alpha scared me a little bit. I mean, it’s not even beta yet.

That was my big mistake. A lot of seasoned CakePHP developers will tell you that the alpha version is ready to go and can (and has been) used in production environments. There is of course the slim chance that some key function or component might change slightly, and you application may break on an upgrade for the alpha version, but that’s a chance that I’m willing to take. The ** alpha version has a lot more in place (emailing templates, authentication, pagination of results **, etc), that it just makes everything worthwhile. Also, a lot of the newer tutorials you’ll find make specific reference to version 1.2. And let’s face it, version 1.2 is just way cooler.

If you’re just starting out, ** I still recommend the alpha version 1.2 **, because by the time you become well versed and need to crank out a web application or site version 1.2 may well be stable.

Upload to Server

One of the key things I was looking for with a PHP framework is compatibility with PHP 4.0. Some of my clients are on older servers and it’s harder to get someone who is already paying for a host to switch just because you said so. Here are the server requirements from the CakePHP manual :

  • An HTTP server (like Apache) with the following enabled: sessions, mod_rewrite (not absolutely necessary but preferred)
  • PHP 4.3.2 or greater. Yes, CakePHP works great in either PHP 4 or 5.
  • A database engine (right now, there is support for MySQL, PostgreSQL and a wrapper for ADODB).

The manual recommends various methods of installation for development purposes and production environments. These recommendations are all well and good if you have your own server, but some things are simply not configurable with the shared hosts that most of us use these days.

I personally don’t see a problem with the development setup. The take the CakePHP folder and dump it the the www root of the site (if it’s the main site of course) or a subdirectory. The one tweak I would make, if your host allows, is to point your www root for that domain to the app/webroot/ folder.

These are recommended for security purposes, but I haven’t seen a problem with any installation that I’ve had. As a matter of fact, this is one of the few times that I’ve heard someone recommend this type of setup. Even well established packages like WordPress , SMF, Zen Photo, phpBB, etc just need you to dump files in a folder.

There is something to be said about the recommended setup though. If you happen to run multiple installations of CakePHP and have different applications, in theory, all of them can share the same CakePHP base code and you’d have different application folders. But for right now, this is just a get up and get started guide. The only thing that you need to ensure is that the app/tmp directory and all subdirectories are writable.

Configuration

Everything you’ll need is in the app/config folder. The file core.php houses, well, core configuration settings. Here are a few of the main ones:

?
1 define('DEBUG', 3);
set’s the debug level. Use 0 for production

?
1 define('CAKE_ADMIN', 'admin');
You’re almost always going to need this, so you might as well uncomment it now. This sets up admin routing so you can have urls like site.com/admin/events/

?
1 define('CAKE_SESSION_STRING', 'DYhG93guVoUubWwiR2G0FgaC9mi');

A random string used for CakePHP sessions. You need to change this into something unique or you might potentially leave holes in your app

Then we have the database.php file. Modify the following to suite your database configuration:

?
1 var $default = array(
2 'driver' => 'mysql',
3 'persistent' => false,
4 'host' => 'localhost',
5 'login' => 'username',
6 'password' => 'passowrd',
7 'database' => 'database name',
8 'prefix' => ''
9 );

I personally have a host that limits the number of MySQL databases that you’re allowed, so I’m forced to dump everything into one database. This makes the prefix option invaluable to me.

Lastly we have routes.php. This file is used to for URL routing. Consider the following:

?
1 Router::connect('/', array('controller' => 'contents', 'action' => 'view', 'home'));

This is going to route the homepage site.com/ to my contents controller and run the viewaction and pass to this the parameter home. This is the same as going to: site.com/contents/view/home/. We can also do some other marvelous things with routing, but I’ll save those for later.

Depending on what your setup is and where you host, you might have to make modifications to the .htaccess file. I haven’t narrowed down an explanation yet, but on various shared hosts, adding “RewriteBase /” solves a lot of problems, just keep that in mind.