chown root cgiwrap chmod 4755 cgiwrap
<!--#include virtual="/cgi-bin/cgiwrap/user/script...."-->
Download cgiwrap and set that up. I already had cgiwrap set up to wrap cgi scripts, but I did upgrade to the latest version. Get this working first with some simple cgi script tests. (BTW: Options you may find helpful include --with-cgi-dir and --with-httpd-user)
Download the latest version of php and configure it as a cgi binary, not as a module. Basically, if you run ./configure with no options, php will be compiled as a cgi binary. (To set it up as an apache module, which you don't want to do if you want to wrap your scripts, you have to explicitly say ./configure --with-apache.)
Before you compile php, however, and this is crucial, configure php with the option --enable-discard-path which allows you to move the php binary out of the web tree and into /usr/local/bin (which adds security), but more importantly it allows you to use php with cgiwrap properly.
To summarize, you need to run ./configure --enable-discard-path plus any other options you may desire, and place the php binary in /usr/local/bin.
Finally, you need the #!/usr/local/bin/php line at the very top of every php script you write. Then call the php script with cgiwrap exactly as you would call a cgi script. For example:
//https://yourdomain.com/cgi-bin/cgiwrap/
//https://www.site1.com/test.cgi
you can call it as
//https://www.site1.com/cgiwrapDir/cgiwrapd/test.cgi
to run it under cgiwrapd. Basically they ScriptAlias "cgiwrapDir" to the directory where cgiwrap is installed.