====== PHP via FastCGI under Arch Linux ======
The Apache web server can be run in two modes: prefork and threaded. Threaded is far more efficient from a memory standpoint, however, PHP is not generally threadsafe and therefore canot easily be used with threaded Apache with mod_php. Using a wrapper like FastCGI allows easy use of PHP with threaded Apache. Here is how to configure it in Arch Linux.
First, install PHP, Apache, and FastCGI.
# pacman -S apache php-cgi mod_fcgid
FastCGI needs a wrapper or else suexec will get angry, so create one in ''/srv/http'':
# mkdir /srv/http/fcgi-bin.d/php5-default
# ln -s /usr/bin/php-cgi /srv/http/fcgi-bin.d/php5-default/php-fcgi-wrapper
Create the FastCGI Apache configuration file ''/etc/httpd/conf/extra/php5-fcgid.conf'' with the following content:
# Path to php.ini – defaults to /etc/phpX/cgi
DefaultInitEnv PHPRC=/etc/php
# Number of PHP childs that will be launched. Leave undefined to let PHP decide.
#DefaultInitEnv PHP_FCGI_CHILDREN 3
# Maximum requests before a process is stopped and a new one is launched
#DefaultInitEnv PHP_FCGI_MAX_REQUESTS 5000
# Define a new handler "php-fcgi" for ".php" files, plus the action that must follow
AddHandler php-fcgi .php
Action php-fcgi /fcgi-bin/php-fcgi-wrapper
# Define the MIME-Type for ".php" files
AddType application/x-httpd-php .php
# Define alias "/fcgi-bin/". The action above is using this value, which means that
# you could run another "php5-cgi" command by just changing this alias
Alias /fcgi-bin/ /srv/http/fcgi-bin.d/php5-default/
# Turn on the fcgid-script handler for all files within the alias "/fcgi-bin/"
SetHandler fcgid-script
Options +ExecCGI
Now, add the necessary information to ''/etc/httpd/conf/httpd.conf'' to load FastCGI:
LoadModule fcgid_module modules/mod_fcgid.so
Include conf/extra/php5_fcgid.conf
Finally, restart apache:
# rc.d restart httpd
===== Links =====
* [[http://www.fastcgi.com/|FastCGI]]
* [[http://httpd.apache.org/mod_fcgid/|Apache mod_fcgid]]
* [[http://typo3.org/documentation/article/using-php-with-mod-fcgid/|Using PHP with mod_fcgid (typo3.org)]]