PDA

View Full Version : FastCGI on Modern DirectAdmin



skaag
12-01-2008, 05:34 AM
So I am finding a lot of very old guides on how to install FastCGI on DirectAdmin, with Apache 2.x, PHP 5.x CGI, etc.

Can someone who has done this recently point me to a good guide that works on Debian 4.0?

Thanks!
Skaag

tillo
12-01-2008, 06:08 AM
I did just that two weeks ago on a developement box and placed it tonight in production. FastCGI+APC, perfect config, almost compatible with DA and custombuild conf overwrite.
It's very stable and worth the effort.

I'll soon create a guide, complete with some statistics and technical conclusions.

skaag
12-01-2008, 07:14 AM
That's awesome. I would love to take part in the writing of that guide, and I can test it as well + make sure it's friendly, well designed, etc.

scsi
12-01-2008, 07:15 AM
All you have to do is use custombuild.

cd /usr/local/directadmin/custombuild
edit options.conf how you want it
./build update
./build all d

skaag
12-01-2008, 07:17 AM
And which option do you turn on for FastCGI exactly, besides choosing php5-cgi?
The desired effect is FastCGI + SuPHP + APC, just like tillo describes above.

scsi
12-01-2008, 07:24 AM
php5-cgi is fastcgi

You can install suphp with ./build suphp

I never heard of apc not sure what that is.

skaag
12-01-2008, 07:26 AM
No, php-cgi is not fastcgi. There is no fastcgi daemon, or spawned process from Apache, such as fcgi-pm. If you are running this thinking it is fastcgi you are mistaken... (And you are missing out on some great performance).

scsi
12-01-2008, 07:47 AM
http://andrewk.net/test.php

I would think according to this it is fastcgi?

smtalk
12-01-2008, 07:52 AM
Server API: CGI/FastCGI (it doesn't mean it's working as FastCGI).

scsi
12-01-2008, 07:54 AM
Well then why does custombuild not support fastcgi? Does anyone have a guide to get it working?

tillo
12-01-2008, 08:14 AM
I'll explain everything in the guide :)
The main reason for which custombuild doesn't get FastCGI working (even if it actives the builtin FastCGI handler, that's what you see in phpinfo() or `php-cgi -v') is that it's pretty hard to integrate in an existing solution.

It's been 6 months since I tried FastCGI the first time, since then I've had to read a lot of very old and WRONG documentations, tutorials and manuals to make it work just as I think is the best way.

Furthermore, running FastCGI with a very special config is the only way to make a proper use of APC/XCache/eAccelerator (PHP opcode cachers) if you can't use mod_php because you use the "worker" MPM Apache2 connection handler and any PHP not-threading-safe module. If you are on mod_php/prefork, there is absolutely no need for FastCGI AFAIK.

Like I said, it's hard and I'll explain in the detail all of that.
I would love your help skaag, just added you on MSN. Let me know if you prefer AIM or Skype.

skaag
12-01-2008, 08:28 AM
I'm currently on all of those mediums, I also added you on AIM for example.

lkbryant
12-01-2008, 11:00 AM
what is buildconf override ?

is that something that'd make .htaccess work just as it did on mod_php on fcgi?

ehsanch
12-24-2008, 12:31 PM
tillo im very interested to read you guide. it is long time im waiting for that.

tillo
12-25-2008, 03:57 AM
I'm sorry about that, I'm still doing it but I'm going to be a little late.
I'm trying to fill it up with any information that could be useful to anyone, but in the meantime I've some personal things to solve.

I'm probably going to finish it for the beginning of the new year.

dlong500
01-28-2009, 06:00 PM
Hey tillo,
Any progress on your FastCGI guide? I'd love to read it if you're going to be releasing it soon so I could get a good perspective on someone who has dealt with this recently (and maybe avoid having to wade through a bunch of incomplete/old guides).

tillo
01-28-2009, 06:10 PM
I'll make an effort and finish it, hopefully in a few days.
Sorry to keep everyone waiting, live is a bitch and it seems like lately she had to prove it to me :(

dlong500
01-28-2009, 06:24 PM
Thanks! I'm sure I speak for a lot of people when I say how much I appreciate people who take the time to share good info that saves time and frustration for everyone else. It's worth the wait.

dlong500
02-19-2009, 08:14 PM
Hey tillo, just checking again on the status of the FastCGI guide. I'm not trying to put pressure on you but maybe just trying to be a "squeaky wheel". :D

tillo
02-20-2009, 04:54 AM
I don't mind being pushed a little :) it's on my TODO list, as always. I've got a surgery last week and I'm resting, I'm going to work on it as soon as I'm on my feets.

skaag
02-23-2009, 03:55 PM
Damn Tillo, I hope everything is OK!!! Get well soon!! :-)
Long time no speak by the way. I did notice you are absent from the messengers for a long time now. I just hope you are ok. Feel good! :)

Inquisitor
04-08-2009, 10:26 AM
I don't mind being pushed a little :) it's on my TODO list, as always. I've got a surgery last week and I'm resting, I'm going to work on it as soon as I'm on my feets.
I'm also looking forward to this guide, and I hope that your recovery from the surgery went well. :)

If you need anyone to help test the guide, then I'd be more than willing to, if I'm free at the time. Thanks for putting in the effort, tillo.

tillo
04-22-2009, 07:11 PM
Oh my, I even managed to totally forget about this little project of mine... my profound apologies to those who were waiting, I'll try to complete it soon enough.
@Inquisitor: I'll contact you in private as soon as the first version is done :) thank you!

Jerret
06-23-2009, 01:45 AM
We haven't forgotten! :)

If you get this puppy done don't forget to let us know.

Thanks,
Jerret

Jerret
06-23-2009, 02:06 AM
Just stumbled across this post:

http://www.directadmin.com/forum/showpost.php?p=124878&postcount=450

Isn't this the same thing but you're showing the steps for installing XCache vs APC?

Regards,
Jerret

tillo
06-23-2009, 02:29 AM
It's slighty similar, but I've done many improvements since.

I still haven't had time to work on it, but, as request by skaag, some time ago I've gathered a (hopefully) complete set of my config files (see below).
@skaag: how did things go for you?

It's important to note that this config is ment for a very special system: many GB of RAM and very few users all with very high traffic.
Of course the "right" tutorial will guide you into build a correct config for your needs, but this will be enough for skilled people. Also remember that you can use per user php.ini files, allowing you to choose which users will have the APC extension, how much memory will they use and which of their scripts can be ignored.

First, the set of config files: http://www.tillo.ch/temp/fastcgi.txt

And I also sent this message to him afterwards:

Hi there,

There is one huge thing that needs to be done in order to make my FastCGI-driven system work: Apache2 has to be compiled with the Worker MPM.



root@edge:/usr/local/directadmin/custombuild# cat custom/ap2/configure.apache
#!/bin/sh
"./configure" \
"--prefix=/etc/httpd" \
"--exec-prefix=/etc/httpd" \
[...]
"--with-ssl=/usr" \
"--enable-headers" \
"--with-mpm=worker" \
"--enable-proxy-connect" \
[...]


As you can see, after "--enable-headers" I've added "--with-mpm=worker". The other things don't matter.

Here is the worker configuration:


root@edge:/etc/httpd/conf/extra# cat httpd-mpm.conf
[...]
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 1
ServerLimit 4
MaxClients 256
MinSpareThreads 32
MaxSpareThreads 64
ThreadsPerChild 64
MaxRequestsPerChild 0
</IfModule>
[...]

- StartServers MUST be 1.
- ServerLimit should be set to 1 if you can't afford to have FastCGI to be run more then once. It's a failsave option, if you run 32 php-cgi processes and have 33 users connected at the same time 64 processes will be spawned. If you set 1 the 33th user will timeout.
- MaxClients should be the exact same amount of php-cgi processes spawned by FastCGI
- MaxRequestsPerChild MUST be 0 to have APC cache the opcode forever (or until apache is restarted)

The other values can be modified according to your performance needs.

Here is what the processes should look at the end:



$ pstree -u 27854
httpd─┬─httpd(apache)───65*[{httpd}]
├─httpd(apache)
└─httpd(apache)─┬─php-cgi(webapps)───256*[php-cgi]
├─php-cgi(tillo)───256*[php-cgi]
├─php-cgi(noirgame)───256*[php-cgi]
├─php-cgi(lithium)───256*[php-cgi]
└─php-cgi(exty)───256*[php-cgi]

Jerret
06-23-2009, 12:49 PM
Thanks Tillo,

This is my situation indeed - a server with 9GB of ram and only a handful of users. My intention is to preserve the suphp ownership mechanism but increase performance/responsiveness by eliminating the setup/teardown nature of CGI php and adding the performance enhancements of caching the opcode.

I'll look into it in more detail tonight, thanks again!

Best Regards,
Jerret Kinsman

tillo
06-23-2009, 02:18 PM
I'm glad it fits your needs, please let me know if there is anything missing.
I really wanted to make a nice tutorial out of that, I hope I will someday.

BLTYNR
09-04-2009, 12:20 PM
Tillo thank you, i have do everything in this post :
http://www.directadmin.com/forum/showpost.php?p=124878&postcount=450

How can i chek of everything is done?




[root@serv ~]# php -v
PHP 5.2.10 (cli) (built: Sep 3 2009 21:13:20)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by ionCube Ltd., and
with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies

grockord
09-06-2009, 09:45 PM
Fastcgi is more faster than cli mode?

Randy
09-07-2009, 06:46 AM
Another possibility is to run mod_ruid, that runs the entire httpd-proces under a user. A short install guide from my internal wiki: (EL5/x86_64)


yum installl libcap-devel
cd /usr/src
wget http://websupport.sk/~stanojr/projects/mod_ruid/mod_ruid-0.6b.tar.gz
tar -xzf mod_ruid-0.6b.tar.gz
cd mod_ruid-0.6b
/usr/sbin/apxs -a -i -l cap -c mod_ruid.c
cd /usr/local/directadmin/data/templates
cp virtual_host2* custom/
cd custom
wget http://crew.pcextreme.nl/files/linux/util/directadmin/da_vhosts_templates_apache2_mod_ruid.tar.gz
tar -xzf da_vhosts_templates_apache2_mod_ruid.tar.gz
rm -f da_vhosts_templates_apache2_mod_ruid.tar.gz
nano /etc/httpd/conf/httpd.conf

Add above "ServerAdmin admin@localhost":
# mod_ruid
RMode config
RUidGid apache apache


echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue

Randy
09-07-2009, 06:50 AM
Fastcgi is more faster than cli mode?

Yes and no. But FastCGI runs PHP under the user, not under apache : apache. So a php.ini per user is possible. No more 666/777 chmods. Thus, this is more safe. It's the same as suphp, only now we dont spawn a cgi process for every request but leave these open with an fcgi-deamon. (Use the deamon from lighthttpd). It saves a lot of (disk) i/o too.

tillo
09-07-2009, 10:18 AM
How can i chek of everything is done?


First, if FastCGI is used correctly your processes should look something like this:


$ pstree -u
[...]
├─httpd─┬─httpd(apache)───65*[{httpd}]
│ ├─httpd(apache)
│ └─httpd(apache)─┬─php-cgi(webapps)───128*[php-cgi]
│ ├─php-cgi───128*[php-cgi]
│ ├─php-cgi(tillo)───128*[php-cgi]
[...]


Also, the APC distribution includes an apc.php script that you can place wherever you want to see if caching is well used.
Just like this one: http://www.tillo.ch/apc.php

massive
10-03-2009, 07:31 AM
Thanks for the guide tillo.
I succeded to install it. One question.
Is it possible to have php.ini for each user?

tillo
10-03-2009, 02:54 PM
It is indeed possible, just follow any guide related to DA and PHP-CGI. With my guide you already have a wrapper, so it may just as easy as adding a variable definition into the FastCGI wrapper that instruct PHP to read $USER/php.ini (or whatever).
I never did it, so I can't tell you if that's all.

ditto
02-10-2010, 03:15 AM
[..]If you are on mod_php/prefork, there is absolutely no need for FastCGI AFAIK.[..]

At the moment I am using PHP 5.2.12 with CLI. I am not using any firewall solutions (like APC). Would you reccomend me to change to use FCGI?

I am conserned if my server is not "secure" enough with CLI. After I have been reading about it, I don't want suphp or CGI because of the performance is not so good as with CLI.

So I am left with FastCGI then? Should it be OK to run FastCGI without suphp, as I don't want suphp?

The problem is that the technician at my datacenter don't seem to have any qualifications on FastCGI.

I am running a server with shared hosting clients, and I am just about to move all my clients to a new server with the following spesifications:

* Supermicro SYS-6016T-UF
* Dual Intel Xeon Quad-Core E5504 2.00GHz
* 4 x 500GB 7.2kRPM 32MB (using RAID10)
* 12GB DDR3-1333MHz

And it will have CentOS 5.x 64bit, Apache 2.2.14, PHP 5.2.12 and MySQL 5.0.90 (and of course newest DA version).

Can I PM you about a enquiry for setting this new server up with FastCGI, and configure FastCGI it to be optimal for many users on the same server? Maybe it will be to expensive?

I feel uncertain about the security when running CLI, but don't see any other good solutions then FastCGI, but don't have the knowledge to do this myself. Do you think that a server can be secure enough when only using CLI?

tillo
02-10-2010, 04:34 AM
I see a little bit of confusion, but that's understandable since you have a technician who should do that for you. But if you want to make the good decisions (and that's your role) I suggest you learn some more about it.

A few hints:

- APC (the one I was talking about, of course) is not a firewall. It has absolutely nothing to do with security. APC opcode cacher is an extension for PHP that caches and provides ready "opcode" (that's what PHP creates after parsing a script) to PHP when a script is requested. It is developed by the PHP guys. It requires either mod_php or FastCGI to work, because the PHP handler must be persistent (normal CGI does not have one).

- The problem with mod_php (a.k.a. CLI) is that there is no stable way (experimental ways exist) to execute PHP scripts under the corresponding user, creating vulnerable situations (mainly the possibility to read and/or write each others files)

- suphp and suexec (which are used differently but the result is almost the same) both solve the aforementioned problem, but they need PHP in CGI mode (normal or FastCGI it doesn't matter)

In conclusion, if you want security use either suphp or suexec (therefore PHP in CGI or FastCGI mode).
If you want security with the same performance as mod_php, use FastCGI (the performance loss is caused by process spawning, which is avoided by FastCGI).
If you want even more performance (but make sure it is compatible with all of your customers software) use APC.

Hope I've been clear enough, tell me if I didn't.

EDIT: to answer your request for practical help, I'm not that expensive usually but these days I just don't have time (new job, new home) unless paid *a lot* (I guess money beats stress :D).

ditto
02-10-2010, 04:50 AM
If you want security with the same performance as mod_php, use FastCGI (the performance loss is caused by process spawning, which is avoided by FastCGI).

So if I use FastCGI, I would not need to use suphp at all, and still get the better security (better then CLI)?

Thank you for all the valuable information in your post!

tillo
02-10-2010, 05:05 AM
Nope, I meant: "If you want security use suphp, which requires CGI mode, and if you don't want to lose performance use it with FastCGI and not the normal CGI".

You won't escape from using suphp (or suexec), that's for sure. For any reason you may stick to, that keeps you from using it, there is at least one workaround. :)

ditto
02-10-2010, 05:13 AM
Nope, I meant: "If you want security use suphp, which requires CGI mode, and if you don't want to lose performance use it with FastCGI and not the normal CGI".

You won't escape from using suphp (or suexec), that's for sure. For any reason you may stick to, that keeps you from using it, there is at least one workaround. :)

Thank you!

ditto
02-10-2010, 05:43 AM
My datacenter have now agreed to configure suphp and FastCGI on my new server. Is there a way for a beginner like me (with limited knowledge of this) to be able to check wether FastCGI actual is setup (and not only CGI) on my server? This so that I afterwards can check this after the technician at the datacenter say they have completed the job?

tillo
02-10-2010, 06:41 AM
Yes there is, a simple one really. The output of "pstree -u" and "pstree -up" should contain something similar to those snippets:


$ pstree -u
[...]
├─httpd─┬─httpd(apache)───65*[{httpd}]
│ ├─httpd(apache)
│ └─httpd(apache)─┬─php-cgi(webapps)───128*[php-cgi]
│ ├─php-cgi(tillo)───128*[php-cgi]
│ ├─php-cgi(noirgame)───128*[php-cgi]
│ ├─php-cgi(lithium)───128*[php-cgi]
│ ├─php-cgi(exty)───128*[php-cgi]
│ ├─php-cgi(drunkard)───128*[php-cgi]
│ ├─php-cgi(psyastro)───128*[php-cgi]
│ └─php-cgi(vito)───128*[php-cgi]
[...]



$ pstree -up
[...]
| | |-{httpd}(14831)
| | `-{httpd}(14832)
| |-httpd(30625,apache)
| `-httpd(30626,apache)-+-php-cgi(3839,webapps)-+-php-cgi(3840)
| | |-php-cgi(3841)
| | |-php-cgi(3842)
[...]


You can see clearly that there are 8+8*128 persistent php-cgi processes, a master and 128 handlers for each web user on my server. The exact number depends on the setup of course.

I added the second snippet to show you how to check that they are persistent: the PID must always be the same (they will eventually change on respawn, when needed, or Apache restart). For example, 3839 is the PID for my webapps's master process.

FastCGI offers the possibility to respawn the master and handlers processes from time to time in order to exit from a stale PHP state in case of a bug, but don't let it do too much often: it would recreate the performance loss between mod_php and CGI, because processes take time (and IO+CPU load) to spawn.
On my setup I never let any process respawn, and I never had any problem.

ditto
02-10-2010, 06:49 AM
Thank you so much, Tillo! It is reassuring that I afterwards can check this myself.

Gander
02-17-2010, 05:31 PM
Hello. I am Polish with poor english, so sorry for grammar errors ;)

I doing step-by-step instructions from it: http://www.tillo.ch/temp/fastcgi.txt , skipping settings for php4. I have some troubles with suPHP and virtual_hosts.conf, but finally all errors go away :)

Unfortunately, i can't run any php script: pages is "loading..." a long time, and finally I get "500 Internal Server Error"...

This is my configs, listed like "fastcgi.txt":

x-wing:~# cat /etc/httpd/conf/extra/httpd-phpmodules.conf
#LoadModulesuphp_module/usr/lib/apache/mod_suphp.so
LoadModule fastcgi_module /usr/lib/apache/mod_fastcgi.so

x-wing:~# cat /etc/httpd/conf/extra/httpd-includes.conf
# All FastCGI directives
Include conf/extra/httpd-fcgi.conf

x-wing:~# cat /etc/httpd/conf/extra/httpd-fcgi.conf
<IfModule mod_fastcgi.c>
ScriptAlias /fcgi5 /opt/fcgi/php5.fcgi

<Directory "/opt/fcgi">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
SetHandler fastcgi-script
</Directory>

AddHandler fastcgi-script .fcgi

FastCgiIpcDir /tmp
FastCgiWrapper /opt/fcgi/suexec
FastCgiConfig -maxClassProcesses 1 -maxProcesses 16 -processSlack 1 -idle-timeout 300 -pass-header HTTP_AUTHORIZATION

AddType application/x-httpd-php5 .inc .php .cphp .phtml .php5

Action application/x-httpd-php5 /fcgi5

</IfModule>

x-wing:~# ls -la /opt/fcgi
total 36
drwxr-xr-x 2 root root 4096 Feb 17 22:52 .
drwxr-xr-x 3 root root 4096 Feb 17 22:29 ..
-rw-r--r-- 1 root root 170 Feb 17 22:34 php5.fcgi
-rwsr-xr-x 1 root root 24080 Feb 17 22:52 suexec

x-wing:~# cat /opt/fcgi/php5.fcgi
#!/bin/sh
PHPRC="~"
export PHPRC
PHP_FCGI_CHILDREN=256
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=50000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php5/bin/php-cgi

x-wing:~# /usr/local/php5/bin/pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
APC 3.0.19 stable

x-wing:~# tail -n 6 /usr/local/etc/php5/cgi/php.ini
[APC]

extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/apc.so

apc.shm_size = 128
apc.filters = "sql_.*\.php"


x-wing:~# pstree -u
init-+-atd(daemon)
|-cron
|-da-popb4smtp
|-directadmin(nobody)---5*[directadmin]
|-dovecot-+-dovecot-auth
| |-16*[imap-login(dovecot)]
| `-16*[pop3-login(dovecot)]
|-exim(mail)
|-httpd---6*[httpd(apache)]
|-init-logger
|-mysqld_safe---mysqld(mysql)---9*[{mysqld}]
|-named(bind)---4*[{named}]
|-portmap(daemon)
|-proftpd(ftp)
|-rsyslogd---3*[{rsyslogd}]
`-sshd-+-sshd---bash
`-sshd---bash---pstree


I have no idea what is wrong?

tillo
02-18-2010, 01:21 AM
First thing I see is that php5.fcgi doesn't have the executable bit. Run "chmod +x /opt/fcgi/php5.fcgi". This may be the main problems, but check Apache and PHP errors logs to be sure.

Also, make sure that when you run "/usr/sbin/httpd -M" there is "fastcgi_module". If there isn't, the path may be wrong or the module may not be compiled correctly. Again, check in the Apache errors log.

Same thing with the APC module, once you get PHP running check with the apc.php file (laying somewhere in your system, copy it into a public_html directory) that APC is loaded and working.

Finally, I specified (outside the fastcgi.txt, but in every post where I refer to it) you should run the worker MPM and you are using the prefork MPM (the Apache handlers are processes and not threads). I'm not sure this will prevent FastCGI from working but there is absolutely no reason to stick with the prefork MPM since you don't use mod_php anymore, and it's a huge performance killer.

Gander
02-18-2010, 03:35 AM
Yes, chmod was a problem. I try rebuild apache with "worker MPM". I think it's will work quite good, but... without any warning all memory was filled out and I now waiting for admin to restart server...

tillo
02-18-2010, 03:43 AM
Yeah, in fact in your conf I see that you run 256 handlers per user, and each master process uses up to 128MB of memory for APC.

Now, on my system, after a while every PHP handler uses up to 20MB of memory for my busiest user.
If you take this into consideration, and say you have 20 users, this makes:
20*128MB + 20*256*20MB = 2'560MB + 102'400MB = 104'960MB = 105GB of RAM needed.
Of course this is the worst case of all, your PHP handlers may use less than 3MB each (as for my idlest user) and you may have less than 5 users, do the math.

Gander
02-18-2010, 04:24 AM
So how I should set that values if I have only 2 GB of RAM?

5*32MB + 5*64*5MB = 160MB + 1'600MB = 1'760MB ~= 1.7GB?

tillo
02-18-2010, 04:54 AM
If you have 5 users, that's right. Take into account that "webapps" is one of them, so you should have 4 customers.

Since you probably use the same server for other things (like MySQL) and you may want to spare some RAM (unless you want to suffer from easy DoS), this may be better:

5*128MB + 5*16*5MB = 640MB + 400MB = 1040MB = ~1GB

As you can see I gave more memory to the APC opcode cache instead of to the PHP handlers; that's because it's better to have a consistent cache and spawning some processes than the opposite.
Additionnally, if none of your customers have more than 16 users at the same time no handler will be respawn anyway.

I feel like explaining a little how the PHP handlers are used by FastCGI.
- when you set PHP_FCGI_CHILDREN to 16, that will be the number of handlers per user instantly spawned
- when you set PHP_FCGI_MAX_REQUESTS to 50000, that will be the number of requests an handler will serve before getting automatically respawn, to avoid memory leaks (that's why I have 20MB on each handler, because I set it to 0: they never respawn)
- when the requests are more than PHP_FCGI_CHILDREN, a multiple of that is spawned automatically to avoid denial of service, and they will last until they are being used (if at a given moment 17 users are querying a user's website, for a little while you will have 16 more handlers for that user; in my tests, a new APC memory segment will be used for them!)

Gander
02-18-2010, 06:53 AM
Ok, I am understand part of this black magick... ;)

I have discovered that I have only 1 GB of RAM... So, I run htop (top) to check how many RAM is used.

On previous settings I had 750 MB used (when apache is stopped: 215MB)

I was change my settings to this values:

apc.shm_size = 64

PHP_FCGI_CHILDREN=16

<IfModule mpm_worker_module>
StartServers 1
ServerLimit 1
MaxClients 32
MinSpareThreads 16
MaxSpareThreads 32
ThreadsPerChild 16
MaxRequestsPerChild 0
</IfModule>

Now I have 378 MB used (about 30% of RAM).

Hmmm... My VPS have only a few small e-shops and websites, and I don't need super-performance, but I don't want a small DoS again...

How I should set it up, to gave a similar to default for DA peformance (RAM using)?

tillo
02-18-2010, 07:03 AM
Well, the equivalent to DA default settings is CHILDREN=1, MAX_REQUESTS=1 and shm_size=0. But then, why would you want to use FastCGI?

I guess what you are trying to say is that you would like to know a minimal useful setting for a small system like yours, with not many users nor requests.

There it is: CHILDREN=4, MAX_REQUESTS=5000, shm_size=32.
For 5 users, this makes use of max 160MB for opcode cache and max ~100MB for all persistent handlers together, so a 260MB maximum RAM use by PHP. Less than that, FastCGI isn't really worth it.

Magician
02-21-2010, 10:55 AM
Hi tillo, thank you for sharing your knowledge. Its very, VERY helpfull.

Base on that i finally run on my vps DA php + suexec + fastcgi. Unfortunelly i have not enought memory to handle all user by fastcgi.

I wonder if it possible to handle only selected user by fastcgi (and use op-cache for him/them) and other non-exacting users by suphp.

If it possible can you give me some clue how to do it?

tillo
02-22-2010, 01:40 AM
It surely is possible, but I never did it.

You may try it like that:
- de-comment the line that loads the suPHP module within httpd-phpmodules.conf.
- move the "Action application/x-httpd-php5 /fcgi5" line from httpd-fcgi.conf into the correct VirtualHost within /usr/local/directadmin/data/users/<user>/httpd.conf.

This won't deactivate APC for the users running suPHP, so keep in mind that PHP may be slightly slower (the opcode cache won't be useful, but it will be created at each request anyway).

nmb
03-18-2010, 09:52 PM
tillo,

I got a question about your instruction here -> http://www.directadmin.com/forum/showpost.php?p=124878&postcount=450

I would like to know if I can use mod_fcgid ( http://httpd.apache.org/mod_fcgid/ ) instead of mod_fastcgi and do everything else according to your instruction?

From what I've read from many place, mod_fcgid is a better version of mod_fastcgi. So, I would like to go for a better one.


Thank you,

nmb
03-19-2010, 01:17 AM
Nevermind, I found an article in Thai here -> http://www.icez.net/blog/389/directadmin-mod_fcgid-php-fastcgi

It shows steps how to do it in mod_fcgi which is what I need. Already tried that and it works without any problem :)
________
ROB SMEDLEY (http://www.ferrari-wiki.com/wiki/Rob_Smedley)

interfasys
01-03-2011, 01:04 PM
I would not use mod_fcgid if I were you. It's not compatible with PHP-FPM which is the future of PHP/FastCGI.

nmb
01-03-2011, 07:13 PM
I would not use mod_fcgid if I were you. It's not compatible with PHP-FPM which is the future of PHP/FastCGI.

Never heard of PHP-FPM until today :D Anyway, how to use it? just compile PHP-FPM with PHP 5.3 and then, with FastCGI, it will be used automatically?

Also, just found this -> http://bugs.php.net/52569 that said



We are currently implementing PHP-FPM in a shared hosting environment. We have many users on one server (about 200) and we have to define one pool for each customer (each with a different uid).
If PHP-FPM starts one children per customer at startup, this would kill the servers, I think.
So we have to start them on demand. When using PHP via mod_fcgid/suEXEC you can define FcgidMinProcessesPerClass 0, which works fine, but in PHP-FPM this is not allowed.

I tried to remove the check in fpm_conf.c:
if (config->pm_min_spare_servers <= 0)
if (config->pm_start_servers <= 0)

but this does not really work (zero children are created at startup which is fine, but no child is created on request and the request hangs). I currently don't find the right entry point.


So, I might need to wait for them to fix this before try it :(
________
Lovely Wendie99 (http://www.lovelywendie99.com/)

interfasys
01-03-2011, 08:59 PM
Hmmm...Just lost my long reply in a BSOD ;(
Will try again later...
Short answer is that it's easy to setup, but there are little gains compared to all the hype out there regarding the benefits of FastCGI, unless you're on NGINX...
One positive thing would be the fact that you can use one pool per user, but as you've mentioned, it can lead to problems.
Another is that you can offer custom PHP version to customers that need one (and are willing to pay for it).

nmb
01-04-2011, 06:54 PM
Hmmm...Just lost my long reply in a BSOD ;(
Will try again later...
Short answer is that it's easy to setup, but there are little gains compared to all the hype out there regarding the benefits of FastCGI, unless you're on NGINX...
One positive thing would be the fact that you can use one pool per user, but as you've mentioned, it can lead to problems.
Another is that you can offer custom PHP version to customers that need one (and are willing to pay for it).

Thanks for information. I will have to try that soon. In fact, I have one server that has only one website installed. (Quite a busy server though.) Anyway, I have plan to buy a better server to replace it. Will try that before I move it :)
________
FIX PS3 (http://fixps3.info/)

interfasys
01-04-2011, 07:30 PM
After having done some more testing, I don't find it as reliable as mod_php, but it could be due to my config/test or the different caching systems that are in place. I get half broken pages sometimes.
Don't forget to move back to mod_fastcgi if you want to use PHP-FPM.

nmb
01-06-2011, 05:09 AM
After having done some more testing, I don't find it as reliable as mod_php, but it could be due to my config/test or the different caching systems that are in place. I get half broken pages sometimes.
Don't forget to move back to mod_fastcgi if you want to use PHP-FPM.

I believe mod_php is the best but with limited resources, I choose to go to mod_fcgid / mod_fastcgi anyway :)

Thanks.
________
Creampie videos (http://www.****tube.com/categories/16/creampie/videos/1)

massive
01-07-2011, 03:03 AM
Do you have any documentation regarding mod_fcgid or have you installed it?

nmb
01-08-2011, 03:51 AM
Do you have any documentation regarding mod_fcgid or have you installed it?

Well, mod_fcgid installation I found is in Thai here -> http://www.icez.net/blog/389/directadmin-mod_fcgid-php-fastcgi

But in case you can't read Thai, you can try to follow instruction here -> http://www.bxtra.net/articles/2011-01-05/how-to-directadmin-with-modfcgid

Both of them are pretty much the same. Except one main thing, the one on Bxtra is telling you to use custom folder for "vhost" files which will help you not to do it again if you need to use Custombuild to compile a newer version of Apache.
________
Suzuki tl1000r (http://www.suzuki-tech.com/wiki/Suzuki_TL1000R)