I proceed to explain the problem and scenario a bit complex for my limited knowledge.
initially I thought it was some problem associated with the performance of my scripts and queries, so I created this post on the site in Spanish: LINK
but after researching most of the afternoon; I'm about to attribute it all to a misconfiguration of my dev environments.
I am working with 2 devices server:
Local:
- Windows 10
- Laragon Server
Development:
- Ubuntu 20.04
- XAMPP
in this case I will focus on local:
I have configured the laragon stack to support virtual hosts and run 2 versions of PHP (7.2 / 7.4) i have follow this 2 guides: Link 1 AND Link 2
my apache configuration:
Define SRVROOT "C:/laragon/bin/apache/httpd-2.4.47-win64-VS16" ServerRoot "C:/laragon/bin/apache/httpd-2.4.47-win64-VS16" Listen 80 LoadModule access_compat_module modules/mod_access_compat.so LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule allowmethods_module modules/mod_allowmethods.so LoadModule asis_module modules/mod_asis.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authz_core_module modules/mod_authz_core.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule cgi_module modules/mod_cgi.so LoadModule dir_module modules/mod_dir.so LoadModule env_module modules/mod_env.so LoadModule headers_module modules/mod_headers.so LoadModule include_module modules/mod_include.so LoadModule isapi_module modules/mod_isapi.so LoadModule log_config_module modules/mod_log_config.so LoadModule mime_module modules/mod_mime.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so LoadModule ssl_module modules/mod_ssl.so LoadModule version_module modules/mod_version.so <IfModule unixd_module> User daemon Group daemon </IfModule> ServerAdmin [email protected] ServerName Laragon <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "C:/laragon/www" <Directory "C:/laragon/www"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride None Require all granted </Directory> <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> <Files ".ht*"> Require all denied </Files> ErrorLog "logs/error.log" LogLevel error <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog "logs/access.log" common </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/" </IfModule> <IfModule cgid_module> # # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # #Scriptsock cgisock </IfModule> <Directory "${SRVROOT}/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule headers_module> RequestHeader unset Proxy early </IfModule> <IfModule mime_module> TypesConfig conf/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz </IfModule> # Configure mod_proxy_html to understand HTML4/XHTML1 <IfModule proxy_html_module> Include conf/extra/proxy-html.conf </IfModule> <IfModule ssl_module> SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule> AcceptFilter http none AcceptFilter https none EnableSendfile Off EnableMMAP Off IncludeOptional "C:/laragon/etc/apache2/alias/*.conf" IncludeOptional "C:/laragon/etc/apache2/sites-enabled/*.conf" Include "C:/laragon/etc/apache2/httpd-ssl.conf" Include "C:/laragon/etc/apache2/mod_php.conf" ScriptAlias /php72 "C:/laragon/bin/php/php72" Action application/x-httpd-php72-cgi /php72/php-cgi.exe <Directory "C:/laragon/bin/php/php72"> AllowOverride None Options None Require all denied <Files "php-cgi.exe"> Require all granted </Files> </Directory> the virtual hosts:
<VirtualHost *:80> DocumentRoot "D:/webdev/Local/test1/" ServerName test1.me ServerAlias *.test1.me <Directory "D:/webdev/test1/"> AllowOverride All Require all granted </Directory> <FilesMatch "\.php$"> SetHandler application/x-httpd-php72-cgi </FilesMatch> </VirtualHost> Alias of phpmyadmin
Alias /phpmyadmin "C:/laragon/etc/apps/phpMyAdmin/" <Directory "C:/laragon/etc/apps/phpMyAdmin/"> Options Indexes FollowSymLinks MultiViews AllowOverride all Require local </Directory> MySQL configuration
[client] #password=your_password port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 socket=/tmp/mysql.sock key_buffer_size=512M max_allowed_packet=4096M table_open_cache=256 sort_buffer_size=32M read_buffer_size=32M read_rnd_buffer_size=32M myisam_sort_buffer_size=128M thread_cache_size=16 secure-file-priv="" explicit_defaults_for_timestamp=1 datadir= "C:/laragon/data/mysql" lower_case_table_names=2 sql_mode="" wait_timeout=28800 interactive_timeout=28800 [mysqldump] quick max_allowed_packet=4096M PHP configuration for both version (7.2/7.4)
file_uploads = On upload_max_filesize = 4096M max_file_uploads = 100 allow_url_fopen = On memory_limit = 3G post_max_size = 600M max_execution_time = 5000 max_input_time = 5000 max_input_vars = 5000 date.timezone= America/Panama error_reporting = E_ALL display_errors = on display_startup_errors = on html_errors = On session.gc_maxlifetime = 2592000 session.cache_expire = 2592000 As you can see I am serving php 7.4 by default using apache handler 2.0; I am serving php 7.2 using an alias.
- phpmyadmin => php 7.4 Apache Handler 2.0
- test1.me => php 7.2 CGI/FastCGI
error logs of MySQL:
2021-10-02T04:26:59.472441Z 35 [Note] Aborted connection 35 to db: avipac_dbproducts' user: 'root' host: 'localhost' (Got an error writing communication packets) error logs of Apache:
[Fri Oct 01 23:22:17.806390 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] Script timed out before returning headers: php-cgi.exe, referer: http://test1.me/ [Fri Oct 01 23:23:43.661155 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] AH01215: PHP Fatal error: Allowed memory size of 3221225472 bytes exhausted (tried to allocate 20480 bytes) in D:\\webdev\\Local\\test1\\control\\classgeneric\\class.managerdb.php on line 111: C:/laragon/bin/php/php72/php-cgi.exe, referer: http://test1.me/ [Fri Oct 01 23:23:43.676759 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] AH01215: PHP Fatal error: Allowed memory size of 3221225472 bytes exhausted (tried to allocate 65536 bytes) in Unknown on line 0: C:/laragon/bin/php/php72/php-cgi.exe, referer: http://test1.me/ [Fri Oct 01 23:23:43.676759 2021] [cgi:error] [pid 3808:tid 1108] [client 127.0.0.1:61857] AH01215: PHP Fatal error: Allowed memory size of 3221225472 bytes exhausted (tried to allocate 24576 bytes) in Unknown on line 0: C:/laragon/bin/php/php72/php-cgi.exe, referer: http://test1.me/ [Fri Oct 01 23:24:59.451291 2021] [cgi:error] [pid 3808:tid 1104] [client 127.0.0.1:53918] Script timed out before returning headers: php-cgi.exe, referer: http://test1.me/ I definitely accept that the mysql query is relatively large for a local environment on Windows; but the problem is that the same query is executed by apache handler 2.0 and php 7.4 in less than 1 second ... but in CGI / FastCGI it stops when it reaches the timeout (180 seconds / 3 minutes) ... I have had the delicacy of set the same settings for FastCGI and Apache Handler 2.0 but not concive because one fails and the other does not.
Of course, of course, that's why one of my doubts is that they tell me in my setup what configuration I need to improve FastCGI. It is what I mainly ignore. (where, how and what).
it is possible that someone tell me in my setup what configuration I need to improve FastCGI. It is what I mainly ignore. (where, how and what) I really don't understand why I can't make Fast CGI at least not break and work like Apache does ...
I do not know what is wrong, what I need or how to solve these errors ... I know that CGI / FastCGI is taking a long time and consuming a lot of memory but I don't know why it not work and Apache Handler Work correctly
Or exist any way to proxy Apache Handler 2.0 instead of use php-cgi via FastCGI alias?
Illustrative Images Apache Handler 2.0:
CGI/FastCGI:
UPDATE #1
i find this configuration file: Note: I am assuming that this configuration file is important; but I have no idea of its functionality or what things should I add, remove or modify to make FastCGI behave like Apache Handler 2.0.
LoadModule fcgid_module "C:/laragon/etc/apache2/modules/mod_fcgid-2.3.10-win64-VS16.so" <IfModule fcgid_module> FcgidInitialEnv PATH "C:/laragon/bin/php/php74;C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;" FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:/Windows/Temp" FcgidInitialEnv TMP "C:/Windows/Temp" FcgidInitialEnv windir "C:/Windows" # 10 hrs: in case you have long running scripts, increase FcgidIOTimeout FcgidIOTimeout 36000 FcgidIdleTimeout 36000 FcgidProcessLifeTime 36000 FcgidBusyTimeout 36000 FcgidConnectTimeout 3600 FcgidMaxRequestsPerProcess 0 FcgidMaxProcesses 50 FcgidMaxRequestLen 81310720 # Location php.ini: # FcgidInitialEnv PHPRC "C:/laragon/bin/php/php74" FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 0 <Files ~ "\.php$>" AddHandler fcgid-script .php Options +ExecCGI FcgidWrapper "C:/laragon/bin/php/php74/php-cgi.exe" .php </Files> </IfModule> 

