Contact form on a NGINX web server

Has anyone gotten the Elements API and PHP intact Form working on a NGINX web server?

I have PHP 8.2.35 running on this nginx server and the API refuses to respond. If I add the ?apicheck argument. nothing ever happens. Form submissions always fail instantly. Can’t even get logs to generate, and the directory permissions are properly setup allowing the web nginx user write privileges to that directory.

All credentials are valid and work. If I create a separate php script using phpmailer with the same credentials, the emails work just find.

Quite a few hosts use nginx and forcing the use of apache isn’t the right move here. Telling customers they have to move their hosting to another provider using apache as the web server is also not an option.

Any help here would be greatly appreciated.

intact Form should be Contact form

Hi @dejees

Sorry to hear you are having troubles, but nobody is forcing you or your web host to use Apache. The form should work fine on NGINX web server. :slightly_smiling_face:

It might be a mod_security rule your web host has set up that is blocking the submission. Do you have the option to disable mod_security in your web hosting control panel temporarily to test?

Also it would be great to get your web host to review the server logs when you click the “Submit” button so they can see if any specific errors are getting logged in the server’s error log or PHP error log.

Sorry for not responding sooner, away with family issues.

I think I have narrowed it down to the .htaccess file Elements puts in the …/com.elementsplatform.formspack/spi directory

NGINX does use/reaad .htaccess files, it ignores them. The I open the .htaccess in a text editor the first comments line specifically says “Forms API - Apache Configuration”. Does elements have something for an NGINX server configuration.

Looks like since NGINX isn’t handling the rewrite rules and other stuff in that .htaccess file.

For reference, even submitting the URL with a ?apicheck ending is totally ignored and nothing happened other than the base page loading.

So my interpretation is that elements is tying this down to either an apache server or another server that can handle apache directives in a .htaccess file like Litespeed.

I have tested this on nothing an apache server and a Litespeed server and the contact form works great on both of those. The issue a the customer has an NGINX server and this is frustrating the contact form cannot work on any web server. While NGINX is not as popular as Apache, many use it.

Again, any help appreciated.

I think I have narrowed it down to the .htaccess file Elements puts in the …/com.elementsplatform.formspack/api directory

Found this below with further research…

Does NGINX use .htaccess?

No. NGINX never reads a per-directory .htaccess file. There is no setting to enable it either—the feature does not exist in stock NGINX. Any rule you would put in .htaccess on Apache goes directly into your NGINX server { } or location { } block instead, and takes effect after you reload NGINX with nginx -s reload.

Can the elements team provide the needed directives so the nginx server/location blocks can be modified correctly? Also, are there any other .htaccess files elements generates that I simply haven’t found yet?

Please advise. Thank you.

Hi @dejees

You are correct that .htaccess files aren’t read by NGINX.

The good news is that the underlying Forms API isn’t inherently dependent on Apache. It uses the Slim PHP framework, which supports NGINX environments too. However, the web server needs to be configured to route API requests correctly.

You’ve reported two separate issues:

  1. You can’t get the API check working.

  2. The form is not submitting (failing instantly upon submit).

While possible, these two aren’t necessarily connected. I think the most important thing to troubleshoot is the second issue with the form failing to submit.

Is this your server you are testing the form on? If so can you pass any error logs you are seeing on the server when you click the submit button on the form? For example in the PHP error log, or the NGINX error log.

Let me know so we can further look into this.

For clarification, when I say the form is not submitting…

I mean the form does fire the error event saying the email was not sent, which is my message in the error event. I know outbound phpmailer sent email works on that server because executing a script on the terminal line using php and the same credentials works/sends fine.

As for the API check by appending ?apicheck to the contact form URL, the page just loads, no other messages on the NGINX server. On a separate Litespeed server, where all the exact same published code exists, I get a green bar at the top, so I know it’s working and emails send just fine, no joy on the NGINX server, no green bar at the top on ?apicheck and instant failure in the error event when submitting the form.

Hopefully that better explains things.

Yes this is on a VPS server, running Debian 12, PHP 8.2 latest update and NGINX.

When I check the php8.2-fpm.log, no entries. Which makes me believe the api is failing to execute.

Also, when checking the nginx error log specified in the NGINX config for that site, no error messages either.