By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,678 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,678 IT Pros & Developers. It's quick & easy.

Problem serving executables with HTML out

rohswell
P: 2
When my Apache installation tries to serve an executable file (web page) it gives an internal server error. I have installed and setup Apache under Cygwin under Windows XP. I am writing web pages for an embedded Linux system and using the setup above as a development/test platform. Each web page is a C program, compiled and linked to produce an executable using Cygwin and Gnu C. For example, the home page would be index.exe. When this program is executed on the Cygwin command line, it sends HTML to stdout that defines the web page. The HTML is valid per HTML 4.01 Transitional.

I attempted to configure Apache to execute all web pages as CGI scripts. Here are the significant lines from httpd.conf:

Expand|Select|Wrap|Line Numbers
  1. ServerRoot "/tools/apache"
  2. DocumentRoot "/tools/apache/htdocs"
  3. <Directory "/tools/apache/htdocs">
  4.     Options Indexes FollowSymLinks ExecCGI
  5.     AllowOverride None
  6.     Order allow,deny
  7.     Allow from all
  8. </Directory>
  9.  
  10. <IfModule alias_module>
  11.     ScriptAlias /cgi-bin/ "/tools/apache/htdocs/"
  12. </IfModule>
  13.  
  14. <IfModule mime_module>
  15.     TypesConfig conf/mime.types
  16.     AddType text/html .exe
  17.     AddHandler cgi-script .exe
  18. </IfModule>
  19.  
Apache works and serves HTML pages, but will not serve index.exe in the htdocs folder. The URL http://192.168.0.101/index.exe produces an internal server error. The error log reads:
[Tue Feb 05 09:02:56 2008] [error] [client 192.168.0.101] Premature end of script headers: index.exe

The access log reads:
192.168.0.101 - - [05/Feb/2008:09:02:56 -0700] "GET /index.exe HTTP/1.1" 500 535

Again, I know that index.exe produces valid HTML out. If I redirect its output to a file, say home.htm, then Apache will serve that HTML file just fine.

I guess I did something wrong in the config file, but I don't know what. I've read the documentation on the config parameters. I changed the ScriptAlias value from cgi-bin to htdocs because I want all the web pages in the main web folder, not in a separate place.

This is where I really struggle trying to understand. Why would CGI scripts be placed in a folder outside the main web site anyway? I also write PHP web sites served on hosted machines and I don't have to create a special folder for the PHP files.

Any help will be greatly appreciated. Thanks.
Feb 5 '08 #1
Share this Question
Share on Google+
1 Reply


rohswell
P: 2
Here's some new information.

In the config file, I commented out everything in the Alias module and left the entries for mime types. Now Apache will serve .exe files, as long as they run to completion and produce text/html out.

The problem has been narrowed to a call to shmget to access shared memory segments created by another process. Any CGI program using this shared memory method will run correctly if executed on the Cygwin command line. However, it always fails when Apache runs it.

I tried changing User to rayf and Group to None to match what I see in Cygwin. But that had no affect. So the question becomes, what is it about the Apache process that causes shmget to fail? The error reported by Apache is still "Premature end of script headers" which now makes sense because I understand the header line "Content-type: text/html\n\n" is not being sent because index.exe dies in shmget before it generates output.
Feb 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.