We won't be walking or jogging, let's run. Let's call this run
pastry ;)
- Create a folder in your server's web root (/var/www/html in Ubuntu/Apache)
mkdir pastry and then go inside this folder cd pastry.
- Run
composer create-project --prefer-dist cakephp/app ./
This will download latest version of CakePHP from the template/skeleton repo app at github.com/cakephp/app in the current folder (the ./ part tells composer to install in this folder, rather than creating another folder inside this).
Once cakephp/app package and all the dependent packages are installed, there will be a prompt to set folder permissions (for logs/cache etc). Press Enter on the prompt, or n if you want to set the permissions later or with a different access level.
After the permissions are set, Security.Salt value will be updated in config/app.php automatically (this will be referred in the next step).
- Go to
config folder : cd config
- Copy
.env.default to .env : cp .env.default .env
Note : Environment variables would be used rather than changing the code files, to keep code consistency across different deployment environments.
- Open
bootstrap.php and un-comment following lines:
if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
$dotenv = new \josegonzalez\Dotenv\Loader([CONFIG .'.env']);
$dotenv->parse()
->putenv()
->toEnv()
->toServer();
}
As of writing this post, the above code is near line number 55.
Un-commenting the above lines enable loading environment variables from .env file
- Go back to the main folder :
cd ..
- Run
code . : This will open VS code with current folder opened by default.
From this point onward folder/file path will be mentioned, but not exact commands. Either you know them already (and these commands seem very trivial and stupid to include in the first place) or you would use VS code (or whatever other editor/IDE you prefer) and there would be different commands/actions to perform those actions.
- Open
config/app.php, copy (or cut) the long string against SECURITY_SALT key, and paste it in .env file against the variable SECURITY_SALT.
What we are doing here is keeping the code clean from any variables and using .env file for any environment changes.
I cut the string (not copy) so that it looks like this:

- Open
.env file and update APP_NAME and set it to any relevant name. I have set it to pastry.
Un-comment the line with variable DATABASE_URL and update the value in following format:
mysql://pastry:pastry@localhost/${APP_NAME}
The first pastry is DB username, and you might have something else (may be root, you shouldn't use root for all projects, but that's a different concern).
The second pastry is the password.
I have also kept the database name as pastry, which is set as APP_NAME, but if you have set it up differently, then instead of the variable ${APP_NAME}, use the DB name that you have set.
- Open Apache URL in browser for this folder.
I have URL like
localhost/pastry and you should be able to see all checks marked as green, as per following screenshot:

- Go to terminal (in the
pastry folder) and run following command:
bin/cake bake migration CreateUsers first_name:string? last_name:string? email:string:unique:EMAIL_INDEX password:string created modified active:boolean email_verified:boolean email_verified_at remember_me_token:string?
Break down of above command:
bin/cake - Cake shell (like artisan in Laravel)
bake - Parameter to create files based on other parameters
migration - Creates DB migration
CreateUsers - The migration is set to Create table by name Users
Rest of the part are columns with some specifications, in following format:
fieldName:fieldType?[length]:indexType:indexName
The question mark following the fieldType will make the column nullable.
The command will create Migration file that will be used in the next step to create DB table with specifications mentioned in this file.
While this command is used to create the migration file, the file can be created manually as well. Additionally, I recommend opening the file (located inside config/Migrations folder) and review it to get a better understanding of the migration file, and also to fine tune if needed.
- Execute migrations by running following command:
bin/cake migrations migrate
This will create the DB table as per the specifications in the migration file.
If there are multiple migrations created in the above step, then all will be executed with this command.
Running this command again will NOT run previously executed migrations again.
The log of migrations are stored in phinxlog DB table (created when this command is executed first time).
Bake command will be used in next post(
CakePHP 2) to auto generate Controller, Model and View files.