Author |
|
mrdj1024
Joined: 03 Apr 2023 Posts: 55 Location: Bridgeton,NJ,USA
|
Posted: Tue 09 May '23 20:19 Post subject: |
|
|
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: 3092 Location: Hilversum, NL, EU
|
Posted: Tue 09 May '23 21:42 Post subject: |
|
|
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
|
Posted: Tue 09 May '23 23:01 Post subject: |
|
|
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: 7371 Location: Germany, Next to Hamburg
|
Posted: Fri 12 May '23 8:38 Post subject: |
|
|
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: 212 Location: Paris, France, EU
|
Posted: Fri 12 May '23 14:51 Post subject: |
|
|
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: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 212 Location: Paris, France, EU
|
Posted: Sun 14 May '23 10:31 Post subject: |
|
|
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
|
Posted: Mon 22 May '23 12:17 Post subject: |
|
|
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
|
Posted: Wed 24 May '23 17:44 Post subject: |
|
|
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
|
Posted: Wed 24 May '23 18:08 Post subject: |
|
|
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
|
Posted: Sat 08 Jul '23 21:43 Post subject: |
|
|
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 |
|