WebFaction
Community site: login faq

I'm trying to set up Open Melody, and set up its required and optional dependencies. I'm not a perl guy, though.

I saw http://community.webfaction.com/questions/3308/how-to-install-htmlparser-perl-module but I'm having a different error.

I set up CPAN according to http://docs.webfaction.com/software/perl.html and installed all the modules; I even verified they really work, with 'perl -d' followed by 'use HTML::Parser;' and it works. It finds the stuff in my ~/lib/perl5 directory.

But, when I run the Melody check.cgi, these additions to the PERL5LIB that were put in my ~/.bashrc don't show up. I have this set up in a "Static/CGI/PHP-5.3" application, and I figure I must just be setting something basic up wrong. I even tried a .htaccess with "SetEnv <paths>", but no luck.

The only search/include paths that seem to register in the CGI script are the default ones.

asked 07 May '11, 14:36

mnemnosi
111
accept rate: 0%


The problem is that we serve CGI scripts via suexec, and suexec discards environment variables.

As a workaround, you can set your environment variables in a wrapper script, and then rewrite all of your .cgi URLs through that script via .htaccess.

Your wrapper script should look something like this...

#!/bin/sh

export PERL5LIB="${PERL5LIB}:/home/username/lib/perl5:/home/username/perl5/lib:/home/username/perl5/lib/i386-linux-thread-multi/"
exec /home/username/webapps/appname$SCRIPT_URL

Change 'username' and 'appname' to your username and the name of your app respectively, save the wrapper script in your app directory, and set the permissions on the wrapper script to 711.

Your .htaccess should look something like this...

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !wrapper.cgi
RewriteRule ^(.*)\.cgi /wrapper.cgi

Change 'wrapper.cgi' to whatever you named your wrapper script. If you saved the wrapper script to somewhere other than the root of your app directory, then adjust accordingly.

Once that's done, requests for your cgi scripts will be rewritten to executed via the wrapper script. The wrapper script sets the environment variables after suexec has already sanitized the environment, so they'll be present for your scripts.

Hope that helps!

permanent link

answered 07 May '11, 18:33

seanf
12.2k42136
accept rate: 37%

This didn't work for me; I got basic errors in the Apache logs saying "Premature end of script headers: wrapper.cgi". After changing username, appname, and tweaking the paths (...username/perl5 -> username/lib/perl5 and such). Tried various things, chmod +x and the like. Setting SCRIPT_URL and running my wrapper.cgi from the command line worked fine.

It sorta makes me wonder if the best way to run a perl webapp would be a local install of Apache with mod_perl or.. whatever one does to un-CGI complex perl apps. It seems this is all way more complicated to make simple perl scripts work then is usual for webfaction -- so I'm probably just going to go look for a non-perl based alternative to what I need to do.

Thanks for the advice. But I don't run into any of these problems with Python-based solutions so I'll go find an alternative there I think. :)

permanent link

answered 08 May '11, 04:43

mnemnosi
111
accept rate: 0%

use lib '/home/[username]/lib/perl5';
use lib '/home/[username]/lib/perl5/lib64/perl5';
use lib '/home/[username]/lib/perl5/lib';
use lib '/home/[username]/lib/perl5/lib/i386-linux-thread-multi/';
use lib '/home/[username]/lib/perl5/share/perl5';

when I add 2nd and 5th line to my code, my perl modules run perfectly.

permanent link
This answer is marked "community wiki".

answered 29 Jan '15, 04:53

Atul Gupta
113
accept rate: 0%

edited 29 Jan '15, 05:05

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×20
×6

question asked: 07 May '11, 14:36

question was seen: 4,182 times

last updated: 29 Jan '15, 05:06

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM