0

OK, so here's my situation :

  • I've written an interpreter (for a language of my own design)
  • I need every file with a specific extension (e.g. .xxx) to be first handled by my interpreter

Here's what I've tried so far (other than... messy solutions with exec via PHP... lol) :

.htaccess

Options -ExecCGI -MultiViews -Includes -Indexes FollowSymLinks

Action lgm-cgi /usr/local/bin/lgm -c
AddHandler lgm-cgi .lgml

But guess what : It's not working.

I'm requesting www.mydomain.com/index.lgml and instead of returning the processed file, it returns the very same file (index.lgml) as text.

What am I doing wrong? Any suggestions?


I don't consider myself anywhere close to an expert regarding server configuration and .htaccess so I suppose this whole thing might be much easier than I expect; so please shed some light! :-)

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • Considering you are trying to use .htaccess style files we can assume you do _not_ have access to the real server configuration? So most likely this is a hosting environment? Are you sure you can execute cli commands in that environment? And unfortunately you probably also do not have access to the servers error log file? – arkascha Apr 19 '14 at 07:27
  • @arkascha Well, wrong guess. I own the server. (Debian Wheezy + Apache2 installed) So, I have full access to anything; feel free to suggest anything! – Dr.Kameleon Apr 19 '14 at 07:29
  • Then why do you use .htaccess style files for this? They are notoriously error prone, hard to debug, make things complex and really slow the server down. Put such stuff into the server configuration! Then reload the server and watch its error log file. – arkascha Apr 19 '14 at 07:31
  • @arkascha Well, I've tried that but I feel quite lost, it's like doing random things I've seen around and expect them to work. Do you have any specific idea of what is to be written and where, to achieve what I'm trying? – Dr.Kameleon Apr 19 '14 at 07:32
  • Your lines do not seem unreasonable, otherwise I would have pointed obvious things out. So once more: _what does the error log file say?_ – arkascha Apr 19 '14 at 07:36

1 Answers1

0

You have mixed two distinct concepts: handlers and actions. You'd have to write a module to introduce new handler into the httpd server. After that, you'd have to use AddHandler or SetHandler to actually bind it with certain file type and/or URL space.

You would have to double check your error logs, but I suspect that while serving the .lgml file Apache figured out, that lgm-cgi handler doesn't exist and fell back to default-handler, which served your file as flat text.

You are correct however, to use Action here as it is appropriate. You just need to use it a bit differently. First, you should introduce a custom type for your file:

AddType application/lgml .lgml

...then associate that type with your action:

Action application/lgml /usr/local/bin/lgm -c

This should work.

EDIT: As pointed out by kbro, 2nd argument to Action should be a CGI Script. So you'd have to write one (lets say /cgi-bin/lgm-handler.sh) which would call /usr/local/bin/lgm under the hood. Then you would introduce it into the server as such:

Action application/lgml /cgi-bin/lgm-handler.sh
Jacek Prucia
  • 1,026
  • 2
  • 12
  • 22
  • Quite a long time ago, but this is how I made it work. So, thanks for sharing! (who knows, someone else might need it too) ;-) – Dr.Kameleon Dec 01 '14 at 13:36
  • 1
    Not true. "Action" can be used to create a custom handler implemented by a CGI script. You don't need to write a module. http://httpd.apache.org/docs/2.2/handler.html – kbro Aug 04 '15 at 15:00
  • @kbro I've forget about the CGI script requirement. Good catch there. Do not agree with the rest. If you really think Action introduces a custom handler, then please introduce one, then use it with SetHandler directive. If you can come up with such configuration I might just change my mind :) – Jacek Prucia Aug 18 '15 at 12:06