A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Test Kerberos authentication

vi /etc/krb5.conf
/opt/mitk5/bin/kinit [username]

Password protect a directory in Apache

Put a .htaccess file in the directory you want to protect, containing:

AuthUserFile /full/path/to/your/htpasswd_file
AuthGroupFile /dev/null
AuthName "Password Protected Area"
AuthType Basic



require valid-user


Then use an online htpasswd generator to create the htpasswd_file at the location you specified for AuthUserFile above. Make sure this is outside your public webspace.

Log and email your Apache errors

In the .htaccess at the root of the site:
ErrorDocument 404 http://www.example.com/error_page.php?err=404
ErrorDocument 503 http://www.example.com/error_page.php?err=503
etc.

In error_page.php:


$myemail = "someone@example.com";
$subject = "example.com: $errorNum error";
$message = "$errorNum Error Report:\n";
$message .= "\nHTTP_REFERRER: ".$_SERVER['HTTP_REFERER'];
$message .= "\nREQUEST_URI: ".$_SERVER['REQUEST_URI'];
$message .= "\nHTTP_USER_AGENT: ".$_SERVER['HTTP_USER_AGENT'];
$message .= "\nQUERY_STRING: ".$_SERVER['QUERY_STRING'];
$message .= "\nREMOTE_ADDRESS: ".$_SERVER['REMOTE_ADDR'];


ob_start();
print "\n\nSERVER = "; print_r( $_SERVER );
print "\nGET = "; print_r( $_GET );
print "\nPOST = "; print_r( $_POST );
print "\nFILES = "; print_r( $_FILES );
print "\nREQUEST = "; print_r( $_REQUEST );
print "\nSESSION = "; print_r( $_SESSION );
print "\nENV = "; print_r( $_ENV );
print "\nCOOKIE = "; print_r( $_COOKIE );
print "\nprevious php_errormsg = "; print_r( $php_errormsg );
print "\nargv = "; print_r( $argv );
$output = ob_get_clean();
$message .= "\n\n$output\n";


# email the error
mail($myemail,$subject,$message,"From: support@example.com");


# log the error
$myFile = "logs/error.".date('Y_m_d-H.i.s').".log";
$fh = fopen($myFile, 'w');
$stringData = $message;
fwrite($fh, $stringData);
fclose($fh);
?>

Using Apache::Registry

When a script uses a config file that is a perl package, and that package gets changed, it must be reloaded. This can happen either through Apache::StatINC, or Apache::Reload. With both methods you must wait for about a second for perl to 'let go' of the config packages before performing any actions on those files. Otherwise all sort of intermittent weirdness will occur, (e.g. when running the script multiple times in a test and changing the config files inbetween).

Using StatINC_UndefOnReload On can cause all manner of strange errors if you run a script/module, then do :w on the module in vim but don't change anything, then run the script/module again.

Using PerlFreshRestart On causes lots of "Attempt to free unreferenced scalar" errors

Also, when changing the contents of perl configuration 'packages', the modification date on the file must be changed for any Apache module to reload it. Remember that move doesn't change the modification date of files, but copy does. So copy and unlink files, don't move them.


Cocoon documentation

Current:
  • Wiki: http://wiki.apache.org/cocoon/FrontPage (question about docs. Answer: Understand How ASF works)
  • Official v2 site: http://cocoon.apache.org/
  • Jira bug tracking: https://issues.apache.org/jira/browse/COCOON (issue about docs - there are several more issues regarding out-of-date contribution procedures)
  • Cocoon 3 alpha: http://people.apache.org/~reinhard/c3-ref/html/
  • List of mailing lists: http://svn.apache.org/repos/asf/cocoon/site/site/mail-lists.html (also a browsable SVN repository of the documentation website - will updating this fix the live site?)
  • Main site mailing lists: http://cocoon.apache.org/2.1/1175.html
  • Searchable mailing list archives: http://markmail.org/search/?q=list%3Aorg.apache.cocoon.users
    • and http://markmail.org/search/?q=list%3Aorg.apache.cocoon.dev

Dead or out-of-date:
  • org.apache.cocoon.docs - is this dead?
  • This link to Cocoon Bugzilla is dead (it should be Jira now anyway): http://cocoon.apache.org/2.0/howto/howto-bugzilla.html
  • Many of the links on this menu are dead: http://cocoon.apache.org/2.0/
  • The "View, Edit or comment" link at the bottom of this page is dead: http://cocoon.apache.org/

Criticism:

    Nginx high-performance webserver

    Nginx is a high-performance HTTP server. http://wiki.nginx.org/Main

    Seems to be used by quite a lot of sites and a few people have noticed nginx 404 error pages by facebook and youtube indicating they may also be using it? http://wiki.nginx.org/NginxWhyUseIt

    Comes also with a memcached module to talk with memcached directly: http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/

    And has embedded perl in it as standard: http://wiki.nginx.org/NginxEmbeddedPerlModule

    And call perl directly from SSI
    <!- # perl sub="module::function" arg="parameter1" arg="parameter2"... >

    For XSLT fans: http://wiki.nginx.org/NginxHttpXsltModule

    Start Apache with a custom configuration

    /path/to/main/httpd -f /path/to/your/custom/httpd.conf -k start

    Using a custom Apache config

    apachectl -f ~/httpd/conf/httpd.conf -k graceful

    tail -f ~/httpd/logs/error_log

    Apache::Registry / Perl config files

    • Apache::Reload causes more problems than it fixes
    • Apache::StatINC only works on the @INC path which is set by Apache before scripts are run
    • Apache::Registry - just don't bother
    • Don't use Apache's PerlFreshRestart On, it will break things
    • If parsing Perl syntax config files from Apache, remember it takes a few seconds for Perl to 'let go' after making changes.

    Read an internal Apache variable

    ...such as %{MY_MOD_OUTPUT_NOTE}n -- that would be available for logging, but not visible by mod_include.

    RewriteEngine On
    RewriteRule ^(.*)$ $1 [E=MY_MOD_ENV_VAR:%{ENV:MY_MOD_OUTPUT_NOTE}]

    Apache: make file download instead of appear in browser

    (Untested)

    ## FORCE FILE TO DOWNLOAD INSTEAD OF APPEAR IN BROWSER ###
    -> http://www.htaccesselite.com/addtype-addhandler-action-vf6.html
    AddType application/octet-stream .mov .mp3 .zip

    Apache error "premature EOF in parsed file"

    When Apache 1.3 says "premature EOF in parsed file".
    What it means is "You've messed up the attribute syntax in a mod_include command".

    Examples:

    <!--#config timefmt=%s --> (no quotes)

    <!--#set var='title' value='This title would've screwed things up' --> (apostrophe not escaped)

    Where you might find Apache files

    • /usr/sbin/apachectl
    • /usr/sbin/httpd
    • /etc/httpd/conf/httpd.conf
    • /var/log/httpd/error_log
    • /etc/httpd/
    • /etc/httpd/modules/

    Template Toolkit troubleshooting

    If a module upon which your code is dependent does not compile, then Template Toolkit 2 under mod_perl 1.3 can give two misleading error messages:
    1. can't locate that module in the @INC path, although it is really there
    2. plugin error - load() returned a false value
    The solution to both error messages is to syntax check all the dependent modules.

    Reloading mod_perl modules automatically when they change

    Beware of using Apache::StatINC or Apache::Reload, especially is the module in question is a module acting as a configuration file. A severe shortage of fun can occur.

    c logging

    if your fprintf statements don't reach the apache error log, you may have to flush the output buffer:

    fprintf(stderr, "error statement\n");
    fflush(stderr);


    Logging in an apache handler

    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "debug message");