Developing a blog with CakePHP

Posted on February 11, 2011
If you want to develop a blog from sctrach without using any CMS like WordPress or Drupal, then you’ve come at the right place! In this series, we will understand how to develop a blog using
the CakePHP framework. So, why CakePHP? CakePHP is a robust PHP Framework having an extensive community and excellent documentation. It’s based on the MVC pattern, which makes it really simple to use.
Moreover, you can add numerous functionalities to your web application or blog using this framework.

We would be covering the following topics in this series

  1. Installing and Configuring CakePHP
  2. Understanding MVC
  3. Creating a simple blog
  4. Adding advanced features to your blog – Understanding Models, Views, Controllers in Depth
  5. Understanding Helpers
  6. Ajaxifying comments, adding content summary and Gravatar to your blog
  7. Securing your blog

In this article, we’ll just take a look at installing and configuring CakePHP.

Download the latest version of CakePHP framework from CakePHP.org. Make sure to download the stable release and not the release candidate.
Unpack the contents of the Cake archive inside the “www” folder of wamp or mamp directory.You now have a folder in your document root named after the release you’ve downloaded. We will rename this
folder to “newblog” (or you can have any name of your choice) . The directory structure inside this folder should look something like this:

We would be doing all our work inside the app folder. The cake folder stores all the core functions for CakePHP. Make sure that you do not edit anything inside this folder. The vendors folder is where youíll place third-party PHP libraries you need to use with your CakePHP applications.
You will notice that there are several other folders inside the app folder. We will take a look at each of them as we go on developing our blog.

Configuring Cake PHP

Configuring Cake PHP is pretty easy. Go inside the app –> Config folder and open the database.php.default file with your favorite editor. Scroll down to the following array in the file:

 < php 	var $default = array( 	'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'username',
'password' => 'password',
'database' => 'databasename',
'prefix' => '',
);
?>

Enter your login, password, database name and save the file as database.php. That’s it!

Open you browser and go to http://localhost/cakephp. You should now see the following success page:

However, you might see a colorless page like this:

It means that rewrite_module is not enabled in your Apache Server. To do so, click on the wampserver icon in your system tray and go to Apache–>Apache modules and click on the rewrite_module in the list to enable it. It should work fine after rewrite_module has been enabled.

So, now that you’ve CakePHP up and running, we’ll move on to the next step in subsequent article. Do leave your comments if you’ve any doubts regarding this article.

Leave a Reply

You must be logged in to post a comment.