How to run XAMPP’s PHP CLI and CakePHP console

XAMPP is one of the easiest options to develop using PHP or PHP CLI. I use CakePHP for development and one of the features of CakePHP is to back the MVC. In this guide, we’ll see how to get started. This tutorial doesn’t teach you how to use CakePHP’s bake feature. This guide is specifically written for Windows Vista or Windows 7.

0. Objective

To run XAMPP’s PHP CLI, you first have to set up the environment variables for PHP CLI. Also introduce how to get started on CakePHP’s console.

1. Setting up environment variables

Firstly, we would need to let the command prompt know where to find php.exe. In my computer set up, it is located in ‘C:\xampp\php\’. Yours might be in ‘C:\xampp-lite\php\’ depending on where you install your XAMPP.

We need to edit some system environment variables:

Editing system environment variables in Windows Vista.

Click on ‘Edit the system environment variables’, a dialog box will pop up. Click on ‘Environment Variables…’, you should be greeted with the following dialog box:

Editing the path for environment variables

My path looks like this before I add anything:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

Append your XAMPP PHP directory at the back of what is already there:

;C:\xampp\php\

Open a new command prompt (don’t use existing one), and type “php” and see if there are any problems.

2. Avoiding MSVCR71.dll error

I encountered an error: “php.exe – System Error: The program can’t start because MSVCR71.dll is missing from your computer. Try reinstalling the program to fix this problem.”.

PHP MSVCR71 dll error

PHP MSVCR71 dll error

This error is caused by the “php_pgsql.dll” extension. We can proceed by disabling PostgreSQL if we don’t use it. If you do need it, you may consider installing Microsoft .NET Framework 1.1.

Open the file ‘php.ini’ in ‘C:\xampp\php\’ and search for “pgsql”. Disable the extension by placing a semicolon in the beginning of the line this way:

;extension=php_pgsql.dll

3. Command Prompt’s “Start in” setting

You can have multiple shortcuts of command prompts in your desktop. I set my command prompt shortcut to start in ‘C:\xampp\htdocs\dev\app’ which is my CakePHP application folder:

Command prompt properties start in setting

Command prompt properties start in setting

And when I run the command prompt, it will show:

Microsoft Windows [Version 6.1.7000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\xampp\htdocs\dev\app>

This is just more convenient without having to navigate through the folders again and again.

4. Running the CakePHP console

You should run the Cake console in your application folder this way:

C:\xampp\htdocs\dev\app>”../cake/console/cake” bake

This runs the ‘cake’ program and tells it to bake.

For a list of CakePHP console commands to use, you can try:

C:\xampp\htdocs\dev\app>”../cake/console/cake” help

That’s all

You can also put the CakePHP console path in your Windows environment variables. However note that if you have multiple projects with different versions, this method is less than ideal. Hope it helps.

15 thoughts on “How to run XAMPP’s PHP CLI and CakePHP console”

  1. Thank for info. Finally I found useful information.
    Can you explain some examples of commands? I entered the followings but I get error message.

    C:\xampp\htdocs\blog\app>$ cake bake controller
    or
    C:\xampp\htdocs\blog\app>$ cake bake model
    C:\xampp\htdocs\blog\app>$ cake bake view
    C:\xampp\htdocs\blog\app>$ cake bake project

    etc.

    It says ‘$’ is not recognized as an internal or external command, operable program or batch file.

  2. Hi shin, why do you have a dollar sign? I think you probably copy and paste the code from somewhere that uses a UNIX environment.

    You should instead run C:\xampp\htdocs\dev\app>”../cake/console/cake” bake

  3. Excellent tutorial, really spot on! Saved me hours of searching. Many thanks

    Also just to add if your doing database backups/exports then you want to use:

    ../cake/console/cake” schema generate
    or
    ../cake/console/cake” schema dump filename.sql

  4. I’ve searching three days for this – exactly xampp related!

    Well, thankyou! Finally I can use Cake BAKE!!

  5. open your C:\xampp\htdocs\cakephp\cake\console\cake.bat

    in your text editor
    then this line
    php -q “%lib%cake.php” -working “%CD%” %*

    with

    “C:\xampp\php\php.exe” -q “%lib%cake.php” -working “%CD%” %*

    if you installed xampp under c drive or choose correct patch towords php.exe file

    its working for me.

  6. Thanks a lot for all these info.
    I did the edit Environment Variable but with case recognizing cakephp
    but still not recognized in cmd ???

    any help… please
    thanks in Advance .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>