0

I am trying to make a Perl script with arguments that can be executable via a web page. Can someone help me with getting started with the apache and the configurations for that? I've tried for multiple hours but nothing seems to work. I'm using Apache 2.4.29

zAndrewi
  • 9
  • 1
  • 4
  • What steps did you try in the multiple hours? – choroba Mar 21 '21 at 20:36
  • Maybe this question helps https://stackoverflow.com/q/8994348/1741542 – Olaf Dietsche Mar 21 '21 at 20:37
  • So I am trying to make it so it go to "localhost/cgi-bin/first.pl" but I keep getting apache errors and right now it tells me 403 Forbidden – zAndrewi Mar 21 '21 at 20:38
  • Searching for [apache cgi 403](https://stackoverflow.com/search?q=apache+cgi+403) gives https://stackoverflow.com/q/32416046/1741542 – Olaf Dietsche Mar 21 '21 at 20:40
  • To narrow the reason for the 403 error, look into Apache's log files: /var/log/apache2/access.log and /var/log/apache2/error.log. – Olaf Dietsche Mar 21 '21 at 20:43
  • I have solved it, and now I get a 500 internal error – zAndrewi Mar 21 '21 at 20:46
  • https://stackoverflow.com/questions/560749/how-do-i-configure-apache-2-to-run-perl-cgi-scripts – brian d foy Mar 21 '21 at 20:46
  • Any idea how I could pass an argument into the web page? like "localhost/cgi-bin/first.pl?arg1=arg1"? – zAndrewi Mar 21 '21 at 21:26
  • The args are already passed into a CGI script as an environment variable `QUERY_STRING`. For Perl, I suggest https://metacpan.org/pod/CGI, see e.g. https://stackoverflow.com/q/2238015/1741542 – Olaf Dietsche Mar 21 '21 at 21:36
  • Can you give me a more detailed tutorial, I'm new to perl and I don't really understand it, do you have like a youtube viode? – zAndrewi Mar 21 '21 at 21:55
  • @zAndrewi Do some web searching. There have been such tutorials on the web for well over 20 years. – stevieb Mar 21 '21 at 22:01
  • If you get a 500 internal error you should have more info about the error in apaches error log. Try to work from there or give us the info here and we might be able to help. – MrApnea Mar 22 '21 at 08:07
  • As you have an answer to your question, you should close this question and ask your new question separately. – Dave Cross Mar 22 '21 at 08:23
  • Go to youtube.com, input Perl CGI, *et voila* right at the top, there's everything you asked for. :-) – Olaf Dietsche Mar 22 '21 at 09:53

1 Answers1

1

An option to solve this still using perl is creating a small TCP service running in localhost in the server where you can send your parameters, and then you just configure a reverse proxy in apache to that port.

Example:

use strict;
use warnings;
use IO::Socket;  
  
my $port = 9999;  

my $server_socket = IO::Socket::INET->new(
     LocalPort => $port,
     Listen    => SOMAXCONN,
     Proto     => 'tcp',
     Reuse     => 1)
     or die "Cannot open socket: $!";
         

print "Server listening on port $port\n";  
  
while ( my $client_socket = $server_socket->accept() ) {
    my $client_host = $client_socket->sockhost();
    run_your_stuff();
    $client_socket->close();
}

   
sub run_your_stuff{
    print "Executing something...\n";
    system("ping google.es");
    # system("perl your_oder_script.pl");
}

nck
  • 1,673
  • 16
  • 40