I asked how to have FastCGI without suPHP
here to run XCache, but do I need to set custombuild to install php5 as CGI or CLI? And how can I compile FastCGI with apache2 through custombuild?
Since noone ever answered to my questions, I did it by myself, and this is what I have done for everyone who may consider using the same configuration.
1) run custombuild to install Apache 2.x with ./build apache (no ./build clean afterwards, we will need the Apache source later!)
2) run custombuild to install PHP4 CGI and PHP5 CGI (or just PHP5 CGI, your choice) with ./build php
3) download, compile and install FastCGI's mod_fastcgi as described here:
http://www.fastcgi.com/mod_fastcgi/INSTALL.AP2
Of course top_dir is "/etc/httpd".
We will see later where to load the mod_fastcgi module.
4) download, compile and install XCache as described here:
http://xcache.lighttpd.net/wiki/BuildingFromSource
Make sure to note the PATH of xcache.so when doing make install.
The xcache.ini file must be appended to /usr/local/etc/php5/cgi/php.ini (and /usr/local/etc/php4/cgi/php.ini if you want XCache there, not tested) and configured correctly.
5) modify /etc/httpd/conf/httpd.conf
Where there is:
Code:
LoadModule suphp_module /usr/lib/apache/mod_suphp.so
change with:
Code:
#LoadModule suphp_module /usr/lib/apache/mod_suphp.so
LoadModule fastcgi_module /usr/lib/apache/mod_fastcgi.so
Where there is:
Code:
#EnableSendfile off
#######################################################################################
# Do not change anything in included files, because they are rewritten by DirectAdmin #
change with:
Code:
#EnableSendfile off
#All FastCGI directives
Include conf/extra/httpd-fcgi.conf
#######################################################################################
# Do not change anything in included files, because they are rewritten by DirectAdmin #
6) create /etc/httpd/conf/extra/httpd-fcgi.conf
Content:
Code:
<IfModule mod_fastcgi.c>
ScriptAlias /fcgi4 /opt/fcgi/php4.fcgi
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 -singleThreshold 100 -killInterval 300 -autoUpdate -idle-timeout 240 -pass-header HTTP_AUTHORIZATION
AddType application/x-httpd-php4 .php4
AddType application/x-httpd-php5 .inc .php .cphp .phtml .php5
Action application/x-httpd-php4 /fcgi4
Action application/x-httpd-php5 /fcgi5
</IfModule>
Of course you can void all "php4" lines if you didn't install it.
7) create /opt/fcgi and put those files in there (then run chmod +x on them)
/opt/fcgi/php4.fcgi
Code:
#!/bin/sh
PHPRC="~"
export PHPRC
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=50000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php4/bin/php
/opt/fcgi/php5.fcgi
Code:
#!/bin/sh
PHPRC="~"
export PHPRC
PHP_FCGI_CHILDREN=8
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=50000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php5/bin/php-cgi
Please notice that PHP4 'fcgi' binary doesn't have a leading "-cgi". Of course you don't need the first file if you want just PHP5.
8) create a modded/unsecured suexec binary in the same directory!!!
This step is required because the phpX.fcgi scripts won't have the correct owner/group when calling the pages. For more informations read this:
http://www.fastcgi.com/archives/fastcgi-developers/2005-October/003939.html
My patch is not half as good as his patch, but I can't find anywhere his patch.
EDIT: found it... it's exactly the same one
then I found a third patch, still the same... I'm still looking for someone with a more secure way instead of this dirty and unsecure workaround.
Anyway here is how to create the new suexec binary: go to the custombuild directory, then into the httpd-version sources, and into the "support" directory.
Edit suexec.c and comment out lines 566-576. Result:
Code:
/* if ((uid != dir_info.st_uid) ||
(gid != dir_info.st_gid) ||
(uid != prg_info.st_uid) ||
(gid != prg_info.st_gid)) {
log_err("target uid/gid (%ld/%ld) mismatch "
"with directory (%ld/%ld) or program (%ld/%ld)\n",
uid, gid,
dir_info.st_uid, dir_info.st_gid,
prg_info.st_uid, prg_info.st_gid);
exit(120);
}
*/
Now run 'make suexec', then copy the suexec binary to /opt/fcgi/suexec
Make the owner 'root' and chmod it +s (we need it SUID).
9) almost finished, we just need to patch an obviously forgotten IfModule from DirectAdmin's VirtualHosts files
Enter /usr/local/directadmin/data/templates/, copy virtual_host2.conf, virtual_host2_secure.conf, virtual_host2_secure_sub.conf, and virtual_host2_sub.conf to the "custom" directory, then modify all of them from this:
Code:
|*if SUPHP="1"|
suPHP_Engine |PHP|
suPHP_UserGroup |USER| |GROUP|
|*endif|
to this:
Code:
|*if SUPHP="1"|
<IfModule mod_suphp.c>
suPHP_Engine |PHP|
suPHP_UserGroup |USER| |GROUP|
</IfModule>
|*endif|
Then run this as root: echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
Done! You have a running FastCGI+XCache+PHP[45] system!
WARNING:
Save your /etc/httpd/conf/httpd.conf somewhere, just in case: it's the only file custombuild and DirectAdmin should rewrite when updating/upgrading.
If you encounter any problem, just switch the two "LoadModule" lines in the same file, and you will return to a normal CGI/FastCGI+suPHP+PHP[45] system!