How to Install and Configure Perl 5.28 on Arch Linux with Apache or Nginx

Requirements

  • A server with the latest Arch Linux version installed.
  • An operational web server (either Apache or Nginx).
  • Sudo privileges:
    • Commands that must be executed as root are marked with #.
    • It is recommended to run these commands by prepending sudo as a standard user.
  • A text editor you are comfortable with, such as vi, vim, nano, emacs, or any similar tool.

Installing Perl 5.28 on Your Web Server

Perl is included in the Arch base group, so it is typically installed alongside the system.

Setting Up Perl with Apache

  1. Install the mod_perl package from the Arch User Repository (AUR). Refer to Arch Linux’s guide on building packages from the AUR.
  2. To activate the Apache Perl module, edit the file /etc/httpd/conf/httpd.conf and append this line to the list of LoadModule directives:

LoadModule perl_module modules/mod_perl.so

  1. For every <Directory> block where you wish to allow Perl script execution, insert the following configuration:

<Directory "/srv/http/cgi-bin">
    AllowOverride None
    Require all granted
    AddHandler perl-script .pl
    AddHandler perl-script .cgi
    PerlResponseHandler ModPerl::Registry
    Options +ExecCGI
    PerlOptions +ParseHeaders
</Directory>

If the section already includes Options None, make sure to remove or comment it out.

  1. When using multiple virtual hosts, you must also modify /etc/httpd/conf/httpd.conf by commenting out the ScriptAlias directive to prevent all /cgi-bin/ requests from being routed to /srv/http/cgi-bin/ for every host:

<IfModule alias_module>
...
    #ScriptAlias /cgi-bin/ "/srv/http/cgi-bin/"
</IfModule>

  1. Restart Apache to apply changes:
  1. Create the required directory:

Setting Up Perl with Nginx

  1. Install FCGI Wrap:
  1. Enable FCGI Wrap and make it start automatically at boot:

# systemctl enable --now fcgiwrap.socket

  1. To allow Nginx to use FCGI Wrap, modify /etc/nginx/nginx.conf and add this block to each server section that should handle Perl scripts. If you use virtual hosts, edit each one accordingly:

location ~ /cgi-bin/.*\.(cgi|pl)$ {
    root         /usr/share/nginx/html/;
    fastcgi_pass unix:/run/fcgiwrap.sock;
    include      fastcgi.conf;
}

  1. Create the necessary directory:

# mkdir /usr/share/nginx/html/cgi-bin/

Verifying Perl Functionality

  1. In the corresponding CGI directory, generate a file named test.cgi containing the following script:

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "perl works\n";

  1. Ensure the script is executable:
  1. Navigate to http://YOUR-SERVER-WEB-ADDRESS-OR-IP/test.cgi in your web browser. If everything is configured properly, you will see the message: perl works.
  2. Don’t forget to remove the test.cgi file after the test.

Conclusion

By following this guide, you’ve successfully enabled Perl 5.28 support on an Arch Linux web server using either Apache or Nginx. Whether you chose mod_perl or FCGI Wrap, your setup is now capable of executing Perl scripts, and ready for more complex CGI applications. Always remember to remove test files and ensure proper permissions and configurations for production use.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: