简体   繁体   中英

How do I run Perl files over XAMPP on Windows?

I am new to the Perl language, and I tried running it as I do for PHP files, by putting files in htdocs and then accessing them over localhost.

Below is the Perl file which I created, but wasn't able to run over localhost:

-----hello.pl---------------

   #!/usr/bin/perl
   print "Hello World.\n";

  1. Install xampp. during installation, Make sure that, you have checked perl to be installed.
  2. I assumed that, you have installed xampp in c:/xampp directory.
  3. Now go to c:/xampp/htdocs directory. Inside htdocs directory create a directory perl. Now inside the perl directory, make a file named hello.cgi .
  4. In hello.cgi write the following code snippet.

hello world program:

#!C:\xampp\perl\bin\perl.exe
# The above line is perl execution path in xampp
# The below line tells the browser, that this script will send html content.
# If you miss this line then it will show "malformed header from script" error.
print "Content-type: text/html\n\n";
print "Hello world."

Now start apache from xampp control panel. And in browser's url, enter localhost/perl/hello.cgi.

If your PHP install has the Perl module, you can evaluate Perl code directly from PHP.

<?php
    print "Hello from PHP!";
    $perl = new Perl();
    $perl->require("test1.pl");
    print "Bye!";
?>

First fix the "shebang" line to point to your Perl executable (I use WampDeveloper, not XAMPP, so your path will be different)...

#!C:/WampDeveloper/Tools/Perl/perl/bin/perl.exe
print "Hello World.\n";

Then create a "cgi-bin" directory inside the DocRoot and place you Perl script inside.

In this directory also create an .htaccess file with this inside...

DefaultType text/html
Options -Indexes +ExecCGI
SetHandler cgi-script

Go to the URL: http://www.example.com/cgi-bin/perlscript.pl

Note: This assumes the above directory does not have the htaccess option disabled for it in the main Apache configuration.

Please follow these steps:

  1. Configure your web server to run Perl script (you may follow this url for more info http://editrocket.com/articles/perl_apache_windows.html ).

  2. Create your file (perl script ) and save it in your cgi-bin directory under root xampp. (ie : C:\\xampp\\cgi-bin).

    NB : your file should contain header info like print "Content-type:text/html\\r\\n\\r\\n"; in top of script which will help browser to understand the type of information coming form web server.

  3. Your script should have "shebang" line or else the server will throw an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM