Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Linux terminal |
Category | Web Server |
OS compatibility | AlmaLinux • CentOS • Fedora • RHEL • Rocky • Stream |
Est. reading time | 3 minutes |
Installing Perl in Fedora Linux using the dnf command
- Log into the remote server using the terminal application provided by your operating system.
- First, patch the Fedora Linux server by running the following:
# dnf update
Outputs:Last metadata expiration check: 2:44:04 ago on Sun Oct 22 12:18:11 2023. Dependencies resolved. =================================================================================== Package Architecture Version Repository Size =================================================================================== Upgrading: iptables-libs x86_64 1.8.9-4.fc38.1 updates 414 k librepo x86_64 1.17.0-1.fc38 updates 96 k Transaction Summary =================================================================================== Upgrade 2 Packages Total download size: 510 k Is this ok [y/N]: y Downloading Packages: (1/2): librepo-1.17.0-1.fc38.x86_64.rpm 1.5 MB/s | 96 kB 00:00 (2/2): iptables-libs-1.8.9-4.fc38.1.x86_64.rpm 3.6 MB/s | 414 kB 00:00 ----------------------------------------------------------------------------------- Total 2.4 MB/s | 510 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Upgrading : librepo-1.17.0-1.fc38.x86_64 1/4 Upgrading : iptables-libs-1.8.9-4.fc38.1.x86_64 2/4 Cleanup : librepo-1.16.0-2.fc38.x86_64 3/4 Cleanup : iptables-libs-1.8.9-4.fc38.x86_64 4/4 Running scriptlet: iptables-libs-1.8.9-4.fc38.x86_64 4/4 Verifying : iptables-libs-1.8.9-4.fc38.1.x86_64 1/4 Verifying : iptables-libs-1.8.9-4.fc38.x86_64 2/4 Verifying : librepo-1.17.0-1.fc38.x86_64 3/4 Verifying : librepo-1.16.0-2.fc38.x86_64 4/4 Upgraded: iptables-libs-1.8.9-4.fc38.1.x86_64 librepo-1.17.0-1.fc38.x86_64 Complete!
- Now the server is patched, and up to date with all apps, it is time to search for Perl packages and modules offered by Fedora Linux. Run:
# dnf list perl
Last metadata expiration check: 2:39:16 ago on Sun Oct 22 12:18:11 2023. Available Packages perl.x86_64 4:5.36.1-497.fc38 updates
Here is how to search for all packages:
# dnf search perl
# Regex search to narrow down results #
# dnf search 'perl-*' | more
# regex but with "grep" or "egrep" #
# dnf search perl | grep -Ei 'Ajax|AWS'
Here is output from the last command:Last metadata expiration check: 2:48:49 ago on Sun Oct 22 12:18:11 2023. claws-mail-plugins-perl.x86_64 : Perl based extended filtering engine for Claws Mail perl-CGI-Ajax.noarch : Perl-specific system for writing Asynchronous web applications perl-AWS-Signature4.noarch : Create a version4 signature for Amazon Web Services
- I wanted to see which Perl version Fedora was about to install, so I typed:
# dnf info perl
Look like I’m getting the Perl version 5.36.1:Last metadata expiration check: 2:40:11 ago on Sun Oct 22 12:18:11 2023. Available Packages Name : perl Epoch : 4 Version : 5.36.1 Release : 497.fc38 Architecture : x86_64 Size : 14 k Source : perl-5.36.1-497.fc38.src.rpm Repository : updates Summary : Practical Extraction and Report Language URL : https://www.perl.org/ License : GPL+ or Artistic Description : Perl is a high-level programming language with roots in C, sed, awk : and shell scripting. Perl is good at handling processes and files, : and is especially good at handling text. Perl's hallmarks are : practicality and efficiency. While it is used to do a lot of : different things, Perl's most common applications are system : administration utilities and web programming. : : This is a metapackage with all the Perl bits and core modules that : can be found in the upstream tarball from perl.org. : : If you need only a specific feature, you can install a specific : package instead. E.g. to handle Perl scripts with /usr/bin/perl : interpreter, install perl-interpreter package. See perl-interpreter : description for more details on the Perl decomposition into : packages.
- Okay, let us install the Perl. Type:
# dnf install perl
- To find out the version of Perl installed just now, simply type “perl -v” on the command line. For example:
# perl -v
Here is what my Fedora cloud Linux server displayed back:This is perl 5, version 36, subversion 1 (v5.36.1) built for x86_64-linux-thread-multi Copyright 1987-2023, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at https://www.perl.org/, the Perl Home Page.
- The next step is to install an embedded Perl interpreter for the Apache web server as follows:
# dnf install httpd mod_perl
- Edit the /etc/httpd/conf.d/perl.conf
# vim /etc/httpd/conf.d/perl.conf
Ensure that the following config exists:# Enable registry scripts for mod_perl # Alias /perl /var/www/perl <Directory /var/www/perl> SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI </Directory>
Create a new directory using the mkdir command and change directory using the cd command:
# mkdir -v /var/www/perl
# cd /var/www/perl
Create the following hello.pl script for testing purpose:
# vim hello.pl
Append the following code:#!/usr/bin/perl print "Content-type: text/plain\n\n"; print "This is a mod_perl 2.0 setup test by nixCraft.com\n";
Finally, set executable bit on the script:
# chmod +x -v hello.pl
Test it using the browser or the CLI. For example:https://your-domain-com/perl/hello.pl
OR from the server itself:
{vivek@desktop~:}$ curl https://127.0.0.1/perl/hello.pl
-
Finally, I’m going to test and config mod_perl handlers. Here is how to test a response handler similar to the registry script. Create a new directory inside /var/www/perl called app1/
# mkdir /var/www/perl/app1/
Create a new file named /var/www/perl/app1/test.pm and add the following code:#file:app1/test.pm #---------------------- package app1::test; use strict; use warnings; use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK); sub handler { my $r = shift; $r->content_type('text/plain'); print "nixcraft.com mod_perl /app/ handler test!\n"; return Apache2::Const::OK; } 1;
Create a new script /var/www/perl/startup.pl and set @INC path for your app. For example:
use lib qw(/var/www/perl); 1;
Edit the /etc/httpd/conf.d/perl.conf and update as follows (append at the end):
Restart the Apache (HTTPD) server using the systemctl command:PerlRequire /var/www/perl/startup.pl <Location /app> SetHandler perl-script PerlResponseHandler app1::test </Location>
# systemctl restart httpd
Test it:{vivek@desktop~:}$ curl -I http://localhost/app/ ##OR type in your browser## http://your-domain-com/app/
How do I remove mod_perl and perl?
# dnf erase httpd perl mod_perl
Conclusion
That is all for now. My perl is working, including mod_perl with Apache 2 under Fedora Linux. Please see Perl and mod_perl documentation here. Please note that this page provides instructions on installing and configuring mod_perl/perl to create and execute dynamic web pages. However, it is your responsibility to ensure your Perl application is secure. Web programming is vulnerable to various attacks, especially when your application deals with database queries, form submissions, sending emails, caching data, and other similar functionalities. Therefore, I recommend you refer to OWASP Web Security guides for complete information. Furthermore, it is highly advisable to protect your application from unwanted traffic using a web application firewall (WAF). Happy coding in Perl!
🥺 Was this helpful? Please add a comment to show your appreciation or feedback.
You can install an rpm containing a Perl module without knowing its name.
On Fedora, running the command ‘yum install "perl(CGI::Ajax)"‘ will install the rpm containing CGi::Ajax, regardless of what it is called.
That is nice. Thank you for sharing the tip.