#!/bin/bash
phpwrapper="#!/bin/sh\n\
export PHPRC=/var/www/vhosts/domain.com/etc/\n\
export PHP_FCGI_CHILDREN=4\n\
export PHP_FCGI_MAX_REQUESTS=1000\n\
exec /usr/local/php5422-cgi/bin/php-cgi"
vhost_conf="<Directory /var/www/vhosts/domain.com/httpdocs>\n\
RemoveHandler fcgid-script\n\
<IfModule mod_fcgid.c>\n\
AddHandler fcgid-script .php\n\
<Files ~ (\.php)>\n\
SetHandler fcgid-script\n\
FCGIWrapper /var/www/vhosts/domain.com/cgi-bin/.cgi_wrapper/.phpwrapper .php\n\
Options +ExecCGI\n\
allow from all\n\
</Files>\n\
</IfModule>\n\
</Directory>"
#Adjust the query below to select the domains you want to create php wrapper
domains=$(mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -Ns -e "select name from domains")
for domain in $domains;
do
if [ -e /var/www/vhosts/$domain/cgi-bin ]
then
echo "processing /var/www/vhosts/$domain/cgi-bin"
if [ -e /var/www/vhosts/$domain/conf/vhost.conf ]
then
echo "/var/www/vhosts/$domain/conf/vhost.conf EXISTS skipping"
continue
fi
mkdir /var/www/vhosts/$domain/cgi-bin/.cgi_wrapper
user=$(mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -Ns -e "select login from sys_users where home like '%"$domain"'")
echo -e $phpwrapper | sed "s/domain.com/$domain/" > /var/www/vhosts/$domain/cgi-bin/.cgi_wrapper/.phpwrapper
chmod 101 /var/www/vhosts/$domain/cgi-bin/.cgi_wrapper
chmod 500 /var/www/vhosts/$domain/cgi-bin/.cgi_wrapper/.phpwrapper
chown $user
sacln /var/www/vhosts/$domain/cgi-bin/.cgi_wrapper -R
chattr -R +i /var/www/vhosts/$domain/cgi-bin/.cgi_wrapper
echo -e $vhost_conf | sed "s/domain.com/$domain/" > /var/www/vhosts/$domain/conf/vhost.conf
fi
done