How to use user Perl with Apache CGI program
Learn how to use user Perl with Apache's CGI program.
Apache's CGI programs typically utilize Perl installed on your system. However, to centralize the effort of managing CPAN modules, perlbrew and plenv.
When creating a new web application with Perl, we recommend a web system development method using a reverse proxy that can naturally support real-time web and cloud servers, but if there are existing CGI applications, there are still more. think.
Environment variable settings
There are two ways to set environment variables in Ubuntu Apache, one is to specify it in the envvars file, and the other is to use the SetEnv directive. It is recommended to use the SetEnv directory on individual sites, leaving the envvars untouched, which has a global impact. Note that you can only use constants with SetEnv.
Environment variable PATH setting
Let's set the environment variable PATH. First, check your current PATH. env command and grep command to display PATH. There are multiple environment variables that contain the name PATH, so I'm using Perl regular expressions to narrow it down to just PATH. ..
env | grep -P'^ PATH ='
Make a note of the displayed PATH.
PATH = / home / appuser / perl5 / perlbrew / bin: /home/appuser/perl5/perlbrew/perls/perl-5.20.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin : / usr / bin: / sbin: / bin: / usr / games: / usr / local / games: / snap / bin
Set this value using the SetEnv directory.
SetEnv PATH / home / appuser / perl5 / perlbrew / bin: / home / appuser / perl5 / perlbrew / perls / perl-5.20.3 / bin: / usr / local / sbin: / usr / local / bin: / usr / sbin : / usr / bin: / sbin: / bin: / usr / games: / usr / local / games: / snap / bin
User Perl is now available.
Setting the environment variable PERL5LIB
If you want to load your own Perl library, set the PERL5LIB environment variable.
SetEnv PERL5LIB / home / appuser / my-app / lib
After setting the environment variables, you need to restart Apache.