As a newbie to command line tools, I found myself overwhelmed while attempting to configure CakePHP’s command line console within a Windows 7 environment. Most of the tutorials that I found either referred to an older version of Windows, or a previous version of CakePHP. To developers new to command line or CakePHP, running the command line console may seem like a daunting task, but it is actually quite simple.
This tutorial will review how to set up the CakePHP 2.0.5 command line console for Windows 7 running WAMP, but the instructions should be similar for Windows Vista and XP as well. We will assume that you already have CakePHP installed, and that your database is configured correctly.
First, we need to set Environment Variables so that Windows can run cake from the command console:
- Open “Computer” under your Windows Start menu
- Right-click the “Computer” window, and select “Properties”
- You will be brought to the Control Panel’s System window. We’ll need to change our environment variables under “Advanced System Settings,” which you can select from the left column menu in this window
- Select the “Advanced” tab on the System Properties window
- Click the “Environment Variables…” button
- In the System Variables box, find the “Path” variable and click “Edit…”
- If there isn’t one already, add a semicolon to the end of the current “Path” variable (a semicolon is used to separate variables)
I use WAMP as my local development environment, and store all of my CakePHP projects in the C:wampwww directory, so my path variables will refer to this “wamp” directory. My CakePHP project also resides in a directory named “order_system.” Yours may differ depending on your development environment and where you have CakePHP installed, so be sure to change these directories to fit your needs
- At the end of your Path variable add
(The first path should point to your installation of PHP, and second variable should point to the “appConsole” location ofthe project that you are developing)
- Click “OK” to save your changes.
Once the Path variables have been saved, we can run a test to be sure that the variables are pointing to the appropriate locations
- From the Windows Start menu, search for “Run”
- In the “Run” prompt, type “cmd.exe” to execute the Windows command line console
- Your command line console will likely be pointing to your User directory initially. Type “cake” at the prompt.
If your environment variables are correct, you should see a “Welcome to CakePHP Console” message, similar to:
CakePHP command console is working properly, but it will need to run within our CakePHP project. As you can see from the screenshot, our working path should be the same as our application path. In order to rectify this, simply use the Change Directory (cd) command to change the path to the “app” folder inside your CakePHP project:
Now that we are in the correct directory, we can instruct CakePHP to “bake” our project, simply by typing at the prompt:
Alternatively, you can skip the bake menu, and jump right into baking a controller, project, view, etc. by running any of these commands at the command line:
cake bake db_config cake bake model cake bake view cake bake controller cake bake project cake bake fixture cake bake test cake bake plugin plugin_name cake bake all
For example, instead of entering “cake bake” after changing to your project directory, enter
cake bake controller
Happy Windows baking!