Optimizing VestaCP phpfcgid template configuration process multi-memory exhaustion 500 errors

VestaCP After the WEB service selects the "phpfcgid" template, a large number of PHP-CGI processes cause the memory to be quickly exhausted:

  • I was basically running out of memory for a few hours after restarting the server.
  • The previously idle PHP-CGI process is not killed, and one process runs nearly 1 subprocesses, consuming at least 20M of memory.

Used in SSH htop command (installation required), you can view this status ▼

After VestaCP's WEB service selects the "phpfcgid" template, a large number of PHP-CGI processes cause the memory to be quickly exhausted.

If you get an error message "-bash: htop: command not found" when you use the htop command, please see this tutorial for the solution ▼

A large number of PHP-CGI processes cause the memory to be quickly exhausted. The problem lies in VestaCPCentOSIn the phpfcgid template, an unoptimized configuration is used.

  • VestaCP in the phpfcgid template, set 1 PHP-CGI process to run up to 20 child processes.

See /usr/local/vesta/data/templates/web/httpd/phpfcgid.sh Line 13 of the file:

export PHP_FCGI_CHILDREN=20

However, such a setup violates Apache's warning in the PHP subprocess management documentation:

PHP child process management (PHP_FCGI_CHILDREN) should always be disabled with mod_fcgid, which will only route one request at a time to application processes it has spawned; thus, any child processes created by PHP will not be used effectively. (Additionally, the PHP child processes may not be terminated properly .) By default, and with the environment variable setting PHP_FCGI_CHILDREN=0, PHP child process management is disabled.

Because in Apache's mod_fcgid module, the PHP-CGI process can only respond to one request and run at a time, the PHP-CGI child process is very inefficient.

Therefore, the settings for PHP subprocess management should be disabled directly ▼

PHP_FCGI_CHILDREN=0

At the same time, if you already have a generated virtual host, you need to modify the configuration files of all websites ▼

/home/用户名/web/域名/cgi-bin/fcgi-starter

After opening the fcgi-starter configuration file, insert the following ▼

export PHP_FCGI_CHILDREN=20

Modify to ▼

export PHP_FCGI_CHILDREN=0
  • After modification, PHP subprocess management will be turned off in mod_fcgid mode.
  • The PHP-CGI process will no longer spawn child processes, which can save a lot of memory.

Also, VestaCP does not set a termination mechanism for idle processes:

  • All newly executed PHP-CGI processes will continue to use memory until the system is rebooted.

To fix this, just add the mod_fcgid config file /etc/httpd/conf.d/fcgid.conf Add the following settings in ▼

FcgidIdleTimeout 120
  • Set Apache to automatically kill PHP-CGI processes that are idle for 2 minutes (120 seconds).

After the setup is complete, restart the Apache service ▼

service httpd restart

After the service is restarted, the hundreds of PHP-CGI processes that were previously displayed in HTOP will no longer be displayed.

Typically, a single PHP-CGI process for a single Vesta CP user consumes 30 to 40M of memory, fully satisfyingLinuxhost requirements.

therefore,Internet marketingpeople want to do wellSEO, it is very important to optimize the configuration of Vesta CP and templates ^_^

You can take a look at the following tutorials on the VestaCP panel ▼

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "Optimizing VestaCP phpfcgid Template Configuration Process Multiple Memory Exhaustion 500 Errors", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-735.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top