# Perl enable on Apache24



## lucas1 (Sep 23, 2021)

Good afternoon. 
Need to enable support Perl  on Apache24 with virtual hosts.
mod_perl.so installed, in httpd.conf added.

```
LoadModule perl_module libexec/apache22/mod_perl.so
```
But then it is not clear which directives or options to include, taking into account virtual hosts, so that, for example, the test file
index.pl executed apache24 and displayed correctly in browser.


----------



## SirDice (Sep 23, 2021)

lucas1 said:


> Need to enable support Perl on Apache24 with virtual hosts.
> mod_perl.so installed, in httpd.conf added.


Take a really close look at the line you added. It points to apache22, that's not correct, that should be apache24.


----------



## lucas1 (Sep 23, 2021)

I accidentally made a mistake in the message text.
Certainly,
LoadModule perl_module libexec/apache*24*/mod_perl.so

Still, how enabled support Perl  on Apache24.


----------



## _martin (Sep 23, 2021)

lucas1 Have you checked this out? Assuming you have the perl module installed (ap24-mod_perl2), module enabled as you mentioned you do need to enable CGI and add the handler. Execution of the perl script is done differently to php.
Edit: it's worth sharing the link mod_perl package ships with itself: start fast


----------



## lucas1 (Sep 23, 2021)

Did so far:









						Apache: включить поддержку Perl
					

Задача - добавить к Apache возможность обработки сценариев на Perl. Система: # uname -v FreeBSD 9.1-STABLE Процесс установки и настройки описан в статье FreeBSD: Apache+MySQL+PHP (LAMP) + phpMyAdmin. Конфигурация Apache стандартная: # httpd -l Compiled in modules: core.c prefork.c http_core.c...



					rtfm.co.ua
				



I also found the method you specified,, but generally, apache24 goes into an error when executing .pl and this 
displays in browser a message about something like "misconfigured server".


And yes. *+ExecCG*I it is necessary in a separate line.


----------



## _martin (Sep 23, 2021)

I pulled the vanilla VM image, installed apache24 and ap24-mod_perl2. Changes I did:

```
root@freebsd13:/usr/local/etc/apache24 # diff -w httpd.conf httpd.conf.sample
166c166
<       LoadModule cgid_module libexec/apache24/mod_cgid.so
---
>       #LoadModule cgid_module libexec/apache24/mod_cgid.so
169c169
<       LoadModule cgi_module libexec/apache24/mod_cgi.so
---
>       #LoadModule cgi_module libexec/apache24/mod_cgi.so
262a263,264
>     #
>     Options Indexes FollowSymLinks
264,268d265
<       SetHandler perl-script
<       PerlResponseHandler ModPerl::Registry
<       PerlOptions +ParseHeaders
<       Options Indexes FollowSymLinks ExecCGI
<
434c431
<     AddHandler cgi-script .cgi .pl
---
>     #AddHandler cgi-script .cgi
root@freebsd13:/usr/local/etc/apache24 #
```
I uncommented the loadmodule in /usr/local/etc/apache24/modules.d/260_mod_perl.conf. 
I created a test /usr/local/www/apache24/data/test.pl:

```
#/usr/bin/env perl

print "Content-type: text/html\n\n";
print "<h2>this is a test</h2>\n";
print "$^O\n";
```
And it was working.


----------



## SirDice (Sep 23, 2021)

_martin said:


> ```
> #/usr/bin/env perl
> ```


Typo? That should be `#!/usr/bin/env perl`


----------



## _martin (Sep 23, 2021)

Hm, interesting. Typo in the script, not in my post. It seems the module that handles the perl is calling the perl interpreter. So the whole shebang line can be omitted. I guess perl module sees the whole line as comment as it starts with #.


----------



## SirDice (Sep 23, 2021)

Yeah, it will always invoke the perl handler because of the `SetHandler perl-script`. So the shebang isn't really needed, but it's good form to keep it.


----------

