Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

mod_perl, and weird caching

by ultranerds (Friar)
on Feb 04, 2014 at 15:27 UTC ( #1073419=perlquestion: print w/replies, xml ) Need Help??
ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Hopefully its ok to ask this question here, as I'm running out of ideas! First of all, I have 2 sites on my dedicated server - both I would like to run under mod_perl. The server is Apache2, is that helps.

Now - if I just have one site under mod_perl, all works fine. As soon as I add the 2nd one - I start seeing content from the other site "leaking" into the other site!

My configs are pretty much the same (just the path + userid + domain are changed):
<VirtualHost 123.123.123.123:80> ServerName domain.com ServerAlias www.domain.com DocumentRoot /home/fatpeter/public_html ServerAdmin webmaster@domain.com UseCanonicalName Off CustomLog /usr/local/apache/domlogs/domain.com combined CustomLog /usr/local/apache/domlogs/domain.com-bytes_log "%{%s}t % +I .\n%{%s}t %O ." ErrorLog /home/fatpeter/error_log ## User fatpeter # Needed for Cpanel::ApacheConf UserDir enabled fatpeter <IfModule mod_suphp.c> suPHP_UserGroup fatpeter fatpeter </IfModule> <IfModule !mod_disable_suexec.c> <IfModule !mod_ruid2.c> SuexecUserGroup fatpeter fatpeter </IfModule> </IfModule> <IfModule mod_ruid2.c> RUidGid fatpeter fatpeter </IfModule> ScriptAlias /cgi-bin/ /home/fatpeter/public_html/cgi-bin/ PerlRequire /home/fatpeter/startup.pl PerlModule Apache2::Reload PerlInitHandler Apache2::Reload PerlModule Apache2::RequestRec <Directory /home/fatpeter/public_html/cgi-bin> SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders PerlOptions +SetupEnv Options +ExecCGI </Directory> <Directory /home/fatpeter/public_html/cgi-bin/links/admin> SetHandler cgi-script </Directory> # We dont wanna run this in mod_perl! <Files suggest.cgi> SetHandler cgi-script </Files> <Files community.cgi> SetHandler cgi-script </Files> <Files nph-build-custom.cgi> SetHandler cgi-script </Files> <Files admin.cgi> SetHandler cgi-script </Files> </VirtualHost>


Now, as I said - that works fine with just one domain. As soon as I add the 2nd one, I start to see variables being passed along wrong (incorrect image URLs, etc)

The only thing I can think of - is that we use the same module names... ie

Domain 1: /cgi-bin/foo/admin/lib/Plugins/Utils.pm Domain 2: /cgi-bin/bar/admin/lib/Plugins/Utils.pm
Notice the folder names are different, but they would both translate as Plugins::Utils.

Now, the question is - how can I stop this "sharing" happening? The accounts are totally separate users, and shouldn't be sharing anything (if you try and change another accounts file, you get a permissions error.. which is totally how it should be)

Any suggestions? Its driving me up the wall only being able to run 1 site under mod_perl, without these undesired effects :/

TIA!

Replies are listed 'Best First'.
Re: mod_perl, and weird caching
by MidLifeXis (Monsignor) on Feb 04, 2014 at 16:17 UTC

    The first vhost that loads a module wins. You have (at least) two approaches:

    • disambiguate by using different module names per vhost (ick)
    • use a single (common) module and configure the differences using a per-vhost configuration object.

    --MidLifeXis

      Hi,

      Thanks for the reply!

      I had a feeling you were gonna say that :/ For the different module names... that doesn't sound like fun! Would it work by for example, changing:

      domain 1: lib/Foo/Bar.pm
      domain 2: lib/Foo2/Bar.pm

      use a single (common) module and configure the differences using a per-vhost configuration object.
      Could you explain this a bit more?

      Thanks!

      Andy

        Sure,

        You would make your module generic, so that it works with all of your vhosts. You would then configure the code based on some vhost specific setting. So for example, if you have a vhost-specific configuration file indicating the graphics file names for specific UI components, you could configure that file name in a per-vhost PerlVar.

        In your code, you could access this per-vhost setting. You could then use that setting to identify the location of the configuration file for that vhost, read the configuration, and respond.

        Basically, a persistent environment like mod_perl assumes that you are not changing the foundation that you are building the application upon. In order for that to hold true, you need to isolate the moving parts into something that you pass through the building infrastructure.

        --MidLifeXis

      For anyone interested, we managed to get it going by adding into pre_virtualhost_global.conf, for each VirtualHost
      PerlOptions +Parent PerlSwitches -Mlib=/home/domain.com/lib/perl
      According to the Cpanel tech guys, this means that it will run a perl instance separately per domain (which is what we need)

      We've got it setup on 2 sites now, and as far as I can see its working a charm (no inter-sharing files at all - which is great!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1073419]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-12-16 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many stories does it take before you've heard them all?







    Results (71 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!