Difference between FastCgiExternalServer and FastCgiServer in Apache FastCGI PHP?
Asked Answered
D

2

10

Just let me state that I am new to FastCGI. I have MAMP's Apache on my OS X machine. Default PHP handler was Apache Handler 2.0 (libphp5.so). I wanted to change to FastCGI and followed the answer here: How to configure Apache to run PHP as FastCGI on Ubuntu 12.04 via terminal?

I added the following at the end of my httpd.conf:

<IfModule mod_fastcgi.c>
   AddHandler php5.fcgi .php
   Action php5.fcgi /php5.fcgi
   Alias /php5.fcgi /Applications/MAMP/fcgi-bin/php5.fcgi
   FastCgiServer /Applications/MAMP/fcgi-bin/php5.fcgi -socket /Applications/MAMP/tmp/php-fcgi/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
   #FastCgiExternalServer /Applications/MAMP/fcgi-bin/php5.fcgi -socket /Applications/MAMP/tmp/php-fcgi/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
   <Directory /Applications/MAMP/fcgi-bin>
       Order allow,deny
         Allow from all
   </Directory> 
</IfModule>

However, as you can see, FastCgiExternalServer is commented out. Instead, I had to use FastCgiServer cause otherwise Apache was giving me the following errors when trying to request a page:

[Fri May 06 23:25:22 2016] [error] [client ::1] (2)No such file or directory: FastCGI: failed to connect to server "/Applications/MAMP/fcgi-bin/php5.fcgi": connect() failed

[Fri May 06 23:25:22 2016] [error] [client ::1] FastCGI: incomplete headers (0 bytes) received from server "/Applications/MAMP/fcgi-bin/php5.fcgi"

But /Applications/MAMP/fcgi-bin/php5.fcgi exists and its content is:

#!/bin/bash
PHP_CGI=/Applications/MAMP/bin/php/php5.6.2/bin/php-cgi
exec $PHP_CGI

What's the difference between FastCgiServer and FastCgiExternalServer and why FastCgiExternalServer didn't work in my case but FastCgiServer worked?

Durning answered 6/5, 2016 at 22:0 Comment(1)
If you're doing PHP fastcgi in 2016, look at mod_proxy_fcgi and php-fpm instead of mod_fastcgi.Arlana
A
15

FastCgiServer is a server that mod_fastcgi will do process management for -- spinning instances up and down and giving them a unix domain socket to listen on. No outside action is required to start the fastcgi server.

FastCgiExternalServer is a server that mod_fastcgi will NOT do any process management for -- it will just reach out to the unix or TCP socket you tell it to use and forward requests/responses to it. You, or some daemon outside of httpd, must be starting something to listen on the listed socket. The most basic way is the 'fcgistarter' utility, other options are things like php-fpm.

Arlana answered 6/7, 2016 at 13:26 Comment(0)
N
1

If performance is reason, I would say use Apache with fcgid. This is considered better for performance. To deal with performance, mod_fcgid starts multiple instances of CGI programs to handle concurrent requests. This is alternate to mod_php for PHP developers, giving higher performance. This article I found is great resource to learn

http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html

Nude answered 11/7, 2016 at 19:7 Comment(4)
To have better performance use nginx instead of apache (look google: nginx apache performance).Verduzco
@KamilKiełczewski presumed Nginx performance advantage is not accurate across the board. For static content, yes, but not dynamic content, where they are approximately equivalent. One example page from googling: hostingadvice.com/how-to/nginx-vs-apacheInternecine
@Internecine But future web direction is is static Client (for instance build on Angular2) for generate dynamic page content (client is static pure JS+HTML+CSS files and all dynamics starts on browser side after load this static files and run JS) and that client comunicate with backend only by RESTfull requests (json, ajax) - so static performance is very important :) So in MVC model the M is on backend, and VC is on frontend :)Verduzco
@KamilKiełczewski yes static is important, I did not say otherwise, and it is where Nginx has advantages, but the dynamic part Nginx does not provide better performance. It doesn't matter the order of the parts. If one requires the client to do all dynamic, then you are shipping everything to the client, which can be an underpowered smartphone. Not wise for many/most configurations other than the simplest applications.Internecine

© 2022 - 2024 — McMap. All rights reserved.