How do I ignore the Perl shebang on Windows with Apache 2?

前端 未结 8 728
南方客
南方客 2020-11-29 08:31

I have set up a local Perl web environment on my Windows machine. The application I\'m working on is originally from a Linux server, and so the shebang for source .pl<

相关标签:
8条回答
  • 2020-11-29 09:13

    There is no portable shebang line. Even on the same platform and architecture, someone might have installed perl is a different location.

    The trick is to not install modules and scripts by hand. When you package everything as distributions and use the module toolchain, the shebang lines are modified automatically to point to the perl you used to install everything. You shouldn't have to think about these details. :)

    0 讨论(0)
  • 2020-11-29 09:15

    I don't have Windows handy, but perlcritic says:

    my $desc = q{Found platform-specific perl shebang line};
    my $expl = q{Perl source in parrot should use the platform-independent shebang line: #! perl};
    

    So, I guess #! perl should work.

    Edit: doesn't work on linux; apparently works in parrot, although I don't see how they manage that.

    0 讨论(0)
  • 2020-11-29 09:17
    1. Install any Windows Bash flavor (such as Cygwin, MSYS2 or GnuWin32);
    2. Create a trivial redirecting shell script:

      exec "@"
      
    3. Create a registry entry:

      Windows Registry Editor Version 5.00
      
      [HKEY_CLASSES_ROOT\.cgi\Shell\ExecCGI\Command]
      @="<path-to-sh> <path-to-script>"
      
      [HKEY_CLASSES_ROOT\.pl\Shell\ExecCGI\Command]
      @="<path-to-sh> <path-to-script>"
      
      [HKEY_CLASSES_ROOT\.py\Shell\ExecCGI\Command]
      @="<path-to-sh> <path-to-script>"
      

      (...and so on.)

    4. Jot in your httpd.conf file:

      ScriptInterpreterSource Registry
      

    Apache will now resolve Unix shebangs relative to the interpretation given by your choosen Bash flavor. This gives much more flexibility than hardcoding interpreter paths in the registry.

    0 讨论(0)
  • 2020-11-29 09:22

    The way I had this working was to copy perl.exe to c:/usr/bin/ and rename it to perl (strip the .exe)

    0 讨论(0)
  • 2020-11-29 09:24

    How to use Linux shebang (#!/usr/bin/perl) when running Perl based web-site with {site-name} on localhost in Windows 10?

    This works for me:

    • XAMPP on localhost\{site-name} (C:\xampp\htdocs\{site-name})
    • independently installed Strawberry Perl (C:\Perl\perl\bin) because Perl included in XAMPP package is not satisfactory

    In default configuration you must use this shebang:

    #!C:\perl\perl\bin\perl.exe -IC:\xampp\htdocs\{site-name}
    

    Is it possible to include directory (after -I switch) permanently to @INC?

    Yes, you can do it by setting the PERLLIB or PERL5LIB environment variables. This works when running perl script from command line, but surprisingly it is ignored by apache server in XAMPP. However one of @INC directories (C:/Perl/perl/site/lib) is usually empty so you can make symbolic link to your web-site directory:

    mklink /D c:\perl\perl\site\lib C:\xampp\htdocs\{site-name}
    

    Now, you can use this shebang:

    #!C:\perl\perl\bin\perl.exe
    

    Moreover, you can create directory c:\usr\bin

    md c:\usr\bin
    

    and copy perl.exe from C:\perl\perl\bin\

    copy C:\perl\perl\bin\perl.exe c:\usr\bin\perl.exe
    

    (Another mklink trick is not working here from some reasons.)

    Finally, you can use Unix-styled shebang on Windows:

    #!/usr/bin/perl
    
    0 讨论(0)
  • 2020-11-29 09:26

    In win7 and up you can also do this with the "dos" command mklink.

    Start a cmd shell as administrator and do something like the following:

    mklink /d c:\usr c:\Perl       # Activestate perl in c:\Perl\bin\perl.exe
    mklink /d c:\usr c:\xampp\perl # Xampp perl in c:\xampp\perl\bin\perl.exe
    
    0 讨论(0)
提交回复
热议问题