I’ve been developing with PHP for god knows how long and just got involved with Python MVC frameworks like Pylons and Turbogears. I wanted to share with you (and keep a track record for myself) how to setup CakePHP, a PHP MVC framework, with Windows.

It’s really simple…

  1. Get EasyPHP 2.0 - this packages PHP, Apache, and a MySQL DB all together. Download and install.
    • I created a new folder to put all my dev work in, so I installed to C:\webdev\EasyPHP
  2. Get CakePHP 1.2 - Download and install
    • I created a dir called ‘C:\webdev\projects\cake_1.2′ (all of my projects will go in the /projects folder)
    • Move the ‘cake’, ‘vendors’ , .htaccess, index.php into this folder
  3. Get cygwin if you don’t already have it
  4. Add some paths to your env
    • Go to Control Panel > System > Advanced > Env Vars and add the following:
    • C:/webdev/EasyPHP2.0b1/php5/;
    • C:/webdev/EasyPHP2.0b1/php5/ext/;
    • C:/webdev/EasyPHP2.0b1/mysql/bin;
    • C:/webdev/projects/cake_1.2/cake/console;
  5. Add folders for the other projects you will be working on
    • I created ‘C:\webdev\projects\proj1′ and ‘C:\webdev\projects\proj2′
    • Within the projX directory I have ‘projX\trunk\app’ which is where all the code will go
    • I will keep proj docs in ‘projX\docs’, so everything is kept together
  6. Edit your config files
    • php.ini
      • EasyPHP does this for you, but you can tweak as you’d like
    • httpd.conf (Apache)
      • change DocumentRoot “${path}/www” to DocumentRoot “C:\webdev\projects”
      • change <Directory “${path}/www”> to <Directory “C:\webdev\projects”>
      • Make sure the AllowOverride is set to All for the correct Directory
      • Make sure this line is uncommented
        LoadModule rewrite_module mod_rewrite.so
      • if you want to be able to setup virtual hosts (so you can do http://projX/ instead of http://localhost/blahblah/blah/projx then uncomment the following line:Include conf/extra/httpd-vhosts.conf
  7. Add a virtual host for each project you will work on (if you followed the last step)
    • Open C:\webdev\EasyPHP2.0b1\apache\conf\extra\httpd-vhosts.conf
      Add something like this:<VirtualHost *:80>
      DocumentRoot /webdev/projects/projX/trunk/app/webroot
      ServerName
      projX:80
      ErrorLog logs/
      projX_error.log
      CustomLog logs/
      projX_access.log common
      </VirtualHost>
    • Edit C:\WINDOWS\system32\drivers\etc\hosts so your comp knows what the IP for the project is. For example:
      127.0.0.1 localhost
      127.0.0.1 proj1
      127.0.0.1 proj2
  8. Allow the command line to find mysql
    • I was stuck on this for a long ass time. I kept getting Fatal error: Call to undefined function mysql_connect() .. here’s how to solve that:
    • Copy C:\webdev\EasyPHP2.0b1\php5\php.ini-dist to C:\webdev\EasyPHP2.0b1\php5\php.ini
    • Uncomment this line:
      extension=php_mysql.dll
    • Copy the following files to ‘C:\WINDOWS\system32′ from your php5 dir (not sure if this made a difference, if you can’t bake a projet because you get a undefined function error then do this)
      php5apache2.dll
      php5ts.dll
      php_mysql.dll
      libmysql.dll
      libmysqli.dll
  9. Modify cygwin (optional)
    • I downloaded tcsh first
    • Add necessary alias’
  10. Bake your first project
    • Open up cygwin
    • cd to /webdev/projects/projX/trunk/app
    • Type ‘cake bake’ in the CLI (command line)
    • All your initial files will be created and copied over from the cake_1.2 dir we setup earlier
    • Edit your database user/pass in the ‘/webdev/projects/projX/trunk/app/config/database file
    • Now you can start to bake your controller, models, etc. Just type cake bake and go!
  11. Done!