How To Set Up Apache2 With mod_fcgid And PHP5 On Ubuntu 9.10 - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Wed, 2010-01-13 18:54. ::

4 Testing

Now we create a small PHP test file, for example in the www.example1.com web site...

vi /var/www/web1/web/info.php

<?php
phpinfo();
?>

... and call that file in a browser (http://www.example1.com/info.php). If all goes well, the output should look similar to this, and you should see CGI/FastCGI in the Server API line:

 

5 Custom php.ini for Each Web Site

Because each web site has its own php-fcgi-starter wrapper script, it is possible to define different php.ini files for different web sites. To demonstrate this, I will copy the default php.ini (/etc/php5/cgi/php.ini) to the /var/www/web2/ directory and make www.example2.com use the php.ini from the /var/www/web2/ directory:

cp /etc/php5/cgi/php.ini /var/www/web2/
chown web2:web2 /var/www/web2/php.ini

(You can now modify /var/www/web2/php.ini to your likings.)

Then we open /var/www/php-fcgi-scripts/web2/php-fcgi-starter...

vi /var/www/php-fcgi-scripts/web2/php-fcgi-starter

... and put /var/www/web2/ in the PHPRC line:

#!/bin/sh
PHPRC=/var/www/web2/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php

Reload Apache afterwards:

/etc/init.d/apache2 reload

Create a new phpinfo(); file for www.example2.com...

vi /var/www/web2/web/info.php

<?php
phpinfo();
?>

... and call it in a browser (http://www.example2.com/info.php). The Loaded Configuration File line should now show /var/www/web2/php.ini:

 

6 Changing Single PHP Configuration Settings

Instead of passing a whole new php.ini file to your web site, you can as well change single PHP configuration settings in the php-fcgi-starter wrapper script (or use a combination of both) by adding the -d switch to the PHP executable. For example, if I want to disable magic_quotes_gpc for the web site www.example2.com, I'd do it as follows:

vi /var/www/php-fcgi-scripts/web2/php-fcgi-starter

#!/bin/sh
PHPRC=/etc/php5/cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php -d magic_quotes_gpc=off

Reload Apache afterwards:

/etc/init.d/apache2 reload

Then call the info.php script again in a browser (http://www.example2.com/info.php) and search for the magic_quotes_gpc line - it should show Off now:

 

7 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Sergio Flores (not registered) on Sat, 2010-01-16 00:55.

Según la documentación oficial de mod_fcgid:

Special PHP considerations

By default, PHP FastCGI processes exit after handling 500 requests, and they may exit after this module has already connected to the application and sent the next request. When that occurs, an error will be logged and 500 Internal Server Error will be returned to the client. This PHP behavior can be disabled by setting PHP_FCGI_MAX_REQUESTS to 0, but that can be a problem if the PHP application leaks resources. Alternatively, PHP_FCGI_MAX_REQUESTS can be set to a much higher value than the default to reduce the frequency of this problem. FcgidMaxRequestsPerProcess can be set to a value less than or equal to PHP_FCGI_MAX_REQUESTS to resolve the problem.

PHP child process management (PHP_FCGI_CHILDREN) should always be disabled with mod_fcgid, which will only route requests to application processes it has spawned. Any child processes created by PHP will be unused and may not be terminated properly. By default, and with the environment variable setting PHP_FCGI_CHILDREN=0, PHP child process management is disabled.

Extraido desde: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html