Content Management Tutorial

This tutorial will walk you through the creation of a simple CMS application. To start with, we’ll be installing CakePHP,creating our database, and building simple article management.

Here’s what you’ll need:

  • A database server. We’re going to be using MySQL server in this tutorial.You’ll need to know enough about SQL in order to create a database, and runSQL snippets from the tutorial. CakePHP will handle building all the queriesyour application needs. Since we’re using MySQL, also make sure that you havepdo_mysql enabled in PHP.
  • Basic PHP knowledge.Before starting you should make sure that you have got an up to date PHPversion:
  1. php -v

You should at least have got installed PHP 7.2.0 (CLI) or higher.Your webserver’s PHP version must also be of 7.2.0 or higher, andshould be the same version your command line interface (CLI) PHP is.

Getting CakePHP

The easiest way to install CakePHP is to use Composer. Composer is a simple wayof installing CakePHP from your terminal or command line prompt. First, you’llneed to download and install Composer if you haven’t done so already. If youhave cURL installed, it’s as easy as running the following:

  1. curl -s https://getcomposer.org/installer | php

Or, you can download composer.phar from theComposer website.

Then simply type the following line in your terminal from yourinstallation directory to install the CakePHP application skeletonin the cms directory of the current working directory:

  1. php composer.phar create-project --prefer-dist cakephp/app cms

If you downloaded and ran the Composer Windows Installer, then type the following line inyour terminal from your installation directory (ie.C:\wamp\www\dev\cakephp3):

  1. composer self-update && composer create-project --prefer-dist cakephp/app cms

The advantage to using Composer is that it will automatically complete someimportant set up tasks, such as setting the correct file permissions andcreating your config/app.php file for you.

There are other ways to install CakePHP. If you cannot or don’t want to useComposer, check out the Installation section.

Regardless of how you downloaded and installed CakePHP, once your set up iscompleted, your directory setup should look something like the following:

  1. /cms
  2. /bin
  3. /config
  4. /logs
  5. /plugins
  6. /resources
  7. /src
  8. /templates
  9. /tests
  10. /tmp
  11. /vendor
  12. /webroot
  13. .editorconfig
  14. .gitignore
  15. .htaccess
  16. .travis.yml
  17. composer.json
  18. index.php
  19. phpunit.xml.dist
  20. README.md

Now might be a good time to learn a bit about how CakePHP’s directory structureworks: check out the CakePHP Folder Structure section.

If you get lost during this tutorial, you can see the finished result on GitHub.

Checking our Installation

We can quickly check that our installation is correct, by checking the defaulthome page. Before you can do that, you’ll need to start the development server:

  1. cd /path/to/our/app
  2.  
  3. bin/cake server

Note

For Windows, the command needs to be bin\cake server (note the backslash).

This will start PHP’s built-in webserver on port 8765. Open uphttp://localhost:8765 in your web browser to see the welcome page. All thebullet points should be green chef hats other than CakePHP being able to connect toyour database. If not, you may need to install additional PHP extensions, or setdirectory permissions.

Next, we will build our Database and create our first model.