Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Dancer newbie question

by erickp (Sexton)
on Feb 22, 2024 at 13:29 UTC ( [id://11157839]=perlquestion: print w/replies, xml ) Need Help??

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

Hi guys,

I'm relatively new to Perl and I'm trying to run a Perl Dancer2 app on my shared hosting (CPanel) environment.

I tried the little snippet found on metacpan here :

https://metacpan.org/dist/Dancer2/view/lib/Dancer2/Tutorial.pod

and it works fine when I curl localhost on port 3000.

The problem is when I try to execute it from outside, like a normal user would see it at the normal domain URL. It doesn't work.

I believe this may be a simple matter of a mod_proxy type config in my .htaccess file but I can't figure out how to do this. I do not have access to httpd.conf from Apache as this is a shared host.

Any ideas on viewing that app from outside?

Thanks.

Replies are listed 'Best First'.
Re: Dancer newbie question
by hippo (Bishop) on Feb 22, 2024 at 13:50 UTC
    I do not have access to httpd.conf from Apache as this is a shared host.

    Talk to your hosting provider. They should be able to tell you which of the many possible proxy modules are available to you and how to set up (basic) proxy configuration to get you started.


    🦛

Re: Dancer newbie question
by marto (Cardinal) on Feb 22, 2024 at 13:41 UTC
Re: Dancer newbie question
by erickp (Sexton) on Feb 22, 2024 at 14:26 UTC
    Trying to get support from the hosting provider. They can't modify the httpd.conf because I'm on a shared host. And I tried the other solutions in .htaccess and I can't seem to get that working...crossing my fingers.

      To explain some more details about the Dancer documentation for Apache, where they say

      As a CGI Script
      ...
      AddHandler cgi-script .cgi
      ...

      They are suggesting that each incoming request would launch a new one-shot call to perl running your Dancer app to serve a single request. This is slow and nobody wants to do it like this.

      Where the documentation says

      As a FastCGI Script
      ...
      You will still need to enable mod_rewrite, but will need to use a FastCGI module instead of a CGI module. There are 3 available: mod_fcgid, mod_fastcgi and mod_proxy_fcgi. For this example, we will use mod_fastcgi (a2enmod fastcgi in Debian).
      ...
      FastCgiServer /srv/www.example.com/public/dispatch.fcgi
      ...
      AddHandler fastcgi-script .fcgi

      they are saying that your apache hosting provider needs to have one of those three fastcgi modules installed (you'll have to ask them if any are available). That module will see your .htaccess file and load a long-running copy of your application, consuming server resources based on how many workers you configure. This is what you want, but may not be something your hosting provider wants.

      Checking with ChatGPT,

      No, the FastCgiServer directive is not typically allowed in an .htaccess file.
      which agrees with the general lack of google results for that example.

      I will second the opinion of others that shared hosting providers are not something you want to use for perl web apps. The shared-hosting-behind-apache model was popular 20 years ago, but it has numerous problems and everyone generally hated it, and we've all moved on (except PHP folks, for whom it still kind of works)

      There's a bigger learning curve, but I recommend getting comfortable with managing your own virtual machine on a cloud platform like Linode or Digital Ocean. Their small instances are $5/mo and are plenty for running a perl web app with small userbase. Having your own VM puts you in full control of apache, or you could ditch apache and use nginx, or Traefik. Traefik gives you free SSL certs and is a fairly nice experience compared to apache; it doesn't serve static files though.

      If you've never managed your own host before and want to skip the learning curve, DigitalOcean also has the App service which deploys one of your GitHub repos directly into a VM for you, so all you have to do is push changes to your GitHub repo and poof, they're available with SSL served from a VM. Here's a blog article I found that sums it up.

      I'm on a shared host.

      That usually limits you to CGI, with a lot of luck you can use FastCGI.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Dancer newbie question
by InfiniteSilence (Curate) on Feb 24, 2024 at 00:18 UTC

    Switch off of a shared host. There are really cheap alternatives where you can get a VPS for like $3/mo (example, racknerd.com).

    Celebrate Intellectual Diversity

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-20 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found