CGI, FastCGI and PHP-FPM - Some basic questions

SYSTEM INFORMATION
OS type and version REQUIRED
Virtualmin version REQUIRED

Hi

I have some newbie question I was hoping to get answered.

Background

  • CGI
    • the slowest php mode to run in
    • allows cgi apps to run in cgi-bin
  • FastCGI
    • a much quicker implementation of CGI with permanent child process
    • allows cgi apps to be run in cgi-bin
  • PHP-FPM
    • Uses the FastCGI for processing PHP requests
    • Is only for PHP

The questions

  • Is running CGI apps now considered an old way of doing things?
  • Can you confirm that if I run PHP-FPM there is no way to run CGI apps?
  • I can remove the PHP CGI module as this is not needed for PHP-FPM in any way?

Thanks

Generally, yes. For large applications, having them load all their dependencies on every run is wildly inefficient. For tiny little apps that don’t load a bunch of extra junk, it may be fine. e.g. if you just need to serve out one tiny API endpoint and you can write a Perl/Python/Ruby/PHP script that runs in a few milliseconds, then it may make sense to use CGI (but an app server probably isn’t notably worse than CGI in those cases, either…it’d be about balancing CPU vs. memory usage).

No. FastCGI can not run CGI scripts. It requires applications built to communicate via the FastCGI protocol, which is not the CGI protocol. A CGI script is not a FastCGI script without a wrapper. We provide a wrapper (fcgiwrap), so you can run CGI applications on systems that don’t have suexec available, but it does not mean FastCGI is running CGI scripts. fcgiwrap runs CGI scripts and communicates with the web server via the FastCGI protocol. It is the application server in this context.

No. I deny that. What gave you that idea?

Where do you see a PHP CGI module?

1 Like

Just learning about CGI :smile: and didnt really know.

apt-get install php8.1-cgi

Sorry for all the arrows, this is my dev server and I have been messing about.

I think I should of said php extensions. :smile:

And thanks for the long response. I will add this to my notes.

We didn’t install php-cgi. That’s your business, not mine. (Though it might be a dependency of one of the other PHP packages we install…I don’t think so, though. I can’t think of any reason any of the other PHP packages would depend on php-cgi.)

I am sure I installed it :smile: I will also be uninstalling it.

It will of been installed when i used the install script from the mutiplephp documentation.

Actually, it probably is a dependency of one of the other PHP packages, as we’ve never installed it, and we’ve historically had the ability to run PHP apps as CGI, so I guess it must have always been there.

is it not needed for this

image

Yeah, but you almost certainly don’t need that. I only ever use FPM. Sometimes I like to have CGI for debugging other execution modes, but it’s not how you should ever run a large PHP application.

1 Like

I mean, Virtualmin detects available execution modes when the config check runs. So, it won’t offer that option if you don’t have php-cgi and that’s a harmless thing.

1 Like

Perfect. I will only ever use PHP-FPM, but is good to know what these things do, just in-case.

You have a good one.

one of the things I really love about the php-fpm framework is you can control the max child processes - so a website becoming very busy will NOT spawn hundreds of child processes — perhaps my old system with FastCGI was not configured properly and that was why I did have 100s that then triggered OOM issues. We specifically changed over to php-fpm to have better control over excessive processes that used to lead to OOM issues.

1 Like

A bit of self promotion but people might find this useful. :smile:

1 Like

Promoting docs you write is always great!

But, this is a bit misleading: “Virtualmin only supports CGI apps out of the box. You can manually add FastcGI support.”

Virtualmin supports, with full UI support, PHP apps via many execution modes, including FastCGI, and multiple versions of PHP (when installed). Virtualmin also supports setting up proxy rules to any other kind of application server (many app servers do not use FastCGI, they just use HTTP, and that is the most common way to run most apps other than PHP at this point in history). FastCGI is on the way out, too.

We brought proxy paths support from Pro into GPL just recently to ease that use case. And Virtualmin Pro is about to get app server and container-based app support (where it has some awareness of the app server or docker/podman and configures the proxy rules automatically).

So, nearly any way you want to run apps in Virtualmin is very easy to do.

1 Like

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