27Jan2008
Filed under: CakePHP, Code
Author: John Brennan
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…
- 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
- 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
- Get cygwin if you don’t already have it
- 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;
- 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
- 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
- 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
- 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
- Modify cygwin (optional)
- I downloaded tcsh first
- Add necessary alias’
- 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!
- Done!
Richard@Home
January 28th, 2008 at 9:39 am
A very thorough walk through. I don’t use EasyPHP 2.0 myself (preferring to install Apache, PHP & MySQL by hand), but the information is mostly transferable.
What are you using cygwin for?
johnnyice
January 28th, 2008 at 9:39 am
Why install them separately? EasyPHP literally takes me 2 minutes to install, you get *somewhat* of the latest build, and then you can go off and tweak any params you need (always a plus to save your php.ini and httpd.conf files of course!)
I’m using cygwin instead of the cmd that winxp comes with because I’m used to the unix env in terms of command line.
Arian
February 7th, 2008 at 7:57 am
hey seems like I am almost there,
Good tutorial overall but didnt get all the way.
I setup virtual hosts and changed the hosts file but apache giving 404 “The requested URL / was not found on this server. when i goto http://proj1”
I am guessing you need to change in for example
“C:\Program Files\Apache Group\Apache2\htdocs\proj1\trunk\app\webroot\index.php” where your CAKE_CORE_INCLUDE_PATH, ROOT, and APP dirs are as cake1.2 core folder wont be copied into the proj1 folder when u run `cake bake`right?,(only files that command created were database.php and cache files initially be4 setting up models etc)?
For me what would these values be? i prefer to work filepaths relatively so i can move this over to unix easily but not sure what to put.
main areas of interest are probably
“C:\Program Files\Apache Group\Apache2\htdocs\proj1\trunk\app” and
“C:\Program Files\Apache Group\Apache2\htdocs\cake_1.2″
I think is better to keep cake1.2 out of app folder so as someone else said, when update to cake happens, u just put pretend cake_2.0 in htdocs alongsdie cake_1.2, and change CAKE_CORE_INCLUDE_PATH in app folder as needed for apps you are testing locally as needed.
Also why put the files in proj1/trunk, instead of just proj1?
Is this for later version control system purposes?
If you can make a tutorial also how to integrate this with Eclipse that would be great. The Bakery’s Eclipse-PDT tutorial did not work for me for getting code completion to work.