RuslanY Blog

Distribuir contenido
IIS, FastCGI, PHP and other interesting stuff
Actualizado: hace 11 horas 3 mins

Install PHP applications with WebMatrix

Vie, 09/07/2010 - 21:45

Microsoft has recently launched a beta release of a new project called WebMatrix. This is a complete web development stack that can be used to start developing and deploying web sites. One thing that may be not so obvious from all the existing announcements is the fact that WebMatrix has full support for installing, running and publishing PHP applications.

Here are the examples of how WebMatrix can be used to create and publish a PHP web site (using WordPress as a showcase).

Installing a PHP application

After installing and launching WebMatrix select “Site from Web Gallery” option and then pick WordPress:

Follow the installation steps as described in Download and Install a PHP application. As you proceed you will notice that WebMatrix downloads and installs the necessary components for running WordPress – the latest version of PHP 5.2 and MySQL. At the end of the installation process you will get a working instance of WordPress, that you can configure and customize further:

Notice the port number used in the URL. This is not the standard port 80 used by default in IIS. The site is not running on IIS that is included with operating system. Instead WebMatrix installs and uses IIS Developer Express, which is a developer-focused version of IIS that runs on all versions of Windows, starting from Windows XP. This is actually very cool because now it is possible to get the latest and greatest IIS features on Windows XP instead of using the good old IIS 5.1 as development web server . But even if you already have Windows 7, you may still want to use IIS Developer Express, because with that you do not need to enable real IIS Web Server included with OS on your development machine.

Even though IIS Developer Express is a lightweight development server it comes with everything needed to run PHP applications, including the latest version of FastCGI module and URL Rewrite 2.0. This means that after you install WordPress with WebMatrix you can enable WordPress’ pretty permalinks by following the instructions at IIS URL Rewrite Module support in WordPress.

Note: By default WebMatrix and IIS Developer Express are not configured to run PHP even if PHP is already installed on the machine. To work this around  install any PHP application via WebMatrix UI. This way WebMatrix will configure IIS Developer Express to handle PHP requests. This is something that will be fixed in future releases of WebMatrix.

Modifying a PHP application

After the WordPress is installed there are several things you can do with it from within WebMatrix. For example you can edit the theme files by using the built-in editor:

You can check what kind of HTTP requests are made by Web Browser to load a typical WordPress page:

(Learn more about this feature at Using WebMatrix Beta: Analyze Your WebSite)

Also, you can check the WordPress database content by using the WebMatrix Database Manager:

And, finally, you can run the search engine optimization analysis and fix any SEO violations found within the application:

(Learn more about this feature at Using WebMatrix Beta: Make your Website SEO Friendly)

Publishing a PHP application

The last step is the publishing of the web application on a live web server. WebMatrix can publish the content to a web server by using various protocols: FTP, FTP/SSL and WebDeploy (note that FTP protocols cannot be used to publish MySQL database). You can pick a hosting provider from the list offered by WebMatrix or you if you know the publishing settings from your hosting provider you can manually enter them in WebMatrix.

When you publish the content the WebMatrix will show you the list of files and the database that will be uploaded to the server. Note also that during publishing the WebMatrix will replace the current database connection settings in wp-config.phpfile with the connection settings used on a hosting web server. WebMatrix will extract that information from the connection string that you specify in publishing settings:

(Learn more about publishng web sites at Using WebMatrix Beta: Publish Your WebSite)

Feedback and suggestions

The WebMatrix is a beta release and the WebMatrix team is open to any constructive feedback on how to improve the product. Do you have any suggestions or have you run into any problems when using WebMatrix? What PHP related features would you like to see in this product? Please let the team know by starting the thread on WebMatrix forum or by leaving a comment here.

WinCache Extension 1.1 for PHP – Release to Web

Mié, 30/06/2010 - 20:44

Today IIS team has published the final release of WinCache Extension 1.1 for PHP. This is the latest stable and production ready version of the extension. The v1.1 has all the features available in version 1.0 plus the following features.

  • User Cache API’s can be used by PHP scripts to store PHP objects and variables in shared memory. This way PHP scripts may improve the execution speed by storing processed data in the cache and then using it in subsequent requests instead of re-creating the data on every request.
  • WinCache Session Handler can be used to configure PHP to store the session data in shared memory cache. Using shared memory instead of the default file session storage helps improve performance of PHP applications that store large amount of data in session objects. The content of the WinCache session cache is persisted on disk so that it is not lost during IIS worker process recycling.
  • File Change Notifications – the entries in the opcode and file caches are now updated as soon as the corresponding PHP files are modified on a file system. This is very useful for PHP applications that store its configuration in PHP files – for example Joomla!. Now the configuration changes for those applications take effect right away instead of a 30 seconds delay (default cache refresh interval).
  • Lock/Unlock API’s – these API’s can be used to obtain/release an exclusive lock on a key in the cache.
Install the Windows Cache Extension 1.1 for PHP – RTW

To install the WinCache Extension 1.1 for PHP 5.2 and PHP 5.3, use the download links at the extension’s home page at http://www.iis.net/expand/WinCacheForPhp.

The installation with Web Platform Installer is the easiest as it will automatically place the extension binary into proper location and will update the PHP configuration to enable the extension. Also, if you have the previous version of the extension installed, then Web PI will upgrade it. If you install any PHP application by using Web PI then the WinCache Extension 1.1 for PHP will be offered as an optional component.

If you install the extension manually, then follow the instructions at Installing/Configuring WinCache for PHP.

Getting the extension source code

The source code for the extension is available at http://pecl.php.net/package/WinCache/1.1.0stable. For the instructions on how to build the extension yourself refer to Building WinCache Extension.

Getting support

The WinCache extension is not supported by Microsoft Product Support Services. Instead it is supported as any other community PHP extension via the forums, mailing lists and the PECL bugs database. Use the following resources:

Storing URL rewrite mappings in a separate file

Mié, 19/05/2010 - 21:00

When using rewrite maps in IIS URL Rewrite it is very common to have a very large number of entries in a rewrite map. In order to avoid cluttering the configuration file - web.config - with this configuration data the rewrite maps can be defined in a separate configuration file. That file can then be referenced from the web.config file. This post provides an example of how this can be done.

Create a file called rewritemaps.config in the same directory where web.config file is. Open that file in notepad and add the following:

<rewriteMaps>   <rewriteMap name="Redirects">     <add key="/oldurl" value="/newurl" />     <add key="/otheroldurl" value="/othernewurl" />   </rewriteMap> </rewriteMaps>

Save this file and then open web.config file in notepad. In the web.config file add the following inside of the <rewrite> section:

<rewriteMaps configSource="rewritemaps.config" />

The configSource attribute tells IIS configuration that the <rewriteMaps> section is defined in a separate file rewritemaps.config. This referenced section can be now uses as if it was defined in the same web.config file. Also, the IIS Manager UI will work well with this referenced file: when you modify or add entries to the rewrite map they will be stored in the rewritemaps.config file.

Here is a complete example web.config file that uses the rewrite map from referenced configuration file:

<configuration> <system.webServer>   <rewrite>     <rewriteMaps configSource="rewritemaps.config"><rewriteMaps>     <rules>       <rule name="Redirect rule1 for Redirects">         <match url=".*" />         <conditions>           <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />         </conditions>         <action type="Redirect" url="{C:1}" appendQueryString="false" />       </rule>     </rules>   </rewrite> </system.webServer> </configuration>

The same approach can be used for storing rewrite rules in a separate configuration file, e.g.:

<rules configSource="rewriteRules.config" />

WinCache Extension 1.1 for PHP – Beta 2

Jue, 29/04/2010 - 19:03

Today IIS team has published a second beta of WinCache 1.1, which has the following new features and improvements :

  • File Change Notifications – the entries in the opcode and file caches are now updated as soon as the corresponding PHP files are modified on a file system. This is very useful for PHP applications that store its configuration in PHP files – for example Joomla!. Now the configuration changes for those applications take effect right away instead of a 30 seconds delay (default cache refresh interval);
  • Persistent Session Handler – the content of the WinCache session cache is persisted on disk so that it is not lost during IIS worker process recycling.
  • Lock/Unlock API’s – these API’s can be used to obtain/release an exclusive lock on a key in the cache.

The beta builds of the extension can be downloaded and installed from the extension home page at: http://www.iis.net/expand/wincacheforphp (look for the “WinCache 1.1 – Beta 2” section there). The source code can be obtained from http://pecl.php.net/package/WinCache/1.1.0beta2. The documentation for the extension can be found on PHP.NET WinCache documentation.

To learn how to change popular PHP applications to use WinCache 1.1 features refer to the following:

This is the beta release and the WinCache team is looking for your feedback on new features and functionality. Use the WinCache Community Forum to ask questions about the extension, report bugs and problems and to suggest features and improvements.

Visual Studio XML IntelliSense for URL Rewrite 2.0

Vie, 23/04/2010 - 21:41

Last year I published an XML schema for URL Rewrite 1.1 that could be used to enable IntelliSense support when editing rewrite rules in Visual Studio XML editor. Now that the URL Rewrite 2.0 has been released, the old schema will not work for the the new configuration elements introduced in the v2.0. Use the link below to download the schema for URL Rewrite 2.0:

VS IntelliSense for URL Rewrite 2.0

Disclaimer: The schema file and the helper script file contained in this package are provided by me and not by Microsoft. The are not officially supported by Microsoft. Use them at your own risk.

Follow the same instructions as in Visual Studio XML IntelliSense for URL Rewrite 1.1 to add the schema to the Visual Studio schema cache. If after following the instructions the IntelliSense does not work then follow the instructions at Not getting IntelliSense in your web.config for system.webServer sections in Visual Studio 2008?.

Slides and Questions from PHP on Windows Webcast

Mar, 13/04/2010 - 20:11

On April 9, Mark Brown and I did a PHP|Architect webcast “PHP Performance On Windows”. The slides from the presentation have been published at the following link:

PHP Performance on Windows – slides

There were a number of question at the end of the webcast that we did not get to answer due to lack of time. This blog post provides answers to those questions.

Q: Why is php_mssql.dll removed from php 5.3.2?
A: The reason why it was removed was because of an incompatible driver. The last SDK supported by Microsoft was not compatible anymore with VC6. Anyway, php_mssql.dll is not recommended to be used with SQL Server because there is a SQL Driver for PHP that is officially supported by Microsoft. You can get more information about the driver at Working with Microsoft SQL Server driver (php_sqlsrv.dll) for PHP on Windows.

Q: How can we have .htaccess file features work on IIS? Is there an alternative?
A: There are several options. If you just want Apache mod_rewrite rules to work on IIS, then you can import them from a .htaccess file. If you want complete support for all .htaccess features then you can try Helicon Ape from HeliconTech. Regarding PHP specific features in .htaccess file – for PHP 5.2 you could use htscanner PECL extension. In PHP 5.3 there is a new feature for per directory PHP configuration and .user.ini files.

Q: Do you have any numbers to compare iis performance with other web servers(apache, nginx, lighttpd)?
A: No, we do not have any numbers that can be shared. It’s difficult to come up with an objective test that compares web server technologies – there are too many variables and interpretations of the results and even if Microsoft ever produced such numbers they would probably cause a lot of controversy over the objectivity of those tests.

Q: Do you plan to implement wincache library for Zend Framework(Zend_Cache)?
A: WinCache team does not have plans for that, but there is already a PHP developer who is working on implementing this: http://github.com/juokaz/wincache.

Q: We have discussed here sugar CRM. Is Microsoft planning to do enhancement in sugar CRM functionality?
A: Microsoft works well with Sugar CRM development team and Sugar CRM add enhancements to their future versions to support new features from Microsoft, such as WinCache user and session cache for example. Microsoft, however does not contribute any code and does not work directly on any enhancements to Sugar CRM.

Q: Is Microsoft planning to develop any dll which can make PHP code to Intermediate language?
A: Assuming that the question is about .NET intermediate language – no, there are no plans for this.

Q: Would there be any tool in Microsoft development tool kit for PHP?
A: There are several projects in Microsoft that provide development tools and instructions for enabling interoperability between PHP and other Microsoft technologies. You can find more details about those projects here: http://www.interoperabilitybridges.com/.

Q: Is WinCache shared data accessible for CLI? Script A launches Script B, C and D … ?
A: Yes, you can access the shared data from CLI as long as you set wincache.enablecli = 1 in php.ini and all the CLI processes have the same parent process.

Q: Are the statistics results of WinCache the same in 5.2.13 as in 5.3?
A: If the question is about wincache.php statistics script then yes – the data presented by that script is the same regardless of the PHP version.

Q: Are there any security concerns with having wincache store session data in shared memory?
A: If you use different IIS application pools for different web sites (which is the recommended configuration), then WinCache ensures that those web sites can not access each other’s cache data. All caches, not just the session cache are not shared across IIS application pools.

Q: Is it safe to write to the user cache assuming data disappears from the system after the cache times out? Is the content of the user cache in wincache 1.1 written to disk at all?
A: Normally the data in the user cache is deleted from the cache after the time to live interval, but the deletion happens on the main request processing thread. This means that if there are no requests to process, the entries in the cache may stay longer than the TTL. WinCache does not write user cache content to disk, but if memory pagefile is enabled on the server, then it may happen that the memory content will be stored by OS in a pagefile. If a maching (not just a process) crashes when user cache content is in the pagefile, then the content may be present on disk.

Q: Is the sqlsrv driver going to be compatible with PDO?
A: SQL Driver for PHP 2.0 will include PDO support.

Q: Is there any documentation on securely configuring php/FastCGI in a shared application pool environment on IIS6 so that websites?
A: Check the article about setting up PHP on IIS6 and look for the section called “Impersonation and file system access”. If this is not what you are looking for – let me know.

Q: When are we going to see PHP 5.3 in the WPI?
A: Web PI team is planning to add support for PHP 5.3 in near future. Most probably it will be possible to select which version of PHP to install from Web PI. This is because there are some PHP applications in Web PI that will never support PHP 5.3.

Thanks to all who has attended the webcast and asked interesting questions!