Enable PUT and DELETE methods on Apache 2.4
Asked Answered
S

4

6

I'd like to enable on my Apache 2.4 under linux the PUT and DELETE methods. When clients try to invoke such methods I get a "405 Method Not Allowed" as answer.

On server side my PHP script handle such requests but it seems filtered by the server itself (that's makes the difference from the similar already answered question - Moreover other questions seems to refers to an old version of Apache).

Can I manage some configurations on .htaccess file or I have to modify the .conf files under /etc/apache2?

Thanks a lot.

Statesmanship answered 27/5, 2016 at 13:34 Comment(2)
Possible duplicate of How to enable and use HTTP PUT and DELETE with Apache2 and PHP?Colossal
No. My script already handles such methods but as stated they seems filtered out by apache; my script is not invoked at all.Statesmanship
B
8

Try the following changes on your server:

Open "/etc/httpd/conf/httpd.conf" and look for the following blocks:

<Limit GET POST OPTIONS PROPFIND>
  Order allow,deny Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
   Order deny,allow Deny from all
</LimitExcept>

Then just add PUT and DELETE after PROPFIND. Then Restart httpd by "/sbin/service httpd restart" or service httpd restart.

Note: In some servers , mostly the ones with a control panel (DA,cPanel,..) you may change this file :/etc/httpd/conf/extra/httpd-directories.conf

I hope it solves your problem.

Burdick answered 22/10, 2016 at 7:7 Comment(0)
T
0

You can use allowmethods_module to enable that.

It's been available since apache version 2.3 but still experimental though.

<Location "/path/to/directory">
   AllowMethods PUT DELETE
</Location>
Thimbleweed answered 6/1, 2021 at 12:45 Comment(2)
Thanks for pointing AllowMethods out, but the correct syntax is AllowMethods PUT DELETE.Devote
Thanks @elmicha; Updated!Thimbleweed
T
0

For Debian/Ubuntu.

In your conf:

<Location "/">
    AllowMethods GET PUT
</Location>

In console:

sudo a2enmod allowmethods
sudo systemctl restart apache2.service
Transpacific answered 27/1, 2021 at 11:15 Comment(0)
V
-3

I got the same error and the root cause is the redirects to https (80-443) are not occurring which one of the things are causing the docker client to fail while allowing the browser to work. I added below directives in Apache httpd (apache2) and it worked for me.

<VirtualHost *:80>
        RedirectPermanent / https://%{SERVER_NAME}/
        RewriteEngine On
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>


<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
        SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
        #   General setup for the virtual host
        ServerName example.org
        ServerAdmin [email protected]
        ErrorLog /tmp/error_log
        SSLProxyEngine On
        ProxyRequests Off
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
        AllowEncodedSlashes NoDecode

        ProxyPreserveHost On
        ProxyPass / http://<BackendIP>/ connectiontimeout=10 timeout=3600
        ProxyPassReverse / http://<BackendIP>/
</VirtualHost>
Vela answered 1/2, 2022 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.