How To Use CakePHP 3.0 Console in Windows

By January 18, 2015 CakePHP, PHP No Comments

CakePHP brands itself as the rapid development php framework. A huge contributor to the “rapid” is the ability to fire off command lines in the console to automate processes, such as creating the associated MVC folders from your database. Essentially “Baking” in the files into your CakePHP project.

In a Windows environment it can be quite tricky getting the Console to work, especially if you have no idea how. The CookBook doesn’t really have any useful information regarding Windows.

FIRST THINGS FIRST:

You’ll need to have your CakePHP project installed locally. You can follow the first section here: Installing CakePHP 3.0 on Shared Hosting

We need the project installed so that we can link the Console to our cmd.exe.

For demo purposes we will be using WAMP, saved in the default directory:

c:\wamp\

LINKING THE CONSOLE TO CMD.EXE:

  1. Right Click on My Computer > Properties
  2. Select “Advanced system settings”
  3. Under the Advanced Tab click “Environment Variables”
  4. In the “System Variables” dialog scroll down until you see the “Path” Variable field.
  5. Select “Path” and click Edit.
  6. Follow the path until you see reference to the PHP.exe (e.g. C:\wamp\bin\php\php5.5.12)
  7. Ensure that there is a semi-colon at the end of the PHP path and then add in the following text, but change “app_name” to your project directory:

C:\wamp\www\app_name\bin\

The full variable value could look something like this:

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\wamp\bin\php\php5.4.3\;C:\ProgramData\ComposerSetup\bin;C:\wamp\bin\php\php5.5.12;C:\wamp\www\app_name\bin\

TESTING THE CONSOLE:

Now it’s time to test the Console so open up CMD.exe (Run as Administrator).

Simply enter in “cake” and push enter.

The welcome screen should display, which means you’re ready for baking.

Enjoy!

Leave a Reply