July 31, 2019
> This seems to work well when running not from cgi, so there is
That was not true, it didn't work even from Linux Shell, I corrected shebang, now it works from Linux Shell.

An, unexpected thing: It did require permissions: sudo ./example.d  which was not the case with rdmd.



cgi still shows Internal Server Error.

Maybe cgi cannot run this script due to lacking sudo permissions required by dub? Unsure.


>#!/usr/bin/env -S dub run --single
>/+ dub.sdl:
>	name "hello"
>	dependency "arsd-official" version="~>4.0.1"
>	
>+/
>import std.stdio;
>void main()
>{
>    writeln(`Content-type: text/html`);
>    writeln(``);
>    writeln(`<body style="background: lightgreen">CGI D Example</body>`);
>
>}

July 31, 2019
On Wednesday, 31 July 2019 at 07:42:22 UTC, BoQsc wrote:
>> This seems to work well when running not from cgi, so there is
> That was not true, it didn't work even from Linux Shell, I corrected shebang, now it works from Linux Shell.
>
> An, unexpected thing: It did require permissions: sudo ./example.d  which was not the case with rdmd.
>
>
>
> cgi still shows Internal Server Error.
>
> Maybe cgi cannot run this script due to lacking sudo permissions required by dub? Unsure.
>
>
>>#!/usr/bin/env -S dub run --single
>>/+ dub.sdl:
>>	name "hello"
>>	dependency "arsd-official" version="~>4.0.1"
>>	
>>+/
>>import std.stdio;
>>void main()
>>{
>>    writeln(`Content-type: text/html`);
>>    writeln(``);
>>    writeln(`<body style="background: lightgreen">CGI D Example</body>`);
>>
>>}


It seems that /var/log/apache2/error.log shows Permission denied error.

>[Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 140090256426752] [client >127.0.0.1:57052] malformed header from script 'example.d': Bad header: Fetching arsd-official 4.0.1 (
>/usr/lib/cgi-bin/.dub/packages/: Permission denied


July 31, 2019
On Wednesday, 31 July 2019 at 07:57:01 UTC, BoQsc wrote:
>>[Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 140090256426752] [client >127.0.0.1:57052] malformed header from script 'example.d': Bad header: Fetching arsd-official 4.0.1 (
>>/usr/lib/cgi-bin/.dub/packages/: Permission denied

Added sudo to the shebang, it started to say that sudo requires tty, meaning that there is no graphical interface for user to input the password.

>[Wed Jul 31 11:14:53.183607 2019] [cgid:error] [pid 6207:tid 140374439274240] [client >127.0.0.1:57400] End of script output before headers: example.d
>sudo: no tty present and no askpass program specified

Script:
>#!/usr/bin/env -S sudo dub run --single
>/+ dub.sdl:
>	name "hello"
>	dependency "arsd-official" version="~>4.0.1"
>	
>+/
>import std.stdio;
>void main()
>{
>    writeln(`Content-type: text/html`);
>    writeln(``);
>    writeln(`<body style="background: lightgreen">CGI D Example</body>`);
>
>}




July 31, 2019
On Wednesday, 31 July 2019 at 08:32:43 UTC, BoQsc wrote:
> Added sudo to the shebang, it started to say that sudo requires tty, meaning that there is no graphical interface for user to input the password.

So, I remove the need to type password when using sudo command, by following these instructions:
https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/

And this is the error I get now:
>[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d


July 31, 2019
On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote:
> And this is the error I get now:
>>[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d

And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error.


>#!/usr/bin/env -S sudo dub run --quiet --single
>/+ dub.sdl:
>	name "hello"
>	dependency "arsd-official" version="~>4.0.1"
>	
>+/
>import std.stdio;
>void main()
>{
>    writeln(`Content-type: text/html`);
>    writeln(``);
>    writeln(`<body style="background: lightgreen">CGI D Example</body>`);
>
>}

Maybe it is not possible to use dub this way.

July 31, 2019
On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote:
> On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote:
>> And this is the error I get now:
>>>[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d
>
> And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error.


It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything.
https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache
July 31, 2019
On Wednesday, 31 July 2019 at 10:24:38 UTC, BoQsc wrote:
> On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote:
>> On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote:
>>> And this is the error I get now:
>>>>[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d
>>
>> And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error.
>
>
> It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything.
> https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache

As info, the command
  dub app.d is
rewritten to:
  dub run -q --temp-build --single app.d

I wonder whether -q is correct here
  -q Only print warnings and errors
maybe --vquiet should be used instead
  -vquiet Print no messages

If there are any warnings, from dub / dmd these could cause invalid
Internal Server Errors.

Kind regards
André


July 31, 2019
On Wednesday, 31 July 2019 at 10:24:38 UTC, BoQsc wrote:
> On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote:
>> On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote:
>>> And this is the error I get now:
>>>>[Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d
>>
>> And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error.
>
>
> It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything.
> https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache

Please see
https://github.com/adamdruppe/arsd/issues/203

Kind regards
André
July 31, 2019
On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote:
>>	dependency "arsd-official" version="~>4.0.1"

I just changed the thing, so now you will want to use version 4.0.2 and also require the cgi configuration rather than the default (I don't know how to do that in dub).

Though personally, when I do cgi stuff in D, I don't bother with rdmd or dub or whatever, I just compile the program separately and copy the binary in to the cgi directory. It is more efficient and simpler to handle in error cases.
July 31, 2019
Hmm, it seems that once I remove sudo from the shebang, the error disappears and Internal Server Error disappears.

example.d - does not work
>#!/usr/bin/env -S sudo dub /+ dub.sdl:
>	name "hello"
>	
>	
>+/
>import std.stdio;
>void main()
>{
>    writeln(`Content-type: text/html`);
>    writeln(``);
>    writeln(`<body style="background: lightgreen">CGI D Example</body>`);
>
>}


/var/log/apache2/error.log

>[Wed Jul 31 15:48:07.769766 2019] [cgid:error] [pid 4012:tid 140324198397696] [client >127.0.0.1:51736] End of script output before headers: example.d


example.d - Works perfectly, no errors in the log
>#!/usr/bin/env -S dub /+ dub.sdl:
>	name "hello"
>	
>	
>+/
>import std.stdio;
>void main()
>{
>    writeln(`Content-type: text/html`);
>    writeln(``);
>    writeln(`<body style="background: lightgreen">CGI D Example</body>`);
>
>}