Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
litespeed_wiki:other-ext-apps:apache-mod-perl-equivalent [2018/04/10 19:56]
Lisa Clarke Proofreading
litespeed_wiki:other-ext-apps:apache-mod-perl-equivalent [2020/08/29 14:56]
Lisa Clarke Copyediting
Line 1: Line 1:
-===== How to Run a Perl Script on LSWS=====+====== How to Run a Perl Script on LSWS ======
  
-LiteSpeed comes with a persistent Perl CGI daemon which can run Perl CGI scripts without modification,​ just like mod_perl in Apache.+LiteSpeed ​Web Server ​comes with a persistent Perl CGI daemon which can run Perl CGI scripts without modification,​ just like mod_perl in Apache.
  
-==== For a Control Panel Environment ==== +===== For a Control Panel Environment ​===== 
-If you configure LSWS to run Perl under a 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 + 
 +==== Set up a Perl FastCGI External App and Script Handler ​==== 
 +If you configure LSWS to run Perl under a 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 ​suffix is used for Perl scripts). The Perl CGI daemon is located at ''/​usr/​local/​lsws/​fcgi-bin/​lsperld.fpl''​
  
-  /​usr/​local/​lsws/​fcgi-bin/​lsperld.fpl 
 {{ :​litespeed_wiki:​other-ext-apps:​lsperld-ext-app.png?​600 |}} {{ :​litespeed_wiki:​other-ext-apps:​lsperld-ext-app.png?​600 |}}
  
 {{ :​litespeed_wiki:​other-ext-apps:​lsperld-ext-app-handler.png?​600 |}} {{ :​litespeed_wiki:​other-ext-apps:​lsperld-ext-app-handler.png?​600 |}}
 +<​code>​
 +    <​extProcessor>​
 +      <​type>​fcgi</​type>​
 +      <​name>​PerlFastCGI</​name>​
 +      <​address>​uds://​tmp/​lshttpd/​perl.sock</​address>​
 +      <​maxConns>​35</​maxConns>​
 +      <​env>​FCGI_PERL_MAX_REQ=1000</​env>​
 +      <​env>​LSAPI_CHILDREN=35</​env>​
 +      <​initTimeout>​60</​initTimeout>​
 +      <​retryTimeout>​0</​retryTimeout>​
 +      <​persistConn>​1</​persistConn>​
 +      <​pcKeepAliveTimeout>​30</​pcKeepAliveTimeout>​
 +      <​respBuffer>​0</​respBuffer>​
 +      <​autoStart>​1</​autoStart>​
 +      <​path>/​usr/​local/​lsws/​fcgi-bin/​lsperld.fpl</​path>​
 +      <​backlog>​100</​backlog>​
 +      <​instances>​1</​instances>​
 +      <​memSoftLimit>​2074M</​memSoftLimit>​
 +      <​memHardLimit>​2074M</​memHardLimit>​
 +      <​procSoftLimit>​400</​procSoftLimit>​
 +      <​procHardLimit>​500</​procHardLimit>​
 +    </​extProcessor>​
 +</​code>​
 +<​code>​
 +   <​scriptHandler>​
 +      <​suffix>​pl</​suffix>​
 +      <​type>​fcgi</​type>​
 +      <​handler>​PerlFastCGI</​handler>​
 +    </​scriptHandler>​
 +</​code>​
  
 Restart LiteSpeed Web Server. Restart LiteSpeed Web Server.
 +==== Testing on cPanel ====
 +For a Perl or CGI script to run in a control panel environment,​ normally you should place the script in a designated directory such as ''/​cgi-bin/'',​ otherwise it may not work.
 +
 +You can create a simple test script hello.pl under /cgi-bin/
 +<​code>​
 +  #​!/​usr/​bin/​perl
 +  use strict;
 +  use warnings;
 +  print "​Content-type:​ text/​html\n\n";​
 +  print("​Hello World\n"​);​
 +</​code>​
 +
 +You can also run perl from the command line to verify the error: ​
 +<​code>​
 +  perl -w hello.pl
 +</​code>​
 +
 +Visit ''​https://​yourdomain.com/​cgi-bin/​hello.pl''​ from the browser to see if it works.
 +
 +If it works from the command line but doesn'​t work from the browser, most likely this is caused by an "​x"​ permission issue. Perl or the CGI script will need to allow everyone "​x"​ permission, like so:
 +<​code> ​
 +  chmod 755 hello.pl
 +</​code>​
 +
 +Perl script errors are beyond our support scope and you are encouraged to google for solutions. You can check [https://​docs.cpanel.net/​knowledge-base/​general-systems-administration/​troubleshooting-guide-for-perl-and-cgi-scripts/​|cPanel'​s documentation] to troubelshoot similar CGI/Perl issues on cPanel.  ​
  
-==== For LSWS Native Configuration ====+===== For LSWS Native Configuration ===== 
 +==== Perl FastCGI for LSWS Native Configuration ====
 For LSWS native configuration,​ you also need to set up the Fast CGI application and add a script handler for "​pl"​. For LSWS native configuration,​ you also need to set up the Fast CGI application and add a script handler for "​pl"​.
  
Line 57: Line 114:
   print "</​body></​html>";​   print "</​body></​html>";​
  
-You should see something similar to the following when visting ''​<nowiki>​http://​yourdomain.com/​test.pl</​nowiki>''​+You should see something similar to the following when visting ''​nowiki>​http://​yourdomain.com/​test.pl</​nowiki>''​
  
 <​code>​ <​code>​
Line 90: Line 147:
 SERVER_SOFTWARE = LiteSpeed SERVER_SOFTWARE = LiteSpeed
 </​code>​ </​code>​
-==== Troubleshooting ====+===== Troubleshooting ​=====
  
 +==== Installation Error on LSWS Native ====
 Without the ''​perl-CPAN''​ package installed, installation may run into the following error: Without the ''​perl-CPAN''​ package installed, 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 .).   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 .).
Line 99: Line 157:
    ​[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    ​[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
  
 +==== lscgid: execve() No such file error ====
 +A simple test perl script on a cPanel server runs into the following error and generates a 500 error code:
 +
 +  lscgid: execve():/​home/​user1/​public_html/​test.pl:​ No such file or directory
 +  ​
 +{{ :​litespeed_wiki:​other-ext-apps:​perl-lscgid-execve-nosuchfile-error.png?​600 |}}
 +
 +But ''/​home/​user1/​public_html/​test.pl''​ //does// exist. So why the ''​No such file or directory''​ error?
 +
 +Inspect the file in vi:
 +
 +  cd /​home/​user1/​public_html/​
 +  vi test.pl
 +  ​
 +There is a ''​^M''​ at the end of each line, which means the file is in DOS/Windows format, not Unix format:
 +
 +  #​!/​usr/​bin/​perl^M
 +  print "​Content-type:​text/​html\n\n";​^M
 +  print <<​EndOfHTML;​^M
 +  <​html><​head><​title>​Perl Environment Variables</​title></​head>​^M
 +  <​body>​^M
 +  <​h1>​Perl Environment Variables</​h1>​^M
 +  EndOfHTML^M
 +  foreach $key (sort(keys %ENV)) {^M
 +    print "$key = $ENV{$key}<​br>​\n";​^M
 +  }^M
 +  print "</​body></​html>";​
 +
 +To test further, try:
 +
 +  [[ $(file test.pl) =~ CRLF ]] && echo dos
 +
 +It returns:
 +  dos
 +
 +Because of the difference in DOS vs Unix format, LiteSpeed lscgid can not recognize the ''​test.pl''​ file. Hence the ''​No such file or directory''​ error.
 +
 +To fix the issue, you will need to convert from DOS format to Unix. There are many ways to do so, including the following ''​awk''​ command:
 +
 +  mv test.pl test.pl.dos
 +  awk '​sub("​$",​ "​\r"​)'​ test.pl.dos > test.pl
 + 
 +You can inspect ''​test.pl''​ again in vi to verify the file format. You should no longer see the trailing ''​^M''​ in each line.
 +
 +  #​!/​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";​
 +  } 
  
 +After the conversion, you should find the perl script is working perfectly. ​
  • Admin
  • Last modified: 2023/03/25 14:06
  • by Lisa Clarke