thedevopsguy has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys,

I've been looking a place to get more knowledge on PERL/Apache interaction and this seems a good place to start.

This is not an actual problem "per se" more like a good-to-have "feature" in my current environment.

I have my Apache running Perl with CGI and virtualhosts, each virtualhost has it's own cgi directory and different apps runnin on them... but there seems to be a catch, each time the perl script call the warn function it prints to the main Apache error log file and not on virtualhost error log file, do you know why? or how can I can change the stdout? Is it something I need to configure in Apache? Any advise on this guys?

UPDATE: Let me give you the details, I'm running Apache 2.2.15 compiled with MPM Worker, and I'm using mod_cgid. Here is the virtualhost template that I'm using:
<VirtualHost 0.0.0.0:443> ServerName privatedomain.com:443 DocumentRoot "/opt/apache/secure-htdocs" DirectoryIndex index.phtml index.php index.html index.htm ErrorLog /opt/apache/logs/privatedomain.com_error_log TransferLog /opt/apache/logs/privatedomain.com_access_log #### SSL Settings SSLEngine On SSLProtocol All -SSLv2 -SSLv3 SSLCertificateFile /opt/apache/conf/ssl.crt/privatedomain.com.c +rt SSLCertificateKeyFile /opt/apache/conf/ssl.key/privatedomain.com.k +ey SSLCACertificatePath /opt/apache/conf/ssl.crt SSLCACertificateFile /opt/apache/conf/ssl.crt/ca-bundle.crt SSLCipherSuite !ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+E +XP:+eNULL SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 <FilesMatch "\.(cgi|pl|shtml|php|phtml|php3?)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/opt/apache/secure-htdocs"> Options All Order Allow,Deny Allow from All </Directory> ScriptAlias /cgi-bin/ /opt/apache/secure-cgi-bin/ <Directory "/opt/apache/secure-cgi-bin" > AllowOverride AuthConfig Limit Options Order Allow,Deny Allow from All </Directory> </VirtualHost>

Replies are listed 'Best First'.
Re: Apache Perl CGI and VirtualHosts
by Corion (Patriarch) on Mar 09, 2015 at 20:19 UTC

    The output of warn goes to STDERR, which is connected to the Apache web server error log. If you already have the error log file for the virtual host set up, it is likely misconfigured (but that's an Apache configuration issue and not a Perl issue :) ).

Re: Apache Perl CGI and VirtualHosts
by hippo (Archbishop) on Mar 09, 2015 at 22:17 UTC

    This is the behaviour we would expect to see with mod_cgid (ie. when using a threaded MPM) as opposed to mod_cgi. Which of these two Apache modules are you using?

      Hi,

      My apache is built using MPM Worker and I'm loading mod_cigd apparently.

      LoadModule cgid_module modules/mod_cgid.so

      Do you think this is related? Do you recommed to switch over mod_cgi and test again?

      --The Dev Ops Guy

        In that case what you are seeing is the expected behaviour. You could switch to a non-threaded MPM (ie. prefork) and use mod_cgi instead but then of course you would lose all the benefits of the threaded MPM. It is entirely your choice as the web server admin which way you choose to go with that.

        Either way, it's not a perl-specific issue.

Re: Apache Perl CGI and VirtualHosts
by locked_user sundialsvc4 (Abbot) on Mar 09, 2015 at 21:15 UTC

    It is most likely an issue with the ErrorLog and/or CustomLog directives within your Apache VirtualHost.   If you could please reply with a (sanitized) version of that virtual-host config, we can probably identify the problem immediately.

      Here is the VHost configuration that I'm using. The apache default error log is... well, error_log I'm actually using another error log and still not outputing to its own.
      <VirtualHost 0.0.0.0:443> ServerName privatedomain.com:443 DocumentRoot "/opt/apache/secure-htdocs" DirectoryIndex index.phtml index.php index.html index.htm ErrorLog /opt/apache/logs/privatedomain.com_error_log TransferLog /opt/apache/logs/privatedomain.com_access_log #### SSL Settings SSLEngine On SSLProtocol All -SSLv2 -SSLv3 SSLCertificateFile /opt/apache/conf/ssl.crt/privatedomain.com.c +rt SSLCertificateKeyFile /opt/apache/conf/ssl.key/privatedomain.com.k +ey SSLCACertificatePath /opt/apache/conf/ssl.crt SSLCACertificateFile /opt/apache/conf/ssl.crt/ca-bundle.crt SSLCipherSuite !ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+E +XP:+eNULL SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 <FilesMatch "\.(cgi|pl|shtml|php|phtml|php3?)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/opt/apache/secure-htdocs"> Options All Order Allow,Deny Allow from All </Directory> ScriptAlias /cgi-bin/ /opt/apache/secure-cgi-bin/ <Directory "/opt/apache/secure-cgi-bin" > AllowOverride AuthConfig Limit Options Order Allow,Deny Allow from All </Directory> </VirtualHost>
      --The Dev Ops Guy