I have installed CiviCRM on my websapce completely new. Upon trying to login the first time I encounter the following issue:
Possibly its due to the parameters not being passed properly to the API. That's why the API throws out the error message "SECURITY: All requests that modify the database must be http POST, not GET."
I guess it has to to with HTTPS-Connection not being established in a proper way.
I have already posted about this issue in the chat ->
Would it be possible to show the browser's network console? I wonder what is the query that caused the error. Is it possible that there is a redirect happening?
Hi again @naechstenliebe.org - I was looking at the codebase and the only places I can see that generate this error definitely only look reachable if the server thinks it is receiving a "GET" request. Specifically in the PHP $_SERVER['REQUEST_METHOD'] == "GET".
As it definitely looks from your browser's perspective like a POST request, I think something in your webserver stack is configured wrongly, and getting in the way.
double-checking that you have the .htaccess provided in the Standalone release in your webroot
looking at any hosting config options for any options around webserver / Apache / htaccess / redirects, and seeing if anything there that looks plausible to adjust
I know others are running Standalone successfully in cPanel type environments, so it should be possible to get it working.
The funny thing is I have installed CiviCRM on a Webspace from a completely different web provider and it worked fine. I used the same tarball.
Regarding your questions:
a) no, nothing at all.
b) no, I have not made any changes to the .htaccess file
c) yes, I get the exact same error message in the log like the one in your screenshot.
Regarding your second post I need to get in touch with my hosting provider since I don't have access to apache configuration. I have already written a mail to them and I am awaiting response.
Today I have investigated further about the issue.
It seems to be a redirect problem. Since the path https://example.com/civicrm/ajax/api4/User/login/ doesn't exist physically, it causes internally an error 404. Therefore the server redirects the request to index.php but for some reason changes it to a GET request.
Experiencing the same "unexpected error" preventing login after fresh installation. Reinstalled several times to no avail. Standard cPanel hosting. Yes, native CiviCRM .htaccess installed. Please advise
Incredible @naechstenliebe.org ! I must admit I've never heard of that option, or mod_negotiation for that matter.
I wonder if we should add this to the default .htaccess or else the Troubleshooting section of the Installation Guide, if it is only applicable in certain contexts (it seems like the common thing with your and @brucew cases is cPanel)
ufundochanged title from Login issue in CiviCRM 5.80.0 to Login issue on CiviCRM Standalone: "unexpected error", "All requests that modify the database must be http POST, not GET"
changed title from Login issue in CiviCRM 5.80.0 to Login issue on CiviCRM Standalone: "unexpected error", "All requests that modify the database must be http POST, not GET"
I know it was enabled on a new CiviHosting account, and it was breaking all FormBuilder forms. But I have to assume that's a newish development for them, because I would imagine others would have mentioned it sooner.
This issue is persisting, if a reverse proxy is being used.
In my case we are using a Cloudflare Zero Trust Tunnel.
To use such a tunnel, the installation of a cloudflared-client is needed on the web server. This client receives the requests from Cloudflare and redirects them to the local CiviCRM installation.
If the local CiviCRM installation is running as HTTP, it will create the same "Unexpected error" and log entries, as described here.
If the local CiviCRM installation uses HTTPS and the reverse-proxy (cloudflared) points at HTTPS, the error disappears.
So there seems to be a problem when changing from HTTPS to HTTP. The faulty flow is like this:
Visitor calls URL via HTTPS from Cloudflare. Cloudflare sends the request to the local client (cloudflared). The local client calls CiviCRM via HTTP on the same machine. If the last step is done via HTTPS, the error disappears.
This happens right after the web-installation of the standalone CiviCRM system. Different values were tested during the installation: language, extensions, etc. But made no difference.
My system: PHP 8.3, MySQL 8.0.41, Ubuntu 22.04., CiviCRM 5.81.1 (Standalone).
@PinkSeal I think your issue will be a slightly different one.
In a setup like that (= reverse proxy, https to the end user client, http to the origin server) there can be issues with a) CiviCRM's attempts to verify SSL connection, b) discrepancy between the BASEURL as the client needs it to look (with https) and the server sees it (with http). Both lead to redirects, which will mess with things including POST requests. On Standalone this is a non-starter because you cant login, but any Civi will struggle...
The simplest solution in my experience is... use HTTPs behind the proxy. (Using cloudflare there are options to use a long lived self signed cert, YMMV)
If not using https, then you need your proxy to assure the server that the client connection is https using the X_FORWARDED_PROTO header. Cloudflare should set that I think, but you also need to configure your server to accept that header from the proxy. How depends on your server config... as I said, using HTTPS is often easiest...
I've noticed that it needs to be a signed and valid certificate. Any unsigned and invalid HTTPS connection will cause this error when logging in. In my case right now, I also did not have any tunnel nor proxy running. Once I got a certificate from Let's Encrypt, it all worked smoothly.
@PinkSeal I'm going to close this issue as we solved the original bug and it seems your case is a much more specific issue related to a reverse proxy situation.
If you want to open a new ticket for that specific issue, then please note that it relates to reverse proxy in the ticket title