Serving a php contact form

I have set up a site for my daughter’s portfolio. She has a simple contact page written in php. How do I get Caddy to execute the php instead of displaying it? Check at taylorstrutton.com/contact.php.

I am running abiosoft’s docker container. Should I add http.cgi or use the php variant of the container…

Any thoughts?

You’ll need a PHP process running, usually FPM (FastCGI Process Manager) is the weapon of choice.

You can run FPM in another Docker container quite easily (I use this setup myself - the official php:fpm container), or you can use Abiosoft’s php-tagged container, which is also a good option.

Once you’ve got PHP running, you can use the fastcgi directive (which includes a php preset) to have Caddy process the PHP instead of simply serving the PHP file directly to the client.

https://caddyserver.com/docs/fastcgi

If the contact form is the only part of your daughter’s website that requires PHP, you may wish to keep the site entirely static and offload form handling to a third party service such as formspree. Maintaining PHP and keeping up with security updates does require ongoing attention.

Should I add http.cgi…

This is an option for you if you don’t want to use fastcgi and maintain a separate PHP server. An example is shown at the bottom of the page at CGI for Caddy.

1 Like

I’ll second the recommendation for a service like Formspree.

Using CGI instead of FastCGI for PHP certainly seems like the hard way to go about it :stuck_out_tongue:

Can’t say I’ve ever looked into it myself, but I’m impressed you’ve got a writeup on it, heh.

Using CGI instead of FastCGI for PHP certainly seems like the hard way to go about it :stuck_out_tongue:

It’s definitely a tradeoff. CGI may be more trouble to initially configure on the Caddy side but it doesn’t require a separate PHP service that needs to be monitored.

Just an update:
As with everything else Caddy and Docker, all you really have to do is just try it. The abiosoft/caddy docker container with php just works. I had to mess around getting php mail working but that happens everywhere. After that it just works.
Loving Caddy so far (second site up in a few days with almost no issues). Thanks to the devs and keep up the good work.
When I get this setup all packed up on github I will post a link here for anyone else who stumbles down this path. See this repo for how I solved this.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.