Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HELP!

Community support for Plesk, CPanel, WebMin and others with insight from two of the founders of Plesk. Ask for help here! No question is too simple or complicated. :-)
ClearlyTechnical
Forum User
Forum User
Posts: 37
Joined: Wed Feb 09, 2005 6:27 pm

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by ClearlyTechnical »

mneese wrote:I don't have any idea what this person did, but if you have 9.2.1, there was posted by plesk a patch to cover such issues. Also, simply upgrading to 9.2.2 would handle the issues also.

I wonder why he didn't discover within the plesk panel, under web settings for each domain the option to have php run as apache or fcgi?

Don't you love it when you invest time and energy to help someone, then they drop out of sight with the solution?
mneese, and you helped by doing what?

9.2.2 didn't fix the problem.

Obviously I am aware of the per domain setting for FCGI, that was the whole purpose of my post to begin with.

Getting php.ini settings per domain was not easy. But when it works, it makes installing things like SugarCRM, Joomla, Civicrm and the like a piece of cake.

Anyway, I think what happened was that I had another set of drama to deal with. It was related to doing ftp backups and restores and getting all that to jive. If anyone is still struggling, please post and I will be happy to share whatever I can. Sorry if I wasn't here to help when you needed it. I can definitely understand your frustration.


Thanks
BruceLee
Forum Regular
Forum Regular
Posts: 879
Joined: Sat Mar 28, 2009 6:58 pm
Location: Germany

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by BruceLee »

Hi ClearlyTechnical,

back in town?! mneese tried to help too, but you disappeared :)
It's not that difficult to get php.ini per domain with psa-mod_fcgid-1.10-3. It takes some modifications and about 30 minutes.
And with Plesk 9.5.2 it's even 100 times easier:
1. set domain to fastcgi
2. edit the cgi wrapper file under /var/www/cgi-bin/cgi_wrapper/cgi_wrapper to your needs
mine looks like this:

Code: Select all

#!/bin/sh
#
# Custom PHP FCGID wrapper for Plesk domains
#
 A=`fgrep -m 1 "$UID" /etc/passwd| awk -F\: '{print $6}' |awk -F"/" '{print $5}'`
 PHPRC=/var/www/vhosts/php-inis/$A/php.ini
 [ -f ${PHPRC} ] || PHPRC="/etc/php.ini"
 export PHPRC
 exec /usr/bin/php-cgi
3. create php.ini for the domain you want with correct permissions (if no php.ini for this domain is present the default php.ini is used)
4. service apache graceful
-> and there you GO.

I use it and it works great.
People like me waited for your tutorial you talked about to get some indications from it to be able to help you better
and maybe reuse it or at least understand your situation better.

Great that your way works for you.
ClearlyTechnical
Forum User
Forum User
Posts: 37
Joined: Wed Feb 09, 2005 6:27 pm

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by ClearlyTechnical »

[php-cgi located here:]
/usr/bin/php-cgi

[In your /var/www/vhosts/domain.com/conf/vhost.conf file]

<Directory /var/www/vhosts/domain.com/httpdocs>
<IfModule mod_fcgid.c>
<Files ~ (\.php)>
FCGIWrapper /var/www/vhosts/domain.com/httpdocs/php-cgi.sh .php
Options All
</Files>
</IfModule>
</Directory>


[In your httpdocs directory in a file called "php-cgi.sh" (set as executable)]

#!/bin/sh
exec /usr/bin/php-cgi -c /var/www/vhosts/domain.com/httpdocs/


[Put your "php.ini" file in httpdocs directory and set to your liking]


[Default settings for files and directories. Remember, if rights are TOO HIGH, you throw 500 error. A big problem for most people is that they follow the ill advised suggestion of 777 when installing those all too famous LAMP based apps and then get confused as to why they are getting 500 errors. It's the opposite, you don't need to go 777, 700 or 760 works for most directories, as well as 600 or 644 for most files.]

chown -R yourFTPname.psacln *
find . -type f -exec chmod 644 {} \; &
find . -type d -exec chmod 755 {} \; &


This should help someone. Please give back to the community.

Don't forget to:
/usr/local/psa/admin/sbin/websrvmng -a -v &

Also:
psa-fcgi-2.4.0-2
psa-mod-fcgid-configurator-1.0-14
psa-mod_fcgid-1.10-3
Last edited by ClearlyTechnical on Thu Nov 18, 2010 1:45 pm, edited 1 time in total.
BruceLee
Forum Regular
Forum Regular
Posts: 879
Joined: Sat Mar 28, 2009 6:58 pm
Location: Germany

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by BruceLee »

another way to do it, more complicated since vhost.conf is not necessary but it should work too.
Hultenius
Forum User
Forum User
Posts: 15
Joined: Sun May 29, 2005 7:27 am

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by Hultenius »

If you don't like the idea of having hundreds of (possibly outdated) php.ini-files, use the wrapper below. It will add open_basedir protection without the need of creating vhost-specific php.ini files. You could also write some fancy if-statements around the variable $MAINDOMAIN to set vhost-specific PHP settings. Works on Plesk 9.5 or later.

/var/www/cgi-bin/cgi_wrapper/cgi_wrapper

Code: Select all

#!/bin/sh
HOMEDIR=`grep ":$UID:" /etc/passwd | cut -d: -f6`
MAINDOMAIN=`grep ":$UID:" /etc/passwd | cut -d: -f6 | cut -d/ -f5`
ARGS="-d safe_mode=0 -d open_basedir=/tmp/:$HOMEDIR/httpdocs/"
exec /usr/bin/php-cgi $ARGS
Don't forget to restart apache.
BruceLee
Forum Regular
Forum Regular
Posts: 879
Joined: Sat Mar 28, 2009 6:58 pm
Location: Germany

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by BruceLee »

That's a nice way too. Do you have any vhost specific if statements running?
How would that impact the performance of the process if it runs hundreds of if-statements? More or less than loading the individual php file?
Another possibilty of that solution is to make some sort of config file that just loads the ARGS vhost specific.

Something like:
ARGS="-d | cat /var/www/vhosts/:$MAINDOMAINR/configfile"
ClearlyTechnical
Forum User
Forum User
Posts: 37
Joined: Wed Feb 09, 2005 6:27 pm

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by ClearlyTechnical »

BruceLee wrote:another way to do it, more complicated since vhost.conf is not necessary but it should work too.
Yep. It was for 9.2.1 as a replacement to su_php which fell short for something I was doing.

Anyway, it was a monster to figure out back then.
ClearlyTechnical
Forum User
Forum User
Posts: 37
Joined: Wed Feb 09, 2005 6:27 pm

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by ClearlyTechnical »

Why don't we put together a nice How-To for this issue. I would have to put it as a top-10 issue for anyone doing virtual hosting and working with popular LAMP applications, no?

Who's with me?
Hultenius
Forum User
Forum User
Posts: 15
Joined: Sun May 29, 2005 7:27 am

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by Hultenius »

BruceLee wrote:That's a nice way too. Do you have any vhost specific if statements running?
How would that impact the performance of the process if it runs hundreds of if-statements? More or less than loading the individual php file?
Another possibilty of that solution is to make some sort of config file that just loads the ARGS vhost specific.

Something like:
ARGS="-d | cat /var/www/vhosts/:$MAINDOMAINR/configfile"
Not yet, but I don't think that would be a performance problem. The wrapper is not executed on each request. FastCGI keeps spawned processes alive for 500 requests or so.
However, I like your idea. Having settings in separated files might be better since the main domain can be changed.
What about this wrapper:

Code: Select all

#!/bin/sh
HOMEDIR=`grep ":$UID:" /etc/passwd | cut -d: -f6`
ARGS="-d safe_mode=0 -d open_basedir=/tmp/:$HOMEDIR/httpdocs/"
if [ -e "$HOMEDIR/php.conf" ]; then
        ARGS="$ARGS -d `cat $HOMEDIR/php.conf | sed 'N;N;s/\n/ -d /g'`"
fi
exec /usr/bin/php-cgi $ARGS
This wrapper will turn on open_basedir protection for all vhosts (and disable safe mode which is not needed anymore). If you want to set more values, just create a php.conf file in the home directory (/var/www/vhosts/mydomain.com/ or /var/www/vhosts/mydomain.com/subdomains/mysubdomain/) and put one setting on each line. Example:

Code: Select all

memory_limit=96M
upload_max_filesize=32M
max_execution_time=120
... and don't forget to restart apache.


ClearlyTechnical wrote:Why don't we put together a nice How-To for this issue. I would have to put it as a top-10 issue for anyone doing virtual hosting and working with popular LAMP applications, no?

Who's with me?
Sounds like a great idea! I just recently started experimenting with PHP over FastCGI and boy was it hard to find any good information. We also need a script to automatically fix permissions on all files and folder (both chown and chmod). It would be a nightmare to switch from mod_php to mod_fcgid otherwise.
BruceLee
Forum Regular
Forum Regular
Posts: 879
Joined: Sat Mar 28, 2009 6:58 pm
Location: Germany

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by BruceLee »

That's nice. I would go the way without the ifstatement. If something is so global that I set it all the time I can do it the main php.in anyway. Maybe I will test this during X-mas<>NewYear time.
Sounds like a great idea! I just recently started experimenting with PHP over FastCGI and boy was it hard to find any good information. We also need a script to automatically fix permissions on all files and folder (both chown and chmod). It would be a nightmare to switch from mod_php to mod_fcgid otherwise.


Great. Lets just brainstorm and put our experiences here and at the end we can write a summary for the wiki.

If I need to set something client related in httpdocs I go to the desired directory and run:

Code: Select all

find . -type d -exec chown user:group {} \;
find . -type f -exec chown user:group {} \;
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
Of course that's still a manual way but it helps doing it quickly. Triggering it when changes are made in Plesk might not be trivial. Or what kind automatic did you mean?
ClearlyTechnical
Forum User
Forum User
Posts: 37
Joined: Wed Feb 09, 2005 6:27 pm

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by ClearlyTechnical »

I use like/kind, but I through the ampersand & on there as directories like civicrm etc. get quite large.

Also, you guys should look at this:
http://download1.parallels.com/Plesk/PP ... /index.htm

and

http://download1.parallels.com/Plesk/PP ... /index.htm


Might be a way to go one level up on the scripting piece of your model.
Last edited by ClearlyTechnical on Sat Nov 20, 2010 2:27 pm, edited 2 times in total.
ClearlyTechnical
Forum User
Forum User
Posts: 37
Joined: Wed Feb 09, 2005 6:27 pm

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by ClearlyTechnical »

Brucelee or anyone,

I have a program I am trying to install. As a plesk user, you know that ownership is the ftpuser and the group is psacln.

The problem is that fastcgi won't allow a script to be written by anyone other than the owner (755/644 or lower) and my script needs the webserver user (apache?) to be able to write to some of these files or directories.

So the software vendor of course offers the cursed advice of 777, which any fastcgi user knows will toss you that beloved 500 error. (sometimes too much of anything is a bad thing, lol).

Ok, so, what is the solution here?

How can I let two users own the same file? I can't right? and if I can't allow anyone other than the user to change a script, then adding apache to the psacln group does me no good correct?

I am sure I am not the only one to run into this, and I would be mightly greatful to gain some insight as to the solutions many of you have come up with.


Thanks
BruceLee
Forum Regular
Forum Regular
Posts: 879
Joined: Sat Mar 28, 2009 6:58 pm
Location: Germany

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by BruceLee »

You could create another group with ftpuser and apache in it and set that on the specific folder.
Which tool/product is it you want to install?
Hultenius
Forum User
Forum User
Posts: 15
Joined: Sun May 29, 2005 7:27 am

Re: Per Domain php.ini Settings with FastCGI Plesk 9.2.1 HEL

Unread post by Hultenius »

BruceLee wrote: If I need to set something client related in httpdocs I go to the desired directory and run:

Code: Select all

find . -type d -exec chown user:group {} \;
find . -type f -exec chown user:group {} \;
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
Of course that's still a manual way but it helps doing it quickly. Triggering it when changes are made in Plesk might not be trivial. Or what kind automatic did you mean?
Not fun if you have hundreds of domains. And don't forget that you have to do this on all subdomains too (+ web users). Possibly httpsdocs aswell.
This will lead to many human errors, late nights... and craziness :)

I want to do a permanent move to FastCGI and ditch mod_php altogether. That's my goal. But the transition has to be smooth.

On another note (and even more off topic), it seems the htscanner project is taking up steam again. A contributor has done quite a bit of work the last few days. Looks promising. Not being able to set php values in .htaccess files is the last obstacle.
Post Reply