Howtos about fastcgi and php that are used or consulted: http://www.debianhowto.de/de/howtos/sarge/apache2_php-fcgi http://www.syscp.de/wiki/contrib/PHP-FCGI-ger Apache2 Install In the first step you install apache2-mpm-worker Code: apt-get install apache2-common apache2-mpm-worker apache2-threaded-dev restart the apache, but without mod_php. mod_php runs not with apache2-mpm-worker! If you want to use mod_php and fastcgi then you need apache2-mpm-prefork! Code: /etc/init.d/apache2 restart Build Suexec then you load the apache sources to compile a new suexec for fastcgi Code: cd /root apt-get source apache2-common cd apache2-2.0.54 cd upstream cd tarballs tar zxf httpd-2.0.51.tar.gz cd httpd-2.0.54 cd support vi suexec.h edit the follow lines: Code: #define AP_HTTPD_USER "www" with Code: #define AP_HTTPD_USER "www-data" Code: #define AP_LOG_EXEC DEFAULT_EXP_LOGFILEDIR "/suexec_log" /* Need me? */ with Code: #define AP_LOG_EXEC "/var/log/apache2/suexec.log" /* Need me? */ Code: #define AP_DOC_ROOT DEFAULT_EXP_HTDOCSDIR with Code: #define AP_DOC_ROOT "/var/www" edit suexec.c Code: vi suexec.c then insert the red market text into Code: [COLOR="Red"]/* no file owner check[/COLOR] 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); } [COLOR="#ff0000"]*/[/COLOR] You need the apache2-header-files to compile suexec Code: cp -p /usr/include/apache2/* . cp -p /usr/include/apr-0/* . Code: make suexec then you must have: Code: ls -l suexec -rwxr-xr-x 1 root root 20565 Aug 5 23:37 suexec copy the suexec for fcgi to /usr/lib/apache2 Code: cp suexec /usr/lib/apache2/suexec-fcgi chmod 4755 /usr/lib/apache2/suexec-fcgi you can delete the files, that you has downloaded with apt-source Compile PHP (next step you can install by debian packages without compiling) Code: $ cd mkdir php5 cd php5 wget http://de3.php.net/get/php-5.1.4.tar.gz/from/a/mirror tar zxf php-5.1.4.tar.gz cd php-5.1.4.tar.gz ./configure --enable-memory-limit --enable-force-cgi-redirect \ --enable-track-vars --with-pcre-regex --with-mysql --without-sqlite \ --without-mm --enable-fastcgi --prefix=/home/_USER_/php5 make make install Important for php5 compilation and fastcgi: Code: apt-get install libmysqlclient14-dev libxml2-dev ./configure with: –enable-fastcgi –without-mm if any packages missed use Code: apt-cache search "MISSED" apt-get install "THE NEEDED PACKAGE Inofficial Debain Packages for PHP5: Code: echo "deb http://people.debian.org/~dexter php5.1 sarge" >> /etc/apt/sources.list echo "deb-src http://people.debian.org/~dexter php5.1 sarge" >> /etc/apt/sources.list apt-get update apt-get install php5.0 php5.0-common php5.0-fcgi apache2-mpm-worker apt-get install apache2-mpm-worker because debian would like to remove it and install apache2-mpm-prefork again. libapache2-mod-fastgi: you musst edit the "/etc/apt/source.list" and include the non-free sector. It show like that: then Code: apt-get update apt-get install libapache2-mod-fastcgi then you edit the "/etc/apache2/mods-avaible/fastcgi.conf" with you favorit editor Code: vi /etc/apache2/mods-available/fastcgi.conf it musst show like: ------------------------------------------------------------------------- now you must install ispconfig, if you didn't have it or you modify it by own ------------------------------------------------------------------------- fast-cgi start script You need a fast-cgi starter for all web hosts: Code: cd /root/ispconfig/scripts vi php-fcgi-starter my php-fcgi-starter (with apache php5.1-fcgi package): it must have root permissions: Code: chmod 755 php-fcgi-starter chown root:root php-fcgi-starter that the webuser can excute it (by suexec) but can't edit it! ------------------------------------------------------------------------------------------------------- ispconfig copy this to /var/www/web*/ if you activate php for this web, but you must modify ispconfig: ------------------------------------------------------------------------------------------------------- modify ISPConfig you must patch the config.lib.php Code: cd /root/ispconfig/scripts/lib then you must patch config.lib.php with the patch file in the attachemend. Copy the patch file into /root/ispconfig/scripts/lib. Code: patch config.lib.php < fcgi_patch.txt By the first php activate for a web Account, it will be create a .php-fcgi-starter for this user. If you wish to modify php for this user, then you must create a new php.ini for this user or change it for all. And edit the fast-cgi-starter script for this user. php_admin_flag in the apache config didn't run and the php_sage_mod button in ispconfig didn't act after the patch/ with fastcgi! I'm pleased to get feedback and better solutions and I hope that fastcgi find a way into the default installation of ispconfig
I have update the howto, with a better solution. so you can can activate or disable it with the php button.
@tosser 1: Why you build a new suexec binary does'nt it work even whith the usual suexec installation? In that german tutorial http://archiv.debianhowto.de/de/apa...cgi-sarge.html#apache2-phpfcgi_suexec_install it tells the need to build an own suexec binary only if somebody does'nt have a filesysthem whitout the possibility to set the immutable-bit. 2. How are you define the FastCgiServer for different vhosts?
Hi! I build a new suexec, because it is easier to add a new web account in ispconfig. and it make it easier to edit the script as root. but you can also set the immutable-bit in /root/ispconfig/scripts/lib/config.lib.php. then ISPC. set it automatically after copy the php-fcgi-starter into the user folder. all web accounts with php have a .php-fcgi-starter script. there can you set some paramaters for fcgi/php (like a php.ini). in the vhost for this webs ispconfig create a ScriptAlias to the startscript. like this: Code: ScriptAlias /php/ /var/www/web1/ and in the fastcgi config define the php start script with this parameter: Code: Action php-fastcgi /php/.php-fcgi-starter so you start a fcgi-server for the different vhosts. for example: fastcgi start it for web1 in /var/www/web1/.php-fcgi-starter and web2 in /var/www/web2/.php-fcgi-starter
It is great an more secure to use php-fcgi rather than the usual php. That's the reason why I want to use fcgi. I dont realy understand how to use and define the "FastCgiServer" for different vhosts (That's me second question) because php-fcgi is still working without a defined "FastCgiServer"?
The FastCGIServer is php-fcgi. you define it dynamic for all vhosts. with execute php-fcgi in the php-starter-script and not with a static parameter in the fastcgi.conf!
ok, thanks! The diffenrent is between static and dynamic, aha So I had defined a static FastCGIServer and a dynamic one? I created the fastcgi.conf like: Code: <IfModule mod_fastcgi.c> FastCgiIpcDir /var/lib/apache2/fastcgi AddHandler fastcgi-script .fcgi FastCgiWrapper /usr/lib/apache2/suexec2 FastCgiServer /var/www/php-fcgi-scripts/web1/php-fcgi-starter -user web1_admin -group web1 FastCgiServer /var/www/php-fcgi-scripts/web2/php-fcgi-starter -user web2_admin -group web2 AddHandler php-fastcgi .php <Location /cgi-bin/php-fcgi-starter> SetHandler fastcgi-script Options +ExecCGI </Location> Action php-fastcgi /cgi-bin/php-fcgi-starter AddType application/x-httpd-php .php </IfModule> and the starter script like: Code: #!/bin/sh PHPRC="/var/www/php-fcgi-scripts/web1" export PHPRC PHP_FCGI_CHILDREN=4 export PHP_FCGI_CHILDREN exec /var/www/php-fcgi-scripts/php5-fcgi-hard/bin/php and for the vhosts (include in isp httpd.conf options field): Code: ScriptAlias /cgi-bin/ /var/www/php-fcgi-scripts/web1/ <Directory '/var/www/php-fcgi-scripts/web1'> AllowOverride None Options +ExecCGI -MultiViews -Indexes Order allow,deny Allow from all </Directory> You mean this Code: [B] FastCgiServer /var/www/php-fcgi-scripts/web1/php-fcgi-starter -user web1_admin -group web1 FastCgiServer /var/www/php-fcgi-scripts/web2/php-fcgi-starter -user web2_admin -group web2[/B] I have to take off because it's I've already defined the FastCgiServer dynamicly by PHPRC="/var/www/php-fcgi-scripts/web1", right?
No PHPRC define the path to configurations like php.ini FastCgiServer is for an static starter and you can't define two FastCgiServer! for your vhosts with a own start script you need no fastcgiserver paramter in you config. you can define one fastcgiserver but you mustn't du that. please read http://www.fastcgi.com/docs/faq.html#PHP, there are a general howto for fastcgi with php does you use ispconfig for manage your vhosts etc.?
Yes, I no... Yes, I use this entries in the ISPConifg Vhosts: ScriptAlias /cgi-bin/ /var/www/php-fcgi-scripts/web1/ and it works fine. Thanks for the hint of the needless FastCgiServer. I think this entry is ok for get the right permissions for the fcgi-user in the vhosts. It is defined in /etc/apache2/mods-enabled/fastcgi.conf And I think I only need to define it once there and no more in any vhost separate,right?
now sadly outdated Not quite sure why this is but it looks this is outdated now. The current (non-free) libapache2-mod-fastcgi depends on apache2.2-common. This should break the self-compiled suexec-fcgi. I notice that current debian packages of php4/5-cgi are fcgi enabled. Why not use those instead of compiling your own? Has anyone tried mod_fcgid instead of fastcgi? It's looking good (debian package and all that) but I cna't configure it like your example for fastcgi... I'll keep exploring but would appreciate any help!
blame it on debian Just found out that this is because debian have switched stable to etch. I'll try with the newer versions of the packages.
Hi, great tutorial, thx. Unfortunately the patch does not work with the latest ISPC release. I would also suggest to: to prevent any modifies to the file attributes of the file and its content.
Hi, for all those preferring to use FastCgi I want to supply my little tweaked version of this great post (thx Tosser). Also if you've got problems to execute the outdated patch this could help you. The following instructions are only about patching ISPConfig to support FastCgi. I added - support that every Vhost will automatically gets copied his own php.ini file into webroot directory. - new var directory to Vhost that contains sessions and uploaded_tmp files Please note: - use on own risk - only apache2 support (you can easily add apache1) - only FASTCGI-Support (can't be switched) - You've to controll the config.lib.php and make your custom changes (CHOWN: Webserver-User, CHMOD: your rights!) - If you want to regenerate the .php.ini // .php-fcgi-starter // var folder - just delete them and run a vhost change. here we go: 1. open config.lib.php 2. find "if($web["web_php"]){" 3. delete this complete if condition including bracket content { ... } 4. and inner in this exact place this: Code: // FIXED TO SUPPORT FASTCGI if($web["web_php"]){ $php = ''; $php = "ScriptAlias /php/ ".$mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"]."/\n"; $fcgip = $mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"]; // COPY /var/www/webX/.php-fcgi-starter AND fill in right webId $fgiFile = $fcgip."/.php-fcgi-starter"; if(!file_exists($fgiFile)) { exec("cp -p /root/ispconfig/scripts/php-fcgi-starter $fgiFile && chown root:root $fgiFile"); $contentCgiFile = $mod->file->rf($fgiFile); $contentCgiFile = str_replace("{WEB_ID}", "web".$web["doc_id"], $contentCgiFile); $mod->file->wf($fgiFile, $contentCgiFile); } // COPY /etc/php5/ispconfig_fastcgi_default/php.ini TO /var/www/webX/.php.ini AND fill in right webId $phpIniFile = $fcgip."/.php.ini"; if(!file_exists($phpIniFile)) { exec("cp -p /etc/php5/ispconfig_fastcgi_default/php.ini $phpIniFile && chown root:root $phpIniFile"); $contentPhpIniFile = $mod->file->rf($phpIniFile); $contentPhpIniFile = str_replace("{WEB_ID}", "web".$web["doc_id"], $contentPhpIniFile); $mod->file->wf($phpIniFile, $contentPhpIniFile); } if(!is_dir("$fcgip/var/uploads_tmp")) { exec("mkdir -p $fcgip/var/uploads_tmp"); } if(!is_dir("$fcgip/var/sessions")) { exec("mkdir -p $fcgip/var/sessions"); } exec("chown -R webserv:web".$web["doc_id"]." $fcgip/var"); exec("chmod -R 775 $fcgip/var"); // "/var/www/{WEB_ID}/var/uploads_tmp/" // var/www/{WEB_ID}/var/sessions" if($go_info["server"]["apache2_php"] == 'addtype' or $go_info["server"]["apache2_php"] == 'both') { $php .= "AddType application/x-httpd-php .php .php3 .php4 .php5\n"; } } else { $php = ""; } 5. in /root/ispconfig/scripts/ create or replace php-fcgi-starter with chmod 755 (!) this (new) content #!/bin/sh PHPRC="/var/www/{WEB_ID}/.php.ini" export PHPRC PHP_FCGI_CHILDREN=1 export PHP_FCGI_CHILDREN exec /usr/lib/cgi-bin/php5 6. create /etc/php5/ispconfig_fastcgi_default and place in here php.ini with this sample config (if you want) Code: ;;;;;;;;;;;;;;;;;;; PHP INI FOR {WEB_ID} ;;;;;;;;;;;;;;;;;;; error_reporting = E_ALL & ~E_NOTICE display_errors = On display_startup_errors = On log_errors = On log_errors_max_len = 1024 error_log = /var/www/{WEB_ID}/log/phperrors.log ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On register_globals = Off register_long_arrays = On magic_quotes_gpc = Off magic_quotes_runtime = Off default_mimetype = "text/html" default_charset = "utf-8" post_max_size = 50M file_uploads = On upload_tmp_dir = "/var/www/{WEB_ID}/var/uploads_tmp/" upload_max_filesize = 60M max_execution_time = 600 ; Maximum execution time of each script, in seconds (30) max_input_time = 600 ; Maximum amount of time each script may spend parsing request data (60) memory_limit = 60M ; Maximum amount of memory a script may consume (8MB) session.auto_start 0 session.save_path = "/var/www/{WEB_ID}/var/sessions" session.use_cookies = 1 session.name = PHPSESSID_{WEB_ID} session.cookie_lifetime = 0 ;;;;;;;;;;;;;;;;;;; APPENDIX, SELECT IF WANTED ;;;;;;;;;;;;;;;;;;; ;error_log = filename ;error_log = syslog ;date.timezone = ;iconv.input_encoding = "utf-8" ;iconv.internal_encoding = "utf-8" ;iconv.output_encoding = "utf-8" ; NOT WORKING WITH FASTCGI AFAIK ;session.gc_maxlifetime = 5 ;session.gc_probability = 1 ;session.gc_divisor = 1000 ;session.cookie_path = / ;session.cookie_domain = ;session.cache_limiter = nocache ;session.cache_expire = 180 ;safe_mode = Off ;safe_mode_gid = Off ;safe_mode_include_dir = ;safe_mode_exec_dir = ;safe_mode_allowed_env_vars = PHP_ ;safe_mode_protected_env_vars = LD_LIBRARY_PATH ;open_basedir = ;extension=apc.so ;apc.mode = on ;apc.rfc1867 = on ;apc.max_file_size = 128M ;apc.enabled=1 ;apc.shm_segments=1 ;apc.shm_size=128 ;apc.ttl=7200 ;apc.user_ttl=7200 ;apc.num_files_hint=1024 ;apc.mmap_file_mask=/tmp/apc.XXXXXX ;apc.enable_cli=1 Done. Hope it works for you! regards, Melchior