Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Websites PHP API - 405 Method Not Allowed on PUT and DELETE

I'm building a simple PHP web service using Azure Web Sites and I'm having trouble getting it to support PUT and DELETE http methods. Assuming it's something that'll have to go into the web.config file - I've tried a few options from around the interwebs but non of them seem to function properly. Any ideas?

Here's the web.config file as it currently stands:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
    </handlers>
    <security>
    </security>
    <directoryBrowse enabled="false" />
    <caching>
      <profiles>
        <add extension=".php" policy="DontCache" kernelCachePolicy="DontCache" />
        <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
      </profiles>
    </caching>
    <rewrite>
      <rules>
        <rule name="block favicon" stopProcessing="true">
          <match url="favicon\.ico" />
          <action type="CustomResponse" statusCode="404" subStatusCode="1"
          statusReason="The requested file favicon.ico was not found"
          statusDescription="The requested file favicon.ico was not found" />
        </rule>
        <rule name="Cols Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
    <defaultDocument>
      <files>
        <remove value="index.php" />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
like image 967
Daniel Sharp Avatar asked Apr 09 '13 17:04

Daniel Sharp


2 Answers

I do not see that you have handler added into your web.config. I haven't personally tested but someone suggested that PUT and DELETE should work with Windows Azure Website however you would need to configure them correctly on your Windows Azure Websites through web.config.

Following is the simple configuration you can use to set it up:

<configuration>
 <system.webServer>
    <handlers>
        <remove name="PHP53_via_FastCGI" />
        <add name="PHP53_via_FastCGI" path="*.php"
               verb="GET, PUT, POST, HEAD, DELETE" 
               modules="FastCgiModule" 
               scriptProcessor="D:\Program Files (x86)\PHP\v5.3\php-cgi.exe"
               resourceType="Either" requireAccess="Script" />
    </handlers>
 </system.webServer>
</configuration>
like image 127
AvkashChauhan Avatar answered Nov 02 '22 03:11

AvkashChauhan


It didn't work with DELETE as the last option, and here's the code modified for PHP54 on Azure. But thanks to Avkash!

<handlers> 
    <remove name="PHP54_via_FastCGI" />
        <add name="PHP54_via_FastCGI" path="*.php"
               verb="GET, PUT, POST, DELETE, HEAD" 
               modules="FastCgiModule" 
               scriptProcessor="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe"
               resourceType="Either" requireAccess="Script" />
    </handlers>
like image 31
Daniel Sharp Avatar answered Nov 02 '22 04:11

Daniel Sharp