30

A portion of our site is done in PHP and a portion of our site is done in ASP.Net. We just set up a new web server with Windows Server 2008 R2 which has IIS 7.5 installed.

I understand that IIS 7+ supports PHP, but can PHP and ASP.Net run side-by-side within a single web site in IIS, or would I have to set up one web site for the PHP pages and one web site for the ASP.Net pages?

Aaron
  • 1,454
  • 3
  • 22
  • 29

8 Answers8

29

You should be able to run both in the same site, but be sure that the AppPool for the site runs a "classic" ASP.NET pool configuration. The default AppPool routes everything through ASP.NET, and you won't want that for your PHP pages.

Other than that, you should be fine. Query strings, files, and back-end databases will be the best way to share data between pages.

Cylon Cat
  • 7,111
  • 2
  • 25
  • 33
  • 2
    It does not need to be in classic mode - I have several solutions running in Integrated mode without problems. – Shagglez May 10 '11 at 12:48
  • 2
    You sir...just resolved a 3 hour long hunt for what was wrong with my IIS setup...up vote – SomeShinyObject Jan 18 '13 at 15:05
  • @Shagglez I have PHP 5.5 installed on a Windows Server 2008 R2 Standard Server with IIS 7.5. Please indicate how I can run PHP files in an ASP.NET Web Application with Integrated Mode. – crazyTech Oct 25 '13 at 15:00
  • Hi i did to run php file in IIS.. But i have one small problem in my link 'www.sprop.in/admin_login' to enter in the address bar. It show all the php file list.. So please any one suggest me how to avoid this and how to execute index.php page default... – Kumar Shanmugam Aug 11 '14 at 05:55
  • @Cylon Cat Hey sir, can we use jsp and asp.net together in a single website ? – Vikas Verma Feb 20 '15 at 18:23
  • I haven't tried it, but you probably can do that. They will not be able to share session, but ASP.NET web services (all types) can be made to access ASP.NET session status, so ajax calls from PHP can access session data that way. – Cylon Cat Feb 21 '15 at 14:10
  • How about security? What if there's for example a security issue in some wordpress plugin. Could that lead to access to the Asp.Net site? I'm asking because we are forced to host a php site on the same domain but we don't manage the php site ourselves. And are there any measures to be taken against that? Thanks! – Beuz Oct 05 '21 at 11:21
11

Yes you can use both under the same website. Since the file extensions are mapped to specific external processes, they are called independently. You can even use Asp.Net to secure .php files with FormsAuthentication by implementing wildcard mappings within IIS (I know 6/7 have this, not sure about 5). Mixing data across them is tricky because they will have separate external processes and thus separate sessions. Most cookies will be readable across both, but secured cookies will not be.

Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
  • Whether or not file extensions are mapped to the same handler depends on the IIS AppPool configuration. You would *NOT* want to use the default app pool, because in that configuration, ASP.NET handles all file extensions. The default AppPool should work, though. – Cylon Cat Jan 21 '11 at 18:25
  • @Cylon Cat - the mappings are handled explicitly in the Handler mappings, and they point to separate ISAPIModules. It won't matter if you use the same AppPool because the memory objects would be segregated within the pool by the module. Asp.Net does not handle all extensions. – Joel Etherton Jan 21 '11 at 18:39
  • Here's a page that discusses the differences between IIS integrated pipeline (default app pool) and classic mode, with reference to how IIS handles non-ASP.NET files in each mode, and how to configure. http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/ – Cylon Cat Jan 26 '11 at 19:53
  • @Joel Etherton Hey sir as you are saying that we can use asp.net and php together in a single website so as same can we use jsp and asp.net together in a single website ? – Vikas Verma Feb 20 '15 at 18:22
  • 2
    @VikasVerma: I have no experience with it directly, but based on my understanding of how jsp works (limited mind you) it's certainly reasonable. They have their own handler mappings so should be handled by different parsing engines even though they occupy a similar file system directory. – Joel Etherton Feb 20 '15 at 18:25
3

Yes you can, but watch out for this:

If you have a wordpress on your "root", and asp.net apps in folders under it

(e.g. http://root.com/aspnetapp1/), and if you follow these suggestions about "urlrewrite" for permalinks in wordpress, you can have trouble if you try to configure "wildcard handlers" in the apsnetapp1.

To avoid issues, the web.config of the wordpress root app must also have that setting:

    <location path="." inheritInChildApplications="false"> 
    <system.webServer>
...
    </system.webServer>
</location>

Or else, your wildcard handler will never raise because index.php from root will catch all your requests to url like: http://root.com/aspnetapp1/api/*

foxontherock
  • 1,776
  • 1
  • 13
  • 16
1

Yes, it will be not a problem. Even some Windows Shared Hosts offer PHP plans - Windows Hosting PHP.

Wazy
  • 8,822
  • 10
  • 53
  • 98
  • 2
    I understand that you can run PHP on Windows in IIS, but my question is can you run PHP and ASP.Net on the same WEB SITE in IIS. – Aaron Jan 21 '11 at 17:50
1

Yes, PHP can be seamlessly implemented into ASP.NET 3.5 / 4.0

Go to http://phalanger.codeplex.com/ (or http://www.php-compiler.net/) and download the latest version of Phalanger. Install into Visual Studio and voila!

Phalanger – the PHP compiler for .NET

Welcome to Phalanger – full-featured PHP runtime & compiler for .NET/Mono frameworks. Phalanger is modern open-source implementation of PHP, compatible with the vast array of existing PHP code. In addition Phalanger gives PHP-application developers lot of new possibilities; from improving performance and using modern environments, to taking advantage of seamless unique .NET integration.

Apache
  • 61
  • 1
  • 3
0

ASP.NET and PHP Support

Develop, deploy and easily manage Web applications using your choice of languages. From ASP.NET to PHP, IIS7 provides a powerful and flexible Web server environment for the world’s most popular Web applications.

(Source: http://www.iis.net/overview/choice/aspnetandphpsupport )

I tried put a test.php file (with conent: <?php phpinfo(); ?> ) to existing ASP.NET website (use real server at https://somee.com ). I knew that ASP.NET and PHP have worked together.

Read more:
http://www.w3schools.com/aspnet/webpages_php.asp
https://technet.microsoft.com/en-us/library/hh994592.aspx

Vy Do
  • 46,709
  • 59
  • 215
  • 313
0

You can run both on the same site, but won't be able to talk to each other unless you setup some sort of messaging system or share storage.They are basically applications of complete different nature.

Another possibility is to call your .NET code from PHP:

A piece of code written in C# like this:

string javascript = "";
Microsoft.Ajax.Utilities.Minifier m = new Microsoft.Ajax.Utilities.Minifier();
Microsoft.Ajax.Utilities.CodeSettings settings = new Microsoft.Ajax.Utilities.CodeSettings();
settings.OutputMode = Microsoft.Ajax.Utilities.OutputMode.SingleLine;
settings.PreserveFunctionNames = false;
string minified = m.MinifyJavaScript(javascript, settings);

Will look like this on PHP:

$minifier = netMinifier::Minifier_Constructor();
$settings = netCodeSettings::CodeSettings_Constructor();
$csssettings = \ms\Microsoft\Ajax\Utilities\netCssSettings::CssSettings_Constructor();
$settings->OutputMode(\ms\Microsoft\Ajax\Utilities\netOutputMode::SingleLine());
$settings->PreserveFunctionNames(FALSE);
$settings->QuoteObjectLiteralProperties(TRUE);
$result = $minifier->MinifyStyleSheet($css, $csssettings, $settings)->Val();

From:

http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
0

ASP and PHP can be used on windows boxes. As long as they're completely separate and aren't dependent on each other. For example, using query strings (i.e file.php?var=1&var2=bla) things get messy when you need to transfer those variables over to the ASP file or vice versa.

So as long as the 2 systems are totally independent of each other, then it should work fine.

You may also find some incompatibility with cookies and sessions. Those too can be passed but not easily.

Wazy
  • 8,822
  • 10
  • 53
  • 98
  • The question is about running both ASP.NET and PHP in the same SITE, not just on the same box. Because they share an AppPool and an IIS worker process, they are not "completely separate" in this case. – Cylon Cat Jan 21 '11 at 18:23