This is an old revision of the document!
How to run perl script on LSWS?
LiteSpeed comes with a persistent Perl CGI daemon which can run perl CGI script without modification, just like mod_perl in Apache.
For Control Panel Environment
If you configure LSWS to run perl under control panel environment, such as cPanel, you need to configure it as a Fast CGI application, and then add a script handler for “pl” or whatever suffixes used for Perl scripts. The Perl CGI daemon is located at
/usr/local/lsws/fcgi-bin/lsperld.fpl
Restart LSWS, then done.
For LSWS native configuration
For LSWS native cofiguration, you also need to procede the above step to setup Fast CGI application and then add a script handler for “pl”.
As “lsperld.fpl” utilizes the Fast CGI interface, it has normally been configured on control panel environment already. However you may need to install Perl Fast CGI module FCGI.pm first in LSWS + bare OS situation since it may not be installed.
Perl Fast CGI module is available at CPAN(Comprehensive Perl Archive Network).
On CentOS7, to add perl-CPAN package first.
yum install epel-release yum install gcc yum install perl-CPAN
The following command can be used to install FCGI.pm through CPAN:
perl -MCPAN -e 'install FCGI'
On CentOS box, you can easily install perl-CGI and perl-FCGI packages through:
yum install perl-CGI
Verify the installed location of FCGI.pm.
find / -name FCGI.pm /usr/lib64/perl5/vendor_perl/FCGI.pm
In order to deal with increasing memory usage of a persistent process, the number of requests that a Perl daemon can process is controlled by an environment variable FCGI_PERL_MAX_REQ, the default is 500. For example: FCGI_PERL_MAX_REQ=1000.
Restart LSWS to make the changes effective.
Testing
Place a test script at document root of one of your virtual host: test.pl
#!/usr/bin/perl print "Content-type:text/html\n\n"; print <<EndOfHTML; <html><head><title>Perl Environment Variables</title></head> <body> <h1>Perl Environment Variables</h1> EndOfHTML foreach $key (sort(keys %ENV)) { print "$key = $ENV{$key}<br>\n"; } print "</body></html>";
You should see something similar to the following when visting http://yourdomain.com/test.pl
Perl Environment Variables DOCUMENT_ROOT = /usr/local/lsws/DEFAULT/html FCGI_PERL_MAX_REQ = 1000 FCGI_ROLE = RESPONDER GATEWAY_INTERFACE = CGI-PerlEx/1.1 HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 HTTP_ACCEPT_ENCODING = gzip, deflate HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.9 HTTP_CONNECTION = keep-alive HTTP_COOKIE = SESS3d805002e809eafb1aa4295801ff28d0=AXgcoPkfgngK9KYuHS4wIn9eVLHEndfHAy7Ys9Gnj4M; COMBIN=2e9910cb4771588a621ae6371c01550bdbe3e6d498788981dca50a1ab6bef6d3; COMINF=bypass_varnish HTTP_HOST = 192.168.0.178:8088 HTTP_UPGRADE_INSECURE_REQUESTS = 1 HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 LSAPI_CHILDREN = 35 LSAPI_PADDING = leave_some_room_to_avoid_overwrite_important_env PATH = /bin:/usr/bin:/usr/local/bin QUERY_STRING = REMOTE_ADDR = 192.168.0.198 REMOTE_PORT = 4322 REQUEST_METHOD = GET REQUEST_URI = /test.pl SCRIPT_FILENAME = /usr/local/lsws/DEFAULT/html/test.pl SCRIPT_NAME = /test.pl SERVER_ADDR = 192.168.0.178 SERVER_ADMIN = SERVER_NAME = 192.168.0.178 SERVER_PORT = 8088 SERVER_PROTOCOL = HTTP/1.1 SERVER_SOFTWARE = LiteSpeed
Troubleshooting
Without perl-CPAN package installed, the above installation may run into the following error:
Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .). BEGIN failed--compilation aborted.
Without installing FCGI.pm, you may run into the following error in stderr.log and 503 error on screen.
[STDERR] Can't locate FCGI.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/lsws/fcgi-bin/lsperld.fpl line 3