Code snippets, tech tricks and other bits and bobs

cgi_wrapper: Per-domain php.ini under php-fastcgi (Plesk 9.5.2 + CentOS 5)

I recently discussed per-directory php directives utilising htscanner, allowing setting values with php_flag and php_value in .htaccess files.

While this is an enormous step forward in term of granular control for the webmaster, it doesn't allow complete control as some things don't work when set in .htaccess as I discovered when trying to set apc config values.

The problem stems from being unable to use vhosts.conf to specify php_admin_value as you would running PHP as an Apache module, and having to resort to other methods. I did attempt http://kb.parallels.com/9059, but it was a complete failure, because Paralells neglect to mention that you must be running Plesk 9.5.2+ in order to utilise cgi_wrapper as directed.

I had been avoiding updating Plesk, as last time I'd done so it had mangled quite a few things, but I bit the bullet, and this time the process seems to have been entirely successful.

From http://kb.parallels.com/9059

The hotfix is as follows:

It is possible to use custom php.ini for domains if php as FastCGI mode is used on it. 
It is necessary to apply hotfix. Fix is compatible with Parallels Plesk Panel versions 9.x.

Use the following instruction for applying hotfix.

1. Download hotfix from the attachment

# wget http://kb.parallels.com/Attachments/13985/Attachments/cgi_wrapper

2. Locate file cgi_wrapper

# cat /etc/psa/psa.conf |grep CGI_PHP CGI_PHP_BIN /var/www/cgi-bin/cgi_wrapper/cgi_wrapper

3. Create a backup of this file

# cp /var/www/cgi-bin/cgi_wrapper/cgi_wrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper_orig

4. Replace cgi_wrapper with the downloaded one

# cp cgi_wrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper

5. Copy php.ini to the configuration directory of domain

# cp php.ini /var/www/vhosts/domain.tld/conf/

6. Change permissions on the configuration directory of the domain

# chmod 0755 /var/www/vhosts/domain.tld/conf

7. Restart apache

# /etc/init.d/httpd restart
Should the download become unavailable, I have included the contents of the updated cgi_wrapper here for convenience:
#!/bin/sh

domain=`fgrep -m 1 "$UID" /etc/passwd| awk -F\: '{print $6}' |awk -F"/" '{print $5}'`
PHPRC=/var/www/vhosts/$domain/conf/php.ini

[ -f ${PHPRC} ] || PHPRC="/etc/php.ini"

export PHPRC
exec /usr/bin/php-cgi -c "$PHPRC"

Filed under  //   CentOS 5   PHP   Plesk 9   Plesk 9.5.2+   cgi_wrapper   php-fastcgi   php.ini