Why is cgi app not working? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- raelb · 2016-05-31 12:02 Hi, I have created a basic cgi app using Lazarus 1.4.0, on Ubuntu 12.04. I upload it to my web server but it returns "Internal Server Error". File permissions have been set. The url is: http://www.bauerapps.com/cgi-bin/cgiapp2/mod1/echo (I also tried http://www.bauerapps.com/cgi-bin/cgiapp2/echo etc..) My code looks like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  var  mod1: Tmod1; implementation {$R *.lfm} { Tmod1 } procedure Tmod1.DataModuleRequest(Sender: TObject; ARequest: TRequest;  AResponse: TResponse; var Handled: Boolean);begin  AResponse.ContentType := 'text/html;charset=utf-8';  AResponse.Contents.Text:= 'datamodule request';  Handled := True;end; procedure Tmod1.echoRequest(Sender: TObject; ARequest: TRequest;  AResponse: TResponse; var Handled: Boolean);begin  AResponse.ContentType := 'text/html;charset=utf-8';  AResponse.Contents.Text:= 'echo request';  Handled := True;end; initialization  RegisterHTTPModule('mod1', Tmod1);end.     Just really basic code. (A cgi from the web server works fine: http://www.bauerapps.com/cgi-bin/test.cgi) The server log returns: [Tue May 31 11:34:02 2016] [error] Premature end of script headers: cgiapp2 Any idea of what is wrong? Thanks Rael ---------------------------------------------------------------------- Leledumbo · 2016-05-31 13:39 Code looks fine, assuming lfm and other things (compiler options, etc.) are correct. FPC version should be OK as Lazarus 1.4.0 is shipped with FPC 2.6.4 so it must be something else, we need a lot more details. What type of app? CGI? FCGI? Embedded server? If the former two, what web server? How's the config? What compiler options used to build the app? All in all, better attach a compileable project at least we can reduce the possibilities of error source. "Premature end of script headers" at the most basic form means the web server cannot communicate with the application binary, i.e. it gets no output at all. ---------------------------------------------------------------------- raelb · 2016-05-31 15:46 It is a "CGI Application", using the default settings. Attached is the project file. Not sure of all the web server details. It is a linux shared web hosting using Plesk 12.5 Control panel. It appears to be using Apache & nginx. As mentioned, an existing "test.cgi" works ok. If you can provide a linux cgi app that is known to be working, I can upload it and see if it works. Thanks Rael ---------------------------------------------------------------------- Leledumbo · 2016-05-31 17:43 Easy way to check whether a CGI app works is to simply execute it in a terminal like normal console programs, which your program does fine (so it does as well on my nginx + uwsgi + cgi plugin). So it's integration with the web server that's problematic. You must understand and be sure specifically what web server is used by the hosting and how it's configured to serve CGI, i.e.: to which directory it should be uploaded, setting the executable permission, etc. There can't be 2 web servers listening to the same port. ---------------------------------------------------------------------- raelb · 2016-05-31 20:05 Can you please tell me how I can execute the cgi from the terminal? How to call specific action? Is it possible for you to me send your compiled cgi app so I can see if that works? [email to support @ bauerapps dot com] Thanks ---------------------------------------------------------------------- Leledumbo · 2016-06-01 09:19 Quote from: raelb on May 31, 2016, 10:05:16 pmCan you please tell me how I can execute the cgi from the terminal? Code: [Select]$ ./yourcgibinaryQuote from: raelb on May 31, 2016, 10:05:16 pmHow to call specific action? Code: [Select]$ REQUEST_METHOD=GET REQUEST_URI=/whateveryourmoduleis/whateveractionithas ./yourcgibinaryQuote from: raelb on May 31, 2016, 10:05:16 pmIs it possible for you to me send your compiled cgi app so I can see if that works? [email to support @ bauerapps dot com] What for? It's your own binary that I use. Try to make it work locally on your machine first. If you can't even get that to work, don't dream it would work in a shared hosting/vps/whatever. Also, consult your hosting documentation. Shared hosting usually has clear documentation as the environment has been specifically tailored and you must adhere to the rules. Use vps if you want as-you-wish rules, but again, it will be of no use if you can't properly connect your CGI binary to the web server. ---------------------------------------------------------------------- raelb · 2016-06-01 22:03 You are quite correct, the problem is on the web server. My provider informed me that they support cgi scripts but not compiled cgi applications. Never heard of that before, but now I know! Thanks alot for your assistance. ---------------------------------------------------------------------- Phil · 2016-06-01 22:59 That's very common. In fact, I've never seen a free Web server that permits compiled executables. Try a free one-year Amazon Web Services account. Part 4 of this series will get you started: https://dl.dropboxusercontent.com/u/28343282/MacXPlatform/PascalDynLib s.html -Phil ---------------------------------------------------------------------- raelb · 2016-06-02 10:11 Hi Phil, Thanks for the link. Actually I did not say free. This is a paid shared web hosting service. With previous hosting providers I have managed to use lazarus cgi, that's why I thought I was doing something wrong in my code. Regards Rael ---------------------------------------------------------------------- Thaddy · 2016-06-02 10:19 Quote from: raelb on June 02, 2016, 12:11:01 pmHi Phil, Thanks for the link. Actually I did not say free. This is a paid shared web hosting service. With previous hosting providers I have managed to use lazarus cgi, that's why I thought I was doing something wrong in my code. Regards Rael If it is for testing purposes you can always ask me. I have several domains/on virtual servers doing nothing and my webhoster allows compiled cgi binaries (compiled for 64bit linux). I can create a subdomain for you for a limited period. Note that I have full access and I WILL check for proper use (bad experiences in the past). But basically it is free. For a limited amount of users: I am not a hoster myself. And only for FPC compiled cgi's and a basic webpage. Say 25MB space or something that should suffice for even the most complex stuff. My hoster is flexweb. Not expensive and with great service. If your tests warrant it: buy some space yourself. Think about €25,- a year incl. domain name. You can choose between xxx.youdotoo.net, xxx.youcooktoo.net, xxx.youwritetoo.net. Take your pick and ask politely by email. xxx is of course your preferred subdomain name. It is not referring to content ---------------------------------------------------------------------- raelb · 2016-06-03 11:07 @Thaddy: Thanks for the offer.