Put a /cgi-bin in grav installation

I would like to put a /cgi-bin directory in a grav installation. However, this seems to conflict with the rules:

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule .* index.php [L]

in the default .htaccess file. Does anyone know of a way I can do this.?


– sw

The rule is that anything actually in the file-system will get processed before this rule. So if you have a cgi-bin/ folder in the root of your site, and you access a file directly in there, it should process fine.

However, not sure why you would need a cgi-bin, that’s very old school technology.

Old school, yes (so are cron jobs)…also extremely useful sometimes…

Well, let me ask this question… How can I make grav generate a page with PHP?

– sw

Well, I take it by your silence that you can’t do what I ask. So, I’m left with the cgi-bin approach. I need to process a POST request generated by a form submission. Where do I put the server for the POST request? In my case, I need to send an email.


– sw

Hi @stevewi. As @rhukster already pointed out, you can actually create a cgi-bin folder directly in the root of the site and place your script there. E.g. if your script is namend action.cgi, then it should be possible (without changing the htaccess) to call yourdomain.com/cgi-bin/action.cgi, provided you have enabled CGI somewhere e.g. in a global “.htaccess” file with content

AddHandler cgi-script .cgi
Options +ExecCGI 

Sorry missed your post, but you cannot create a php page with Grav. For security reasons it uses Twig for output. You can probably create a simple plugin to provide custom functionality equivalent to your CGI executable. There are over 50 example plugins to look at in the downloads.