Thursday, March 18, 2010

Setting up PHP with IIS 6 on Windows XP

This is a small guide on setting up PHP under IIS 6 on a Windows XP/2003 server. If you have any questions or queries about it please don't hesitate to leave me a comment.

Installing PHP

  • Get the latest php (5.2.6 at present) from PHP.net's download page. Download the zip packager rather than the installer.
  • Extract the zip file to c:\php
  • Copy php.ini-dist file to php.ini
  • Edit the c:\php\php.ini file and
    • Set the session.save_path to a temporary directory on your server, you could create a special one for this (e.g. c:\php\session)
    • Set the upload_tmp_dir to a temporary directory on your server, you could create a special on for this (e.g. c:\php\upload)
    • Set the SMTP setting to the ip of your smtp server. It won't work with authentication so make sure you can send from your web server through that smtp server without a user/pass
    • Set the sendmail_from to the email you want all emails from the server to come from
    • Set the upload_max_filesize setting to something a little large (if necessary). Default is 2M. I think 8M is normally ok.
    • Set your extension_dir=C:\php\ext
    • Set post_max_size to at least the size of your upload_max_filesize (+ a little bit more). Default is 8M. 10M should probably be ok if you increased the upload_max_filesize to 8M.
    • Uncomment (by removing the ; at the start of the line)"cgi.force_redirect" and change the value to 0 instead of 1
    • Add these lines to the end of the file
      extension=php_curl.dll
      extension=php_gd2.dll
      extension=php_imap.dll
      extension=php_mysql.dll
      
  • Save and exit the file

Setting up IIS and file/directory permissions

  • Now open the IIS management console by typing Start->Run and typing %SystemRoot%\system32\inetsrv\iis.msc
  • Find out what user we need to give write access to by
    • Edit the properties of the web site you are going to install the php application into
    • On the directory security tab, click the edit button under anonymous access and authentication control
    • Copy down the user name under the anonymous access section (it is allowed right ?). It's usually COMPUTER\IUSR_COMPUTER where COMPUTER is the name of the computer running IIS
  • Now right click on the c:\php\session directory and go to properties, click the security tab, click add and in the box type in the name you copied down before.
  • Click check names and it should underline the name, then click ok.
  • Click modify and it should check all the other necessary boxes for you.
  • Click ok
  • If there is no security tab, then in windows explorer
    • Go to the Tools menu, choose 'Folder Options'.
    • Choose the 'View' tab and find the option called 'Use simple file sharing' (usually the last one) and untick it.
    • Click apply, then ok.
    • Go back to the previous step
  • Repeat this for the c:\php\upload directory and any other directories which need to be writeable by your php application.
  • Now go back to the IIS management console, right click on the website you want to setup php for and go to properties.
  • Click the documents tab and click add and type in index.php and click ok. This tells the webserver to look for index.php files for a default file.
  • Now, still in the iis management console, click the home directory tab, click on the configuration button and then click add.
  • Browse to the c:\php\php-cgi.exe file for the executable and .php for the extension. We want it for All Verbs which is checked by default, check script engine and uncheck "Check that file exists" then click ok.
  • Then click ok until all the dialogs are closed and restart your website in the iis control panel by clicking the restart button in the toolbar or by right click and choosing restart from the tasks menu.
  • Now create a file in your web root called info.php and put in it then browse to that file in your web browser via it's url. It should bring up a phpinfo page which will let you check that mysql is enabled, the session.save_path is right etc.

Wednesday, March 10, 2010

MVC-Based Web Application V/S Web Forms-Based Web Application

Advantages of an MVC-Based Web Application

The ASP.NET MVC framework offers the following advantages:
  • It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
  • It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
  • It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure. For more information, see Front Controller on the MSDN Web site.
  • It provides better support for test-driven development (TDD).
  • It works well for Web applications that are supported by large teams of developers and Web designers who need a high degree of control over the application behavior.

Advantages of a Web Forms-Based Web Application

The Web Forms-based framework offers the following advantages:
  • It supports an event model that preserves state over HTTP, which benefits line-of-business Web application development. The Web Forms-based application provides dozens of events that are supported in hundreds of server controls.
  • It uses a Page Controller pattern that adds functionality to individual pages. For more information, see Page Controller on the MSDN Web site.
  • It uses view state or server-based forms, which can make managing state information easier.
  • It works well for small teams of Web developers and designers who want to take advantage of the large number of components available for rapid application development.
  • In general, it is less complex for application development, because the components (the Page class, controls, and so on) are tightly integrated and usually require less code than the MVC model.