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.
- Commands that must be executed as root are marked with
- 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
- Install the mod_perl package from the Arch User Repository (AUR). Refer to Arch Linux’s guide on building packages from the AUR.
- To activate the Apache Perl module, edit the file
/etc/httpd/conf/httpd.conf
and append this line to the list ofLoadModule
directives:
LoadModule perl_module modules/mod_perl.so
- 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.
- When using multiple virtual hosts, you must also modify
/etc/httpd/conf/httpd.conf
by commenting out theScriptAlias
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>
- Restart Apache to apply changes:
# systemctl restart httpd
- Create the required directory:
# mkdir /srv/http/cgi-bin
Setting Up Perl with Nginx
- Install FCGI Wrap:
# pacman -S fcgiwrap
- Enable FCGI Wrap and make it start automatically at boot:
# systemctl enable --now fcgiwrap.socket
- 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;
}
- Create the necessary directory:
# mkdir /usr/share/nginx/html/cgi-bin/
Verifying Perl Functionality
- 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";
- Ensure the script is executable:
# chmod +x test.cgi
- 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. - 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.