How do I get Perl scripts to work in Apache on High-Sierra?

I recently upgraded to High-Sierra from a prior system which has Perl installed in /opt directory. On that prior system, web-pages that used 'localhost/cgi-bin/something.pl', executed the script. On High-Sierra, the script is simply displayed on the screen, rather than being executed to create the desired page. I have 'perl' enabled within /etc/apache2/httpd.conf, as shown below:


dickguertin@Dick-Guertin /etc/apache2 ==> grep perl httpd.conf

LoadModule perl_module libexec/apache2/mod_perl.so


Perl scripts have always works on prior systems, from Tiger on up through Sierra. Any help would be appreciated.

Posted on Jul 10, 2018 10:33 AM

Reply
15 replies

Jul 12, 2018 5:44 PM in response to dickguertin

dickguertin wrote:


I'm assuming bt 'shebang line' you mean the "#!/usr/bin/perl" at the start of the script.

Yes. That is the shebang line. However, that is the system Perl, not your Perl in /opt. But let's burn that bridge when we get to it.


I could create a web page displaying the 'httpd.conf' (eliminating the leading # comments to make it smaller).

The problem isn't what is in that file, but what isn't. One of the commented-out lines need to be commented-in. By default, mod_cgi is commented out. That is the module that powers the cgi-script handler you are trying to use.

Once you remove the # from the mod_cgi line and restart Apache, your scripts should work.

Then you can change the shebang line to point to your custom version of Perl. You haven't said anything about why you are using a custom version of Perl. There could be a whole lot more issues to deal with.

My recommendation is to always use local modules in Perl. Run everything out of a user directory with default executables. Then, if you need to upgrade the system, move to a new machine, deploy on AWS, it's no big deal.

Jul 12, 2018 2:07 PM in response to dickguertin

I can assure you it is some kind of configuration problem, not a High Sierra problem.


The example directives from my User Tip work fine for /Library/WebServer/CGI-Executables. I just normally don't use that directory. I'm very much against the /cgi-bin concept. That is, in part, what allowed PHP to become so popular.


The difference is that I am associating .pl files with mod_perl directly.


You are using cgi-script. The mod_cgi Apache module is disabled by default in High Sierra. If you enable that, it might work.


At least, it worked when I tried it. But I am not using a custom version of Perl. If you supply the correct path to your Perl on the shebang line, then it should work. I haven't tested that through.

Jul 12, 2018 10:33 AM in response to BobTheFisherman

Bob. I read the connect/mac.html very carefully, and it ends with a sample 'first.cgi' script with instructions to put it in your Sites folder. Then you're told to "http://localhost/~yourusername/first.cgi to view it." That's exactly what happens ... you VIEW the script, you don't EXECUTE the script. To EXECUTE it, you need to put it in one of two places in "/Library/WebServer/CGI-Executables": either that directory directly, or in a sub-directory which has your username. You can then EXECUTE it with "localhost/cgi-bin/first.cgi". As a test, I copied 'first.cgi' to my sub-directory and called it "second.cgi". Then, "localhost/cgi-bin/username/second.cgi" executed. The 'first' only executes from the main directory, and 'second' only executes from my sub-directory. But let me hasten to add that I did all this on Yosemite AND Sierra. It DID NOT work on High-Sierra. What happens there is that "localhost/cgi-bin/scripts" where "scripts" are either '.pl' or '.cgi' executables, are simple displayed as there are from Sites. They are NOT EXECUTED. So I'm still stuck, and can't switch to High-Sierra until this is resolved.

Jul 12, 2018 5:56 PM in response to VikingOSX

There is no explicit reference to any Perl path in the /usr/libexec/apache2/mod_perl.so shared library text. However, Apple engineers are not building code to conveniently point to package manager installation locations, they are building the code to look at standard High Sierra Perl, and Perl module installation locations.


Although you could explicitly point your shebang in your server-side perl script at the package manager script location, what is to ensure your newer version of Perl will not by default — attempt to use standard system Perl modules rather than those intended for your expected version of Perl?

Jul 12, 2018 12:33 PM in response to etresoft

Hello etresoft, I've been trying to contact you. YES, I read your 'tip', but couldn't REPLY to a tip. I've followed all the instructions, and I've made sure httpd.conf contained the following:


Directory "/Library/WebServer/CGI-Executables">

AllowOverride All
Require all granted
Options ExecCGI Includes MultiViews Indexes SymLinksIfOwnerMatch
AddHandler cgi-script .cgi .pl

/Directory>


On all other systems (Yosemite & Sierra) cgi-biin/script.pl EXECUTES. On High-Sierra, it displays to script.

I don't know what else to do. If I can't get it workiong, I'm going to have to abandon High-Sierra.

I'm willing to communicate via email, where I could include attachments of test-files showing my httpd.conf

if that would help. You can contact me via my Google Home Page where I have an email link. Just use this link for dickguertin

Jul 12, 2018 8:42 PM in response to etresoft

THANK YOU. That was the missing link. I'm not using the '.cgi' suffix, so I didn't think I needed the corresponding module. Now everything WORKS! I updated my Google page, and added an introduction line, giving credit to YOU for this breakthrough. FYI, I altered the /opt path for perl to point (symlink) to /usr/bin/perl. That should insure I'm using the system version of perl going forward. Again, many thanks, I really appreciate your insight.

Jul 13, 2018 8:42 AM in response to dickguertin

Very nice! The mod_cgi module doesn’t care about file extensions. You can define your own extension mappings for any script handler.


You should probably investigate the use of mod_perl. It loads your Perl script once and keeps it active for multiple requests. If you have a busy server, this can increase your performance substantially.


The mod_cgi module is for scripting languages that don’t have their own modules, unlike perl or php. It just uses standard OS facilities to launch your script each time it is triggered. For example, if you wanted to deploy a go script on a standard Apache installation, you would have to use mod_cgi.

Jul 12, 2018 2:40 PM in response to etresoft

I'm assuming bt 'shebang line' you mean the "#!/usr/bin/perl" at the start of the script. What I just showed you is from a script that does NOT work on High-Sierra, but does work on all other prior MacOS versions from Tiger through Sierra. What's at /usr/bin/perl is the High-Sierra supplied version: "root wheel 66608 May 29 15:32 perl". The date is when I installed High-Sierra, for the 2nd time (I erased the prior installation). If it would help, I could create a web page displaying the 'httpd.conf' (eliminating the leading # comments to make it smaller). I'll post it on my Goggle Sites, and Reply to this Post with the URL. This should take me less than an hour.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I get Perl scripts to work in Apache on High-Sierra?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.