Page 1 of 1

Slight cgi file change - End of script output before headers

PostPosted: 28. November 2013 12:06
by Elisabeth2
Encountered an error that amazes me:

copied perl.pl file from
c:\xampp\htdocs\xampp\
to directory in my virtual host dir:
c:\xampp\htdocs\motokohana\public\

pointing web browser to it - it works (shows OK)
When I do ANY slight change in file, it does not work:

"End of script output before headers"

my .htaccess in c:\xampp\htdocs\motokohana\public\:

Code: Select all
AddHandler cgi-script .cgi .pl
Options +ExecCGI

# Turn on URL rewriting
RewriteEngine On

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]


my .htaccess in c:\xampp\htdocs\motokohana\:

Code: Select all
# Turn on URL rewriting
RewriteEngine On


# Protect application and system files from being viewed
# RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteRule ^(.*)$ /public/$1 [L,QSA]


perl.pl:

Code: Select all
#!"C:\xampp\perl\bin\perl.exe"

print "Content-Type: text/html\n\n";
print "OK";




however, when I do any change to it, like
Code: Select all
#!"C:\xampp\perl\bin\perl.exe"

print "Content-Type: text/html\n\n";
print "OK2";


it stops working.

Someone else got similiar problem too: http://stackoverflow.com/questions/17608627/end-of-script-output-before-headers-hello-pl
WTF?

Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 13:45
by Nobbie
I think you use an editor (which one?) that writes the file back in UTF-8 (or UTF-16) character code and prepends the so called "BOM" (= Byte Order Mark) in the beginning of the file. This BOM contains two, three or four bytes, which are invisible (unprintable characters) but influence the Perl Interpreter. See http://en.wikipedia.org/wiki/Byte_order_mark

Analyze the file with a hex editor and/or find out, if youre editor supports UTF-8 and BOM and change the default configuration not to prepend a BOM.

Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 13:53
by Elisabeth2
Thank, I already thought about that... but it does not seem to be the case.
I use notepad++ (saving as UTF8 without BOM) and sublime text. Both with the same result.
I checked in hex editor, and there is no BOM.

What is even stranger when I change print "OK" to print "OK2" and save, it does not work (error 500).
When I change it back to print "OK" and SAVE, it works. So this is not editor that is messing it up.

Saving file with other name also did not help - when I open perl.pl and save it as somethingelse.pl,it works. When I change something, it stops.

Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 14:06
by Nobbie
Maybe a problem of (user/file) permissions? Usually Apache runs as "System" (with low granted rights); maybe your own files are saved with insufficient rights (must not be opened by different user id than yours).

That depends also on Windows (which Windows?) and on the file systems (NTFS? FAT32 does not support user rights).

What tells the error log in case of error 500?

P.S.: Can you provide a link to a "corrupt" .pl file?

Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 14:16
by Elisabeth2
> maybe your own files are saved with insufficient rights

But when I edited the file and later saved the file with original content ( print "OK" ) it worked.

> That depends also on Windows (which Windows?)

Windows 7 professional 64 bit
NTFS file system

Thu Nov 28 13:47:57.174137 2013] [ssl:warn] [pid 3356:tid 668] AH01909: RSA certificate configured for www.example.com:443 does NOT include an ID which matches the server name
[Thu Nov 28 13:47:57.262142 2013] [core:warn] [pid 3356:tid 668] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Thu Nov 28 13:47:57.351147 2013] [ssl:warn] [pid 3356:tid 668] AH01909: RSA certificate configured for www.example.com:443 does NOT include an ID which matches the server name
[Thu Nov 28 13:47:57.389149 2013] [mpm_winnt:notice] [pid 3356:tid 668] AH00455: Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.3 configured -- resuming normal operations
[Thu Nov 28 13:47:57.389149 2013] [mpm_winnt:notice] [pid 3356:tid 668] AH00456: Server built: Feb 23 2013 12:42:00
[Thu Nov 28 13:47:57.389149 2013] [core:notice] [pid 3356:tid 668] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Thu Nov 28 13:47:57.391149 2013] [mpm_winnt:notice] [pid 3356:tid 668] AH00418: Parent: Created child process 6960
AH00548: NameVirtualHost has no effect and will be removed in the next release C:/xampp/apache/conf/extra/httpd-vhosts.conf:51
[Thu Nov 28 13:47:57.958182 2013] [ssl:warn] [pid 6960:tid 680] AH01909: RSA certificate configured for www.example.com:443 does NOT include an ID which matches the server name
[Thu Nov 28 13:47:58.064188 2013] [ssl:warn] [pid 6960:tid 680] AH01909: RSA certificate configured for www.example.com:443 does NOT include an ID which matches the server name
[Thu Nov 28 13:47:58.103190 2013] [mpm_winnt:notice] [pid 6960:tid 680] AH00354: Child: Starting 150 worker threads.
[Thu Nov 28 13:48:32.985185 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53858] End of script output before headers: perl.pl
[Thu Nov 28 13:48:40.493615 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53860] End of script output before headers: perl.pl
[Thu Nov 28 13:48:51.003216 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53862] End of script output before headers: perl.pl
[Thu Nov 28 13:49:08.488216 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53864] End of script output before headers: perl.pl
[Thu Nov 28 13:49:28.501360 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53866] End of script output before headers: perl.pl
[Thu Nov 28 13:52:18.236069 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53873] End of script output before headers: perl.pl
[Thu Nov 28 13:52:22.977340 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53874] End of script output before headers: perl.pl
[Thu Nov 28 13:53:01.503543 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53878] End of script output before headers: som2.pl
[Thu Nov 28 13:56:10.302342 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:53895] End of script output before headers: perl2.pl
[Thu Nov 28 14:16:50.052252 2013] [cgi:error] [pid 6960:tid 1980] [client 127.0.0.1:54389] End of script output before headers: somethingelse.pl

Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 14:24
by Nobbie
can you upload a corrupt .pl file or provide a link?

What do you enter in the Browser to execute that file? As you see, the file is executed in "127.0.0.1" environment, but not in VirtualHost. There is something wrong with redirects, SciptAlias or similar.

Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 14:35
by Elisabeth2
Even tried to restart computer, it did not help :)

link to supposedly corrupt file:
https://www.dropbox.com/s/6bfq5rykmbnlldy/perl.pl

In browser I access file via this address:
http://www.moto.localhost/perl.pl

httpd-vhosts.conf:
Code: Select all
# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>


##<VirtualHost 127.0.0.1:8080>
##DocumentRoot C:/xampp/htdocs/
##ServerName localhost
##ServerAdmin admin@localhost
##</VirtualHost>

NameVirtualHost *:80


<VirtualHost *>
    ServerAdmin admin@localhost
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    ServerAlias localhost
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>





<VirtualHost moto.localhost:80>
   DocumentRoot "C:/xampp/htdocs/motokohana/"
   ServerName moto.localhost
   # ServerAlias www.moto.localhost
   ServerAdmin admin@moto.localhost
   
   <Directory "C:/xampp/htdocs/motokohana/">
      Options Indexes FollowSymLinks
      AllowOverride FileInfo
      AllowOverride All
      Order allow,deny
      Allow from all
   </Directory>
   
</VirtualHost>


Re: Slight cgi file change - End of script output before hea

PostPosted: 28. November 2013 21:39
by Nobbie
I downloaded perl.pl and executed it in my environment (Xampp 1.8.1, Windows 8.1 64bit) and it runs without any error.

Sorry, but this the point where i cannot go any further, i would need to work at your desktop in order to go deeper. I wish you good luck, but i am out of ideas whats going wrong there.

Re: Slight cgi file change - End of script output before hea

PostPosted: 29. November 2013 08:49
by Elisabeth2
Thank you very much.

As I said, this problem is very strange, yet someone encountered similiar problem (post at stockoverflow)

So, the virtual host conf file is OK?