Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable DELETE, PUT for PHP app at IIS?

Although DELETE request works successfully locally, it does not work when I deploy my app to MS Azure.

Here is what I get in console when try to delete a record:

DELETE http://mywebsite.azurewebsites.net/api/subjects/1 405 (Method Not Allowed)

My app uses mySQL at cleardb

How to fix such a problem?

EDIT

My app is a PHP 5.5 app, here is what I tried to do in web.config to enable DELETE and PUT, but it didn't work:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
        <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>

<validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
    </modules>
    <security>
      <requestFiltering>
        <verbs applyToWebDAV="false">
          <add verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" allowed="true" />
        </verbs>
      </requestFiltering>
    </security>

         <handlers>
<remove name="PHP55_via_FastCGI" />
  <add name="PHP55_via_FastCGI" path="*.php" verb="GET, PUT, POST, HEAD, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK" modules="FastCgiModule" scriptProcessor="D:\Program Files (x86)\PHP\v5.5\php-cgi.exe" resourceType="Either" requireAccess="Script" />

              <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
              <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
              <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
              <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
              <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
              <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
            </handlers>

    </system.webServer>
</configuration>
like image 777
Samir Sabri Avatar asked May 18 '15 12:05

Samir Sabri


People also ask

How to configure IIs on PHP?

Configuring IIS on PHP. Step 1. First enable IIS on your machine go to Programs and Feature ⇒ Turn Windows feature on or off as shown in below image and check all the check box inside IIS [ Internet Information Service ]. Step 2. After window enable all IIS feature search IIS on start menu and open it and start your server. Step 3.

How do I get put and delete to work with IIS?

To get PUT and DELETE to be accepted by IIS 7.5 for a PHP 5.4 fast-CGI driven REST API I had to disable the WebDAV-module. Otherwise the WebDAV module intervenes the HTTP requests using PUT or DELETE. To get this working was however a bit confusing and I might have missed some steps or done it in another order.

How do I enable put in IIS?

In the IIS Manager, select the application that needs to support PUT. In the Features View, find WebDAV Authoring Rules . Double-click it, or select Open Feature from the context menu (right-click). In the Actions pane, find and click on WebDAV Settings....

What is the PHP manager in IIS?

In order for PHP to run properly on IIS there is a set of recommended settings that need to be configured in IIS and PHP. PHP Manager checks if all of the recommended settings are configured correctly. If some settings are not configured properly then you can use PHP Manager to fix those settings.


1 Answers

I think PUT and DELETE are disabled in WebApi / IIS8 by default, which is what it looks like you are using. Quite a bit of discussion on this here.

like image 200
Paul Fryer Avatar answered Sep 20 '22 11:09

Paul Fryer