2

I'm trying to run a simple fcgi program (for testing purposes) from my browser.

I took the code from here: (fcgi not cgi) Run a C Program on a Linux Server

I replaced \n\n with \n\r\n\r at the end of the HTTP header.

I also made sure http.conf has the following VirtualHost:

<VirtualHost [snip]>
SuexecUserGroup "#502" "#502"
ServerName [snip]
ServerAlias [snip]
ServerAlias [snip]
ServerAlias [snip]
DocumentRoot /[snip]/public_html
ErrorLog /var/log/virtualmin/[snip].com_error_log
CustomLog /var/log/virtualmin/[snip].com_access_log combined
ScriptAlias /cgi-bin/ /[snip]/[snip].com/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /[snip]/[snip].com/public_html>
    Options -Indexes +IncludesNOEXEC +SymLinksifOwnerMatch +ExecCGI
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    AddHandler fcgid-script .php
    AddHandler fcgid-script .php5
    AddHandler fcgid-script .fcgi
    FCGIWrapper /[snip]/fcgi-bin/php5.fcgi .php
    FCGIWrapper /[snip]/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /[snip]/cgi-bin>
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.[snip].com
RewriteRule ^(.*) https://[snip]:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.[snip]
RewriteRule ^(.*) http://[snip]:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
</VirtualHost>

I added the handler line for fcgi files only, the rest was generated by Virtualmin when creating the sub domain.

I've been searching for the past 2h and made some experiments without any good results. I always get 500 Internal Server Error.

Error log:

[Mon Feb 03 18:16:39 2014] [warn] [client SNIP] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Mon Feb 03 18:16:39 2014] [error] [client SNIP] Premature end of script headers: pibell_server.fcgi

Thank you very much.

Community
  • 1
  • 1
  • 2
    `Premature end of script headers` often means the cgi-program crashed. Please show us the code for the program. If it is long, cut it down to a minimal test-case (Hello World) and paste it here. Did you try executing the program from the commandline to see if it runs at all? – grebneke Feb 03 '14 at 15:34
  • As pointed in my first post, I took the code from here: http://stackoverflow.com/questions/14596199/run-a-c-program-on-a-linux-server (fastCGI code, not CGI). How can I run the program from the command line? Simply executing it works? Or do I have to run it using fcgi? – Diogo Parrinha Feb 03 '14 at 18:20
  • @grebneke I have compiled it again, this time on my server and it worked fine from the command line. However, when I run it from my browser: http://[snip].com/cgi-bin/pibell_server.fcgi I still get a 500 internal error. The error log is the same. I even tried putting it in public_html but the error is still there. – Diogo Parrinha Feb 03 '14 at 18:36

1 Answers1

1

The following is extracted from the original question:

@grebneke it turned out that permissions were actually incorrect!

This may help other people:

  1. Make sure the script runs from the command line (thanks @grebneke !)

  2. I applied the following commands to set the permissions properly:

    [root@s1 cgi-bin]# chmod a+rx file.fcgi

    [root@s1 cgi-bin]# chown yourapacheuser:yourapacheuser file.fcgi

I ran the file from mysite.com/cgi-bin/file.fcgi by the way. Not sure if this mandatory but I also have this in my virtual host:

AddHandler fcgid-script .fcgi
d33tah
  • 10,999
  • 13
  • 68
  • 158
  • 1
    I'm not sure if this is normal, but this "answer" was actually an edit to my original question and you took the edit out and posted the answer. This is the first time I use stack overflow, perhaps this is normal here..perhaps it is the way it should be :p – Diogo Parrinha Feb 03 '14 at 20:09
  • Feel free to edit my post to emphasise it even further. I could also switch this post to community wiki or let it be removed if you post the answer on your own. You deserve the rep points for this post more than I do, so it's not a problem for me. I just wanted it to comply with the Q&A form - you put the answer in the question, which is bad. – d33tah Feb 03 '14 at 20:12
  • I understand that, but unfortunately I do not have enough rep points to answer my question. I had to wait 8 hours. Wouldn't be fair to waste other people's time who would answer my question, when I have solved the problem already :) You can take the rep points, I don't need them :p – Diogo Parrinha Feb 03 '14 at 20:32
  • I upvoted you to get you closer to the threshold, whatever it is ;) – d33tah Feb 03 '14 at 21:53