logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> News & Hangout View previous topic :: View next topic
Reply to topic   Topic: Why is it recommended to use fcgid ?
Author
mrdj1024



Joined: 03 Apr 2023
Posts: 55
Location: Bridgeton,NJ,USA

PostPosted: Tue 09 May '23 20:19    Post subject: Reply with quote

i use php 8.1 running as apache module,why is it recommended to use fcgid?
im not overly sure the pros and cons of making the switch,but i will if its needed to keep things up to date.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3094
Location: Hilversum, NL, EU

PostPosted: Tue 09 May '23 21:42    Post subject: Reply with quote

FCGI(mod_fcgid) memory usage of Apache is less en the Speed is on par when running as module. There are advantages to running PHP with FCGI. Separating the PHP code from the web server removes 'bloat' from the main server, and improves the performance of non-PHP requests. Secondly, having one permanent PHP process as opposed to one per apache process means that shared resources like persistent MySQL connections are used more efficiently. And maybe even more important is stability, since I run FCGI my server never crashed primarily caused by php (extension) errors and out of memory errors.

Also with mod_fcgid you can run multiple times with different PHP-versions.

Our moderator James Blond is the mod_fcgid specialist ! He can mention maybe more advantages.
Back to top
mrdj1024



Joined: 03 Apr 2023
Posts: 55
Location: Bridgeton,NJ,USA

PostPosted: Tue 09 May '23 23:01    Post subject: Reply with quote

which modules do i need loaded in httpd.conf for mod fcgid to work?
i also use strict transport security and the url rewrite to https.
so most of my changes i make are in the ssl.conf and not the vhost field.
would i need to add the fcgid configuration parameters to my ssl.conf file?
i also use mod evasive,is that compatible with fcgid?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Fri 12 May '23 8:38    Post subject: Reply with quote

You only need to download mod_fcgid from the Downloads page from AL. Load the module in httpd.conf
And configure it global or in each vhost.

It would be a hassle to paste all the code here. We have a tutorial how to use mod_fcgid https://www.apachelounge.com/viewtopic.php?t=2394

If you still have a question please ask again.
Back to top
Otomatic



Joined: 01 Sep 2011
Posts: 213
Location: Paris, France, EU

PostPosted: Fri 12 May '23 14:51    Post subject: Reply with quote

Hi,

This is how I use the FCGI mode with Wampserver.

- Where are installed the different PHP versions
e:\wamp64\bin\php\php7.4.33\
e:\wamp64\bin\php\php8.0.18\
...
e:\wamp64\bin\php\php8.2.6\

- Modifications of httpd.conf file (added lines)
Code:
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
  FcgidMaxProcessesPerClass 300
  FcgidConnectTimeout 10
  FcgidProcessLifeTime 0
  FcgidMaxRequestsPerProcess 0
  FcgidMinProcessesPerClass 0
  FcgidFixPathinfo 0
  FcgidZombieScanInterval 20
  FcgidMaxRequestLen 536870912
  FcgidIOTimeout 120
  FcgidTimeScore 3
  FcgidPassHeader Authorization
  Define PHPROOT ${INSTALL_DIR}/bin/php/php
</IfModule>

The variable ${INSTALL_DIR} corresponds to the installation path of Wampserver which is e:/wamp64
And PHPROOT will contain the installation path of the different PHP versions without the version number.

A VirtualHost using PHP as an Apache module looks like this:
Code:
<VirtualHost *:80>
  ServerName mysite
  DocumentRoot "G:/www/myfolder"
  <Directory "G:/www/myfolder/">
     Options +Indexes +Includes +FollowSymLinks +MultiViews
     AllowOverride all
     Require local
  </Directory>
</VirtualHost>

To switch it to FCGI mode with any version of PHP - of course provided it has been installed - simply add a few lines to the end of the VirtualHost:
Code:
  <IfModule fcgid_module>
    Define FCGIPHPVERSION "7.4.33"
    FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
    <Files ~ "\.php$">
      Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
    </Files>
  </IfModule>

To obtain, in the end, as VirtualHost:
Code:
<VirtualHost *:80>
  ServerName mysite
  DocumentRoot "G:/www/myfolder"
  <Directory "G:/www/myfolder/">
     Options +Indexes +Includes +FollowSymLinks +MultiViews
     AllowOverride all
     Require local
  </Directory>
  <IfModule fcgid_module>
    Define FCGIPHPVERSION "7.4.33"
    FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
    <Files ~ "\.php$">
      Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
    </Files>
  </IfModule>
</VirtualHost>

And, if you want to do it for HTTPS in httpd-ssl.conf, it's the same principle:
Code:
Define SERVERNAMEVHOSTSSL mysite
Define DOCUMENTROOTVHOSTSSL G:/www/myfolder
<VirtualHost *:443>
  ServerName ${SERVERNAMEVHOSTSSL}
  DocumentRoot "${DOCUMENTROOTVHOSTSSL}"
  ServerAdmin ${ADMINVHOSTSSL}
  SSLEngine on
  SSLCertificateFile      "${CERTIFS}/Site/${SERVERNAMEVHOSTSSL}.crt"
  SSLCertificateKeyFile   "${CERTIFS}/Site/${SERVERNAMEVHOSTSSL}.key"
  <Directory "${DOCUMENTROOTVHOSTSSL}/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride all
    Require local
  </Directory>
  CustomLog "${INSTALL_DIR}/logs/custom.log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  <IfModule fcgid_module>
    Define FCGIPHPVERSION "7.4.33"
    FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
    <Files ~ "\.php$">
      Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
    </Files>
  </IfModule>
</VirtualHost>
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Fri 12 May '23 16:00    Post subject: Reply with quote

@Otomatic

You should really take a look at mod_macro https://httpd.apache.org/docs/trunk/mod/mod_macro.html
Back to top
Otomatic



Joined: 01 Sep 2011
Posts: 213
Location: Paris, France, EU

PostPosted: Sun 14 May '23 10:31    Post subject: Reply with quote

Hi,

Thank you. I already use mod_macro, but for personal use, not for Wampserver.
Wampserver is a development server although some use it as a production server.
To learn, it is necessary to be able to see the results of the actions done.
However, mod_macro generates "virtual" results and that's why, with Wampserver, the options to create, add, modify VirtualHost give concrete and visible results in the httpd-vhosts.conf, httpd-ssl.conf or httpd.conf files.

This could be the subject of a new thread.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1266
Location: Amsterdam, NL, EU

PostPosted: Mon 22 May '23 12:17    Post subject: Reply with quote

There is a downside to using mod_fcgid. If PHP crashes before it could produce any output the user will be confronted with an error 500: "end of script output before headers". With PHP loaded through mod_php + mpm_winnt Apache will crash together with PHP. But in my experience the user will hardly notice it because Apache will be relaunched by the other httpd.exe process and try to run the PHP-script again. On my production server PHP 8.1 occasionally crashes with an OPcache error. A crash in PHP with mod_php will lead to a slower response but not to a fatal error 500.

On a Drupal 9 site OPcache is heavily used with a cache hit rate above 99.5%:
Code:
Cache hits    1965736
Cache misses     7711
But sometimes a PHP script behaves terrible and defeats OPcache. The last time this happened was more than a week ago, so I do not have the event information anymore.
Back to top
dpat99



Joined: 15 May 2023
Posts: 5

PostPosted: Wed 24 May '23 17:44    Post subject: Reply with quote

Jan-E wrote:


On a Drupal 9 site OPcache is heavily used with a cache hit rate above 99.5%:
Code:
Cache hits    1965736
Cache misses     7711
But sometimes a PHP script behaves terrible and defeats OPcache. The last time this happened was more than a week ago, so I do not have the event information anymore.


Can I ask, how did you find those statistics for the Drupal 9 site? I cant seem to find it.

Also, wont the client notice the slow response based on server location being distance? (I am thinking about cdn usage etc)?
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1266
Location: Amsterdam, NL, EU

PostPosted: Wed 24 May '23 18:08    Post subject: Reply with quote

These are just the general OPcache stats. I know they are for the Drupal 9 site, because PHP 8.1 only serves that site. Distance is not really an issue. Low traffic, Dutch users, Dutch server. The first user after a restart will notice some delay, but no Errors 500 anymore since I switched from mod_fcgid to mod_php.
Back to top
mrdj1024



Joined: 03 Apr 2023
Posts: 55
Location: Bridgeton,NJ,USA

PostPosted: Sat 08 Jul '23 21:43    Post subject: Reply with quote

finally made the switch to http/2 and fcgid!
noticed less memory consumption when running php scripts
here are the values in my httpd.conf file
Code:

FcgidMaxProcessesPerClass 300
  FcgidConnectTimeout 10
  FcgidProcessLifeTime 0
  FcgidOutputBufferSize 1000000000
  FcgidMaxRequestsPerProcess 0
  FcgidMinProcessesPerClass 0
  FcgidFixPathinfo 0
  FcgidZombieScanInterval 20
  FcgidMaxRequestLen 1000000000
  FcgidIOTimeout 120
  FcgidTimeScore 3
  FcgidPassHeader Authorization
  Define PHPROOT ${INSTALL_DIR}/bin/php/php

and heres whats in my httpd-ssl.conf
------------------------------------------------------------
Code:

<IfModule fcgid_module>
    Define FCGIPHPVERSION "8.1.16"
    FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
    <Files ~ "\.php$">
      Options -Indexes -Includes +FollowSymLinks -MultiViews +ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
    </Files>
  </IfModule>
Back to top


Reply to topic   Topic: Why is it recommended to use fcgid ? View previous topic :: View next topic
Post new topic   Forum Index -> News & Hangout