FreeBSD CGI BIN Enabling mod perl On Apache24

Perl mod is a Perl programming language module that is inserted into the Apache24 web server. Perl mods can be used to manage the Apache24 web server, respond to web page requests, and more.

The perl mods installed on FreeBSD are more than just CGI scripts on steroids. Perl mods are a new way to create dynamic content by leveraging the full power of the Apache web server to make the web stateful. Customized user authentication system, more powerful proxy usage, and much more. However, miraculously, your old CGI script will continue to work and work very quickly. With the Perl mod you will get more benefits from the performance of the Perl mod that has been integrated into Apache24.

This article will explain how to enable perl mods on Apache24. In this article, the Perl and Apache24 mods will be installed simultaneously on the FreeBSD 13.2 system.


1. Apache24 Perl mod CGI Installation

To use the Perl mod feature, you must first install the Apache24 web server. The following is a guide on how to install Perl mods on Apache24.

oot@ns1:~ # cd /usr/ports/www/apache24
root@ns1:/usr/ports/www/apache24 #
make install clean

After apache24 has been successfully installed, you can continue by installing the perl mod.

root@ns1:~ # cd /usr/ports/www/mod_perl2
root@ns1:/usr/ports/www/mod_perl2 #
make install clean
root@ns1:~ #
cd /usr/ports/databases/p5-DBI
root@ns1:/usr/ports/databases/p5-DBI #
make install clean
root@ns1:~ #
cd /usr/ports/www/p5-Apache-DBI
root@ns1:/usr/ports/www/p5-Apache-DBI #
make install clean

Open the file /usr/local/etc/apache24/httpd.conf, activate ServerName by removing the "#" sign in front of the script.

#ServerName www.example.com:80

Change with

ServerName www.unixexplore.com:80


www.example.com is changed to the domain name on your FreeBSD server, in this case the domain name that I have set in the /etc/hosts file is unixexplore.com. If you have not specified a domain name in the /etc/hosts file, please create a domain name, pay attention to the following example of writing a domain name in the /etc/hosts file.

root@ns1:~ # ee /etc/hosts
::1 localhost localhost.unixexplore.com
127.0.0.1 localhost localhost.unixexplore.com
192.168.5.2 ns1 ns1.unixexplore.com
192.168.5.2 www.unixexplore.com


Still in the /usr/local/etc/apache24/httpd.conf file, after the script.

<Directory "/usr/local/www/apache24/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>

You add the following script below it.

<Location /cgi-bin/*.pl>
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
PerlSendHeader On
Options ExecCGI
Require all granted
</Location>
<Location /cgi-bin/*.cgi>
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
PerlSendHeader On
Options ExecCGI
Require all granted
</Location>

Now you open the file /usr/local/etc/apache24/modules.d/260_mod_perl.conf and activate the perl module by removing the "#" sign in the following script.

#LoadModule perl_module        libexec/apache24/mod_perl.so

Remove the sign "#" thus becoming

LoadModule perl_module        libexec/apache24/mod_perl.so


After Apache24 configuration is complete, enter the following script in the /etc/rc.conf file.

root@ns1:~ # ee /etc/rc.conf
apache24_enable="YES"

Restart the Apache24 web server.

root@ns1:~ # service apache24 restart


2. Test Apache24 Perl mod CGI

To test this Perl mod, we will create a test file called "test.cgi" which will be placed in the /usr/local/www/apache24/cgi-bin folder. Here's how to create the file.

root@ns1:~ # touch /usr/local/www/apache24/cgi-bin/test.cgi

Give permissions to the file /usr/local/www/apache24/cgi-bin/test.cgi.

root@ns1:~ # chmod 755 /usr/local/www/apache24/cgi-bin/test.cgi

Give ownership rights to the /usr/local/www/apache24/cgi-bin/test.cgi file or the /usr/local/www/apache24/ folder.

root@ns1:~ # chown -R www:www /usr/local/www/apache24/
root@ns1:~ #
chown -R www:www /usr/local/www/apache24/cgi-bin/test.cgi

Now you open the file /usr/local/www/apache24/cgi-bin/test.cgi and enter the script below, use the "ee" editor or "nano" editor to enter the following script.

root@ns1:~ # ee /usr/local/www/apache24/cgi-bin/test.cgi
#!/usr/local/bin/perl
print "Content-Type: text/html; charset=utf-8 \n\n";
print "<h1>Congratulations on successfully configuring the Perl mod on Apache24!</h1>";


Restart the Apache24 web server.

root@ns1:~ # service apache24 restart

After restarting, do a test by opening the Yandex browser or Google Chrome. Type the following command in the browser.

http://192.168.5.2/cgi-bin/test.cgi

Remember, IP 192.168.5.2 is the FreeBSD private server IP. If there are no incorrect configurations, the message will appear:

Congratulations on successfully configuring the Perl mod on Apache24!

Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post