Recently I spoke with someone on Twitter who was having issues running on IIS. With all the talk about ASP.NET MVC on IIS, folks forget that the MVC pattern works in other languages as well. CakePHP provides MVC development on PHP. That said, I wanted to dive in and see what the issues were involved in getting this project up and running on IIS 7.
The minimum requirements are a web server and a copy of CakePHP, that's it! Requirements * HTTP. LEMP server is much better than Xampp server, in terms of performance as it has caching packages, Nginx and Apache. For LEMP server, a. Most of the people struct to install cakephp in windows. So that today we are.
I managed to get it installed pretty quickly, but it does take a little tweaking to get you up and running. I’ve chronicled my adventures with CakePHP below in case anyone else is having issues. That said, I must first say that I am not an expert working with CakePHP. This was my first experience with the project, so this information is provided “as-is” and should be taken with a grain of salt.
With this demo, I’ll be walking through the “” offered on cakephp.org, and modifying it as needed to work with IIS 7. That said, let’s get started. Prerequisites • Install: IIS 7 on Windows 2008 Server or Windows Vista • Install: for IIS 7.0. Use the for easiest experience. • Install: module. Use the for easiest experience.
• Install: A database. This post uses MySQL. • Download: source code • Unzip: CakePHP (entire contents) to the intended path Yes, there ARE a lot of Prerequisites, but these are pretty typical for any MVC app on any platform. Assumptions / Conventions For the purposes of this post, I will use the convention/assumption that you have unzipped CakePHP to c:inetpubCakePHP. You should have the following paths now: • c:inetpubCakePHP • app • cake • vendors •.htaccess • index.php • version.txt I will also use the assumption that this is being installed on the “Default Web Site”. This is unlikely what you are doing, so you’ll want to replace the “Default Web Site” instances in the steps below with your site or application path. Transformers Playstation Game.
Lastly, I will assume that you are using and have already installed MySQL. You may use another database if you please, but this blog will reference MySQL. Installing the Blog Sample Pointing IIS to the cake document root First, you’ll need to configure your website to point to the correct location. Using the assumptions above, the correct location would be c:inetpubCakePHPappwebroot. Creating a Blog Database Second, configure your database connection. To do this, you’ll need to create a blog database, and then point your configuration to that new catalog.
Start by creating a new MySQL Catalog using your favorite tool. Simply right click in the catalogs and click “create new schema.” Create a schema named “CakeBlog”.
Once the schema is created, click on the “Tools” menu and select “MySQL Query Browser” and execute the following script: /* First, create our posts table: */ CREATE TABLE posts ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(50), body TEXT, created DATETIME DEFAULT NOT NULL, modified DATETIME DEFAULT NOT NULL8.); /* Then insert some posts for testing: */ INSERT INTO posts (title,body,created) VALUES ('The title', 'This is the post body.' , NOW()); INSERT INTO posts (title,body,created) VALUES ('A title once again', 'And the post body follows.' , NOW()); INSERT INTO posts (title,body,created) VALUES ('Title strikes back', 'This is really exciting! , NOW()); * This SQL code copied verbatim from tutorial found here.
You’ve now created your database and a blog posts table with some default posts. Time to configure CakePHP to read from the database: Cake Database Configuration We’ll need to let CakePHP know where the database is. Copy database.php.default in c:inetpubCakePHPappconfig to database.php Open c:inetpubcakephpappconfigdatabase.php and change the $default variable to point to your database: var $default = array( 'driver' =>'mysql', 'connect' =>'mysql_connect', 'host' =>'localhost', 'login' =>'CakeBlog', 'password' =>'c4ke-1z-k00l', 'database' =>'CakeBlog', 'prefix' =>' ); * This PHP code copied nearly verbatim from tutorial found here: You should now be able to open your browser to your application and see the default cake configuration page.
Setting up Rewriting Rules CakePHP uses mod_rewrite, but also provides the ability to use Cake’s built-in ‘pretty URLs’. We’ll be importing the mod_rewrite rules from the.htaccess files from the default cakephp installation into the IIS URL Rewrite module. We’ll then have to modify those rules. Start this process by opening the IIS Management Console.
Open your application path. In this instance, we are using “Default Web Site”. • Click on the “ Default Web Site” • Open the “ URL Rewrite” module • Click on “ Import Rules” in the Actions pane • Click the “ ” button next to the “Configuration file” textbox. • Select the c:inetpubcakephp.htaccess file and click “ OK” • Click the “ Import” button • Click the “ Apply” button in the “ Actions” pane • Repeat steps 4, 5, 6 and 7 for c:inetpubcakephpapp.htaccess and c:inetpubcakephpappwebroot.htaccess files. The rules are imported, but now you’ll need to edit the rules.
• Click the “ Back to Rules” button in the “ Actions” pane • Edit the two rules with the action starting with “ webroot/” • Remove the “ webroot” portion of the “Rewrite URL”. Your paths should now look as follows: Creating your MVC Application The remainder of your application setup should follow the steps found in the original “”. There is nothing different between IIS and Apache at this point, so copying the steps would be a bit redundant.
Start with the step named “ Create a Post Model”. Much like ASP.NET MVC, Cake provides an MVC pattern for developing PHP applications.
Once you have completed the steps, you should have a default site that looks something like the following: Summary Installing CakePHP on IIS is actually not much different from installing on Apache. The main difference lies in the implementation of mod_rewrite on Apache vs URL Rewriter in IIS. Obviously the installation of PHP differs from Apache. IIS makes the installation of PHP simple with Web Application Installer. If you are using CakePHP on IIS, I would be interested to hear if your experience was different than mine. This all seems straight forward however I’m proabably running into the fact that newer versions are a little different (as always).
So mabye you can sugegst or update if at all possible as I’m very new to IIS and especially how it uses URLrewrite. CakePHP 184.108.40.20684. IIS 7.5 (win 7) I’ve done the basic cake install and config for database all OK, however I noticed that the CSS on the default page was not loading so I’ve been looking into the URL rewrite. Your tuturial was one of a very few clearly covering the steps needed (many others simply suggested things like ISAPIrewrite). However when I import the 3.htaccess files in the order as you have written I get 5 Imported rules ( two starting with app/webroot/ and two with webroot/ and on with index.php?). If I do not edit the rules (deleting the ‘webroot’ or ‘app/webroot’) then on the initial cakePHP page the CSS file is loaded and it all looks normal, however follwing the tutorial as link and attempting through several others (such as ) gives me a 404 error when viewing somthing like.
Deleting the ‘webroot’ and ‘app/webroot’ from the rewrite rules does not help and stops CSS from loading on the default page also. Here is the created web.config as imported from a current default cakePHP install on IIS 7 Any help would be apreciated. I have a Win 2008 IIS 7.5 FastCGI PHP 5.2 web server with Url Rewrite 2.0.
I was successful in combining several posts (found through google) and combined the code into one web.config file that: 1. Shows CSS/Imgs 2. Allows url rewrites – ex.
Domain.com/posts (works) and domain.com/posts/view/1 (works) and domain.com/index.php/posts/view/1 (works). I added this code to my web.config file and used ftp to transfer the file. I did not import the.htaccess files. Here is the web.config code: I hope this helps others.