Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache / XAMPP for Windows incorrectly treats file as executable

I'm running XAMPP 1.8.1 with Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 on my dev machine to test my projects. In both my private project and in well known Bootstrap Datepicker component I can choose any language (one of 38 in case of datepicker) but not Polish.

Upon deeper investigation, I found out that this is caused, because when browser tries to load locale file (general.pl.json, in case of my project and bootstrap-datepicker.pl.js, in case of Bootstrap Datepicker), server (Apache) fails with 500 Internal Server Error.

After analyzing Apache error.log file, I found out, that this is happening, because Apache somehow is trying to execute this file as (probably Perl) executable script:

[win32:error] [pid 5128:tid 1680] [client 127.0.0.1:53455] AH02102: C:/XAMPP/htdocs/mobile/public/pg-demo-bootstrap/locales/general.pl.json is not executable; ensure interpreted scripts have "#!" or "'!" first line, referer: http://127.0.0.1/mobile/public/pg-demo-bootstrap/
[cgi:error] [pid 5128:tid 1680] (9)Bad file descriptor: [client 127.0.0.1:53455] AH01222: don't know how to spawn child process: C:/XAMPP/htdocs/mobile/public/pg-demo-bootstrap/locales/general.pl.json, referer: http://127.0.0.1/mobile/public/pg-demo-bootstrap/
[win32:error] [pid 5128:tid 1644] [client 127.0.0.1:53465] AH02102: C:/XAMPP/htdocs/us/ustv/assets/6dafd2fe/js/locales/bootstrap-datepicker.pl.js is not executable; ensure interpreted scripts have "#!" or "'!" first line, referer: http://127.0.0.1/us/ustv/content/manage/update.html?id=4
[cgi:error] [pid 5128:tid 1644] (9)Bad file descriptor: [client 127.0.0.1:53465] AH01222: don't know how to spawn child process: C:/XAMPP/htdocs/us/ustv/assets/6dafd2fe/js/locales/bootstrap-datepicker.pl.js, referer: http://127.0.0.1/us/ustv/content/manage/update.html?id=4

I did a lot of tests with changing contents and file names, using many fake files to pretend this file (Polish locale) and it all brought conlusion, that content is not a problem, only .pl in filename makes trouble.

Good questions are:

  1. Why Apache claims, this is script, though .pl (Perl?) part of filename is in the middle and filename actually ends with .js or .json?

  2. Why Apache for Windows is trying to execute Linux/Unix/Bash scripts and is looking for #! or '! characters in the first line of it?

Even better question is, how to fix this, so Apache would start treating this file as a simple Javascript, like all other locale files? And would not attempt to execute it?

like image 345
trejder Avatar asked Jul 16 '13 08:07

trejder


2 Answers

In xampp\apache\conf\httpd.conf, there should be a line like:

AddHandler cgi-script .cgi .pl .asp

Simply comment out this line like so:

#AddHandler cgi-script .cgi .pl .asp

and restart Apache. If you want to keep the .cgi and .asp handlers, just delete .pl from the line. Perl will actually still work even if you do this.

like image 170
AlliterativeAlice Avatar answered Nov 05 '22 10:11

AlliterativeAlice


I ran into the same issue, the previous answer did not solve the problem for me, but lead me to the Apache docs at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler which says:

Filenames may have multiple extensions and the extension argument will be compared against each of them.

The multiple extensions link lead to another section on the same page which explains that files can have multiple extensions. Ie.: welcome.fr.html is treated the same as welcome.html.fr. The order of extensions is not relevant and a filename can even contain multiple languages as in welcome.html.en.de. The advantage is that the defined languages are sent in the HTTP headers.

Configure handler based on final extension only:

<FilesMatch \.pl$>
SetHandler cgi-script pl
</FilesMatch>

To make this work I had to remove the handler for pl first:

RemoveHandler pl
like image 43
lmeurs Avatar answered Nov 05 '22 10:11

lmeurs