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:
pdo_mysqlenabled in PHP.
Before starting you should make sure that you have got an up to date PHP version:
You should at least have got installed PHP 7.2 (CLI) or higher. Your webserver’s PHP version must also be of 7.2 or higher, and should be the same version your command line interface (CLI) PHP is.
The easiest way to install CakePHP is to use Composer. Composer is a simple way of installing CakePHP from your terminal or command line prompt. First, you’ll need to download and install Composer if you haven’t done so already. If you have cURL installed, it’s as easy as running the following:
curl -s https://getcomposer.org/installer | php
Or, you can download
composer.phar from the
Then simply type the following line in your terminal from your installation directory to install the CakePHP application skeleton in the cms directory of the current working directory:
php composer.phar create-project --prefer-dist cakephp/app:4.* cms
If you downloaded and ran the Composer Windows Installer, then type the following line in your terminal from your installation directory (ie. C:\wamp\www\dev):
composer self-update && composer create-project --prefer-dist cakephp/app:4.* cms
The advantage to using Composer is that it will automatically complete some important set up tasks, such as setting the correct file permissions and creating your config/app.php file for you.
There are other ways to install CakePHP. If you cannot or don’t want to use Composer, check out the Installation section.
Regardless of how you downloaded and installed CakePHP, once your set up is completed, your directory setup should look something like the following:
/cms /bin /config /logs /plugins /resources /src /templates /tests /tmp /vendor /webroot .editorconfig .gitignore .htaccess .travis.yml composer.json index.php phpunit.xml.dist README.md
Now might be a good time to learn a bit about how CakePHP’s directory structure works: check out the CakePHP Folder Structure section.
If you get lost during this tutorial, you can see the finished result on GitHub.
We can quickly check that our installation is correct, by checking the default home page. Before you can do that, you’ll need to start the development server:
cd /path/to/our/app bin/cake server
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 up http://localhost:8765 in your web browser to see the welcome page. All the bullet points should be green chef hats other than CakePHP being able to connect to your database. If not, you may need to install additional PHP extensions, or set directory permissions.
Next, we will build our Database and create our first model.