Mojo App on Shared Webspace with CGI and Apache

36 views
Skip to first unread message

Michael Schmid

unread,
Dec 25, 2017, 4:26:40 AM12/25/17
to Mojolicious
Hi all

I know that this topic was several times mentioned bevor.

I have read all the information I could found about it.
But I can not solve my problem.

I would like to recode a cgi-app to mojolicious. But I have only a shared webspace
to do it. If I login into my shared webspace with ssh and I enter

mojo version


I can see the following information:

core
    perl v5
.24.3, freebsd
   
Mojolicious 7.58, Doughnut

Optional
    EV
4.0+ / 4.22
    IO::Socket::Socks 0.64+ /
n.a.
    IO
::Socket::SSL    1.94+    / 2.051
    Net::DNS::Native 0.15+    /
n/a
   
Role::Tiny 2.000001+    / 2.000006




Then I have read all the pages like
a.) http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#Apache-CGI
b.) https://github.com/kraih/mojo/wiki/Apache-deployment


and I put following into my .htaccess


AddHandler cgi-script .pl
Options +ExecCGI
IndexIgnore *

RewriteEngine on

RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI} -f
RewriteRule ^(.*) public/$1 [L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^(.*) script/premium_career_scout.pl [L]




On my shared webspace I have the projects in a www directory.
For this case it's in:
www/mojo/premium_career_scout

and the document-root for the project is also set on www/mojo/premium_career_scout


If I call https://mojo.premiumcareerscout.ch/
I get the correct page. I also checked if the css and js files are reachable...
everything seems to be ok!

But on the right upper side of the page I have three links
1.) /faq
2.) /contacts
3.) /jobsuchmaschinen

If I click on such a link, nothing happens. If I do the same on the developing computer
with morbo, everything is working.

Here is the content of PremiumCareerScout.pm


package PremiumCareerScout;
use Mojo::Base 'Mojolicious';

# This method will run once at server start
sub startup {
 
my $self = shift;

 
# Documentation browser under "/perldoc"
  $self
->plugin('PODRenderer');

 
# Router
 
my $r = $self->routes;

 
# Normal route to controller
  $r
->get('/')->to('Portal#main');
  $r
->get('/faq')->to('Portal#faq');
  $r
->get('/contacts')->to('Portal#contacts');
  $r
->get('/jobsuchmaschinen')->to('Portal#jobsuchmaschinen');
 
 
}

1;




What I'm doing wrong?
Can someone help my?

Thank you very much

Michael

Stefan Adams

unread,
Dec 25, 2017, 5:28:49 AM12/25/17
to mojolicious
On Mon, Dec 25, 2017 at 3:26 AM, Michael Schmid <schmm...@gmail.com> wrote:
If I call https://mojo.premiumcareerscout.ch/
I get the correct page. I also checked if the css and js files are reachable...
everything seems to be ok!

But on the right upper side of the page I have three links
1.) /faq
2.) /contacts
3.) /jobsuchmaschinen

If I click on such a link, nothing happens. If I do the same on the developing computer
with morbo, everything is working.

What is the code snippet from your templates to generate the three links and what is the generated code as seen by your browser? 

Michael Schmid

unread,
Dec 25, 2017, 5:50:41 AM12/25/17
to Mojolicious
Hi Stefan

The code-snippet for the 'portal'-page is
<!-- Dieses Template enthält das Layout für die Portal-Seite -->
<!DOCTYPE html>
<html lang="de">
<head>
   
<meta charset="utf-8">
   
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
   
<link rel="stylesheet" type="text/css" href="/css/custom.css">
   
<link rel="stylesheet" type="text/css" href="/css/stickyFooter.css">
   
<link rel="stylesheet" type="text/css" href="/css/jquery-ui.min.css">
   
<title><%= title %></title>
</head>
<body>

   
<div class="container">

       
<!-- Laden der Navigation oben -->
       
<%= include 'layouts/navbarV003' %>
       
       
<!-- Laden der linken Navigation -->
       
<%= include 'layouts/leftSideBarV003' %>
       
       
<!-- Center Column -->
       
<div class="col-sm-6">
       
           
           
<%== $content %>
           
           
           
       
</div>
       
       
<!-- Laden der rechten Navigation -->
       
<%= include 'layouts/rightSideBarV003' %>
 
   
</div>
   
</body>
</html>



The code-snippet for the template of the rightSideBarV003 is

Code h      <!-- Right Column -->
     
<div class="col-sm-3">

           
<!-- Form -->
           
           
<!-- List-Group Panel -->
           
<div class="panel panel-default">
               
<div class="panel-heading">
                   
<h1 class="panel-title"><span class="glyphicon glyphicon-question-sign"></span> Support</h1>
                </
div>
               
<div class="list-group">
                   
<a href="/faq" class="list-group-item">FAQ's</a>
                    <a href="/contacts" class="list-group-item">Kontakt</a>
    <!--                    <a href="#" class="list-group-item">Dynamically Innovate</a> -->
    <!--                    <a href="#" class="list-group-item">Objectively Innovate</a> -->
    <!--                <a href="#" class="list-group-item">Proactively Envisioned</a> -->
                </div>
            </div>
           
            <!-- List-Group Panel -->
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h1 class="panel-title"><span class="glyphicon glyphicon-triangle-right"></span> Artikel</h1>
                </div>
                <div class="list-group">
                    <a href="/jobsuchmaschinen" class="list-group-item">Jobsuchmaschinen</a>
    <!--                <a href="/cgi-bin/contacts" class="list-group-item">Kontakt</a> -->
    <!--                    <a href="#" class="list-group-item">Dynamically Innovate</a> -->
    <!--                    <a href="#" class="list-group-item">Objectively Innovate</a> -->
    <!--                <a href="#" class="list-group-item">Proactively Envisioned</a> -->
                </div>
            </div>


      </div><!--/Right Column -->
ier eingeben...

In the code above you can see the links /faq /contacts and a little bit below /jobsuchmaschinen.
All links are 'hard-coded' in html because they never change: <a href="/fq">FAQ</a> as example.


If I click on such a link, the url changes to mojo.premiumcareerscout.ch/faq, but the content of the page is the same.

The content is written in the library Portal in the subfunction faq or also the same in contacts:

sub contacts{
   
my $self = shift;
   
   
my $content = '
        <!-- Heading -->
        <div>
            <h1 class="page-header">Kontakt</h1>
        </div>
        <!-- /.row -->
       
        Bei Fragen jeglicher Art wenden Sie sich bitte per
        <a href="mailto:supportemail-address">E-Mail</a> an unseren Support<br>
           support-email-address.ch

       
        <br><br>Herzlichen Dank<br><br>
                   
                    Ihr sender
   
    '
;
   
    $self
->render( content => $content );
}

The code above is shorter then the version for the faq's that's why I published this code.

I hope I could answer your questions...


Regards

Michael





Michael Schmid

unread,
Dec 26, 2017, 4:11:22 PM12/26/17
to Mojolicious
I have found some more strange behaviour.

It doesn't matter which of the mentioned links I click, I see in the mojo-log all the time the same message...

Code hier eingeben...[Tue Dec 26 22:08:35 2017] [debug] GET "/"
[Tue Dec 26 22:08:35 2017] [debug] Routing to controller "PremiumCareerScout::Controller::Portal" and action "main"
[Tue Dec 26 22:08:35 2017] [debug] Rendering template "portal/main.html.ep"
[Tue Dec 26 22:08:35 2017] [debug] Rendering template "layouts/portal.html.ep"
[Tue Dec 26 22:08:35 2017] [debug] Rendering template "layouts/navbarV003.html.ep"
[Tue Dec 26 22:08:35 2017] [debug] Rendering template "layouts/leftSideBarV003.html.ep"
[Tue Dec 26 22:08:35 2017] [debug] Rendering template "layouts/rightSideBarV003.html.ep"
[Tue Dec 26 22:08:35 2017] [debug] 200 OK (0.023922s, 41.803/s)
[Tue Dec 26 22:08:39 2017] [debug] GET "/"
[Tue Dec 26 22:08:39 2017] [debug] Routing to controller "PremiumCareerScout::Controller::Portal" and action "main"
[Tue Dec 26 22:08:39 2017] [debug] Rendering template "portal/main.html.ep"
[Tue Dec 26 22:08:39 2017] [debug] Rendering template "layouts/portal.html.ep"
[Tue Dec 26 22:08:39 2017] [debug] Rendering template "layouts/navbarV003.html.ep"
[Tue Dec 26 22:08:39 2017] [debug] Rendering template "layouts/leftSideBarV003.html.ep"
[Tue Dec 26 22:08:39 2017] [debug] Rendering template "layouts/rightSideBarV003.html.ep"
[Tue Dec 26 22:08:39 2017] [debug] 200 OK (0.019665s, 50.852/s)
[Tue Dec 26 22:08:42 2017] [debug] GET "/"
[Tue Dec 26 22:08:42 2017] [debug] Routing to controller "PremiumCareerScout::Controller::Portal" and action "main"
[Tue Dec 26 22:08:42 2017] [debug] Rendering template "portal/main.html.ep"
[Tue Dec 26 22:08:42 2017] [debug] Rendering template "layouts/portal.html.ep"
[Tue Dec 26 22:08:42 2017] [debug] Rendering template "layouts/navbarV003.html.ep"
[Tue Dec 26 22:08:42 2017] [debug] Rendering template "layouts/leftSideBarV003.html.ep"
[Tue Dec 26 22:08:42 2017] [debug] Rendering template "layouts/rightSideBarV003.html.ep"
[Tue Dec 26 22:08:42 2017] [debug] 200 OK (0.020633s, 48.466/s)
[Tue Dec 26 22:08:44 2017] [debug] GET "/"
[Tue Dec 26 22:08:44 2017] [debug] Routing to controller "PremiumCareerScout::Controller::Portal" and action "main"
[Tue Dec 26 22:08:44 2017] [debug] Rendering template "portal/main.html.ep"
[Tue Dec 26 22:08:44 2017] [debug] Rendering template "layouts/portal.html.ep"
[Tue Dec 26 22:08:44 2017] [debug] Rendering template "layouts/navbarV003.html.ep"
[Tue Dec 26 22:08:44 2017] [debug] Rendering template "layouts/leftSideBarV003.html.ep"
[Tue Dec 26 22:08:44 2017] [debug] Rendering template "layouts/rightSideBarV003.html.ep"
[Tue Dec 26 22:08:44 2017] [debug] 200 OK (0.024079s, 41.530/s)

I clicked different links like /faq, /contacts etc. It doesn't look like mojo get the correct routing info..

regards
Michael


Stefan Adams

unread,
Dec 27, 2017, 4:02:07 AM12/27/17
to mojolicious
If a fetch of /faq yields a log entry of GET "/" then it seems to me like Apache isn't passing the environment variables.  I don't remember much about Apache any more, been using Mojolicious as my web servers for close to five years!  :D

Can you modify your Mojo app code to inspect your environment.  Perhaps use a hook?  Maybe in before_dispatch

$c->app->log->info("Env $_: $ENV{$_}") foreach keys %ENV;

You'll need to see PATH_INFO there.  If you do, perhaps let's troubleshoot your app further; if you don't, focus on Apache maybe?

I don't recall ever running a Mojo app as CGI from Apache, but as you said according to the Cookbook, it looks like a piece of cake.

Amazing how simple!

$ env PATH_INFO=/ mojo 
Content-Length: 21
Content-Type: text/html;charset=UTF-8
Status: 200 OK
Date: Wed, 27 Dec 2017 08:33:12 GMT

Your Mojo is working!

But without that environment, Mojolicious doesn't detect that it's CGI and runs

$ env mojo 
Usage: APPLICATION COMMAND [OPTIONS]

  mojo version
  mojo generate lite_app
  ./myapp.pl daemon -m production -l http://*:8080
  ./myapp.pl get /foo
  ./myapp.pl routes -v

Tip: CGI and PSGI environments can be automatically detected very often and
     work without commands.

Options (for all commands):
  -h, --help          Get more information on a specific command
      --home <path>   Path to home directory of your application, defaults to
                      the value of MOJO_HOME or auto-detection
  -m, --mode <name>   Operating mode for your application, defaults to the
                      value of MOJO_MODE/PLACK_ENV or "development"

Commands:
 cgi       Start application with CGI
 cpanify   Upload distribution to CPAN
 daemon    Start application with HTTP and WebSocket server
 eval      Run code against application
 generate  Generate files and directories from templates
 get       Perform HTTP request
 inflate   Inflate embedded files to real files
 prefork   Start application with pre-forking HTTP and WebSocket server
 psgi      Start application with PSGI
 replget   Perform HTTP requests in a REPL
 routes    Show available routes
 sendgrid  Sendgrid API
 test      Run tests
 version   Show versions of available modules

See 'APPLICATION help COMMAND' for more information on a specific command.

You can force it

$ env mojo cgi
Status: 200 OK
Content-Length: 21
Content-Type: text/html;charset=UTF-8
Date: Wed, 27 Dec 2017 08:47:54 GMT

Your Mojo is working!

Maybe you should.  Just thinking out loud, but either edit your script and change it from start_app('PremiumCareerScout') to start_app('PremiumCareerScout', 'cgi') or perhaps you can modify script/premium_career_scout.pl to be script/premium_career_scout.pl cgi tho that really seems like a bad idea because Mojolicious can detect CGI and clearly it isn't because likely PATH_INFO isn't defined.

Let's see where any of that gets you...  I'll admit I don't really know, but hoping that helps!

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscribe@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Michael Schmid

unread,
Dec 27, 2017, 6:10:26 AM12/27/17
to Mojolicious
Hi Stefan

Thank you very much for your proposals.

Code hier eingeben...$self->hook( before_dispatch => sub {
       my $self = shift;
       #$self->req->url->base(Mojo::URL->new(q{http://mojo.premiumcareerscout.ch/}));
  });

 Since I set the comment sign in front of $self->req-url->base.... it's everything running.
I got the idea to re-check it because your sentence about the path_info

Thank you very much...

Regards

Michael
Reply all
Reply to author
Forward
0 new messages