Debian 4.0 etch is the new stable distribution. Noteably, Debian has switched to version 2.2 of apache2. The following walkthrough shows how to setup php running inside the fastcgi apache2 module on this new Debian release.
This walkthrough is based on
http://www.howtoforge.com/forums/showthread.php?t=4606 with the following exceptions:
- use Debian PHP5 or PHP4 pre-compiled binary
- does not require support for the imuteable bit
- uses apache 2.2
- and Debian 4.0 etch
Refer to the original instructions where this walkthrough does not make sense.
For simplicity's sake, this is all done as root. Usually, Debian people recommend using a normal unprivileged account for compiling things and getting package sources.
- Install apache2.2 and download sources
Code:
apt-get install apache2.2-common apache2-threaded-dev apache2-mpm-worker
mkdir /root/install
cd /root/install
apt-get source apache2.2-common
cd apache2-2.2.3/
debian/rules
./configure
The last step will set the configuration options to the Debian defaults.
Code:
cd support
vi suexec.c
Change accordingly, Line 567 (first and last line of this snippet).
Code:
/* no file owner check
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);
}
*/
- Compile and "install" suexec
Code:
make suexec
mkdir -p /usr/local/lib/apache2/
cp suexec /usr/local/lib/apache2/suexec-fcgi
chown root.root /usr/local/lib/apache2/suexec-fcgi
chmod 4755 /usr/local/lib/apache2/suexec-fcgi
Checking the permissions on the file should look like this
Code:
stat /usr/local/lib/apache2/suexec-fcgi
File: `/usr/local/lib/apache2/suexec-fcgi'
Size: 24675 Blocks: 56 IO Block: 131072 regular file
Device: 803h/2051d Inode: 73997 Links: 1
Access: (4755/-rwsr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2007-04-24 07:24:21.000000000 +0100
Modify: 2007-04-20 13:30:09.000000000 +0100
Change: 2007-04-23 14:09:09.000000000 +0100
- Install libapache2-mod-fastcgi
The libapache2-mod-fastcgi package is in the non-free section of the Debian repositories. If it's not there yet change your entry in /etc/apt/sources.list from
Code:
deb http://ftp.uk.debian.org/debian/ stable main
to
Code:
deb http://ftp.uk.debian.org/debian/ stable main non-free contrib
Contrib can be useful too sometimes.
Then install fastcgi
Code:
apt-get install libapache2-mod-fastcgi
And configure apache to use it
Now to the configuration of mod_fastcgi. The following allows us to keep the php-fastcgi-starter outside of what the user can access or modify.
Code:
# /etc/apache2/mods-enabled/fastcgi.conf
<IfModule mod_fastcgi.c>
#AddHandler fastcgi-script .fcgi
#FastCgiWrapper /usr/lib/apache2/suexec2
#FastCgiIpcDir /var/lib/apache2/fastcgi
#temporary sockets are stored here, this must be at the top!
FastCgiIpcDir /var/lib/apache2/fastcgi
#config
FastCgiConfig -pass-header Authorization
FastCgiWrapper /usr/local/lib/apache2/suexec-fcgi
#php
AddHandler php-fastcgi .php .php3 .php4 .php5 .phtml .phps
<Location /php-fastcgi/php-fcgi-starter>
SetHandler fastcgi-script
Options +ExecCGI
</Location>
Action php-fastcgi /php-fastcgi/php-fcgi-starter
#perl
#TODO
##ISPConfig add this by the installtion of it
##ISPConfig INSTALL## AddType ##ISPConfig INSTALL## application/x-httpd-php .php
<Directory "/var/www/">
AllowOverride None
Options +ExecCGI -MultiViews -Indexes
Order allow,deny
Allow from all
</Directory>
</IfModule>
Using the PHP from Debian packages makes is easier to maintain and upgrade the system. To install use
Code:
apt-get install php4-cgi php5-cgi php4-mysql php5-mysql
Edit the default configuration files and enable safe_mode and set open_basedir to /var/www. More importantly, add this to both files (/etc/php4/cgi/php.ini and /etc/php5/cgi/php.ini)
(Note: I am not sure this is necessary)
Create the php-fastcgi starter script
(at this point worth mentioning that ISPConfig should already be installed)
Code:
/root/ispconfig/scripts/php-fcgi-starter
#!/bin/sh
PHPRC="/etc/php5/cgi/"
export PHPRC
PHP_FCGI_CHILDREN=3
export PHP_FCGI_CHILDREN
exec /usr/bin/php5-cgi
and
Code:
chown root.root /root/ispconfig/scripts/php-fcgi-starter
chmod 0755 /root/ispconfig/scripts/php-fcgi-starter
Now patch ISPConfig to use php-fastcgi instead of the php module and create the starter in the right place. This patch also changes the default permissions of new web sites to 750 and adds www-data to every group created by ISPConfig.
Apply this patch to
/root/ispconfig/scripts/lib/config.lib.php
Code:
1119c1119
1119c1119
<
---
>
1120a1121,1123
> //mimo http://www.howtoforge.org/forums/showthread.php?t=4375
> // add www user to each new group
> $mod->system->add_user_to_group("web".$doc_id,$apache_user);
1127a1131,1135
>
> //mimo 2nd part
> exec("chmod 750 $web_path");
> exec("chmod 750 $web_path_realname");
>
1385a1394,1405
> //FASTCGI (here we could add a handler for different versions of php and php.ini files
> //FASTCGI Modification
> #$fcgip = $mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"];
> $fcgip = $mod->system->server_conf["server_path_httpd_root"]."/php-fastcgi/"."web".$web["doc_id"];
> if(!file_exists($fcgip."/php-fcgi-starter")) {
> $mod->log->msg("creating $fcgip"."/php-fcgi-starter");
> if(!file_exists($fcgip)) {
> exec("mkdir -p $fcgip");
> }
> exec("cp -p /root/ispconfig/scripts/php-fcgi-starter ".$fcgip."/ && chown root:root ".$fcgip."/php-fcgi-starter");
> }
>
1387c1407,1410
< $php = "AddType application/x-httpd-php .php .php3 .php4 .php5";
---
> // FASTCGI
> //$php = "AddType application/x-httpd-php .php .php3 .php4 .php5";
> #$php = "ScriptAlias /php-fastcgi/ ".$mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"]."/\n";
> $php = "ScriptAlias /php-fastcgi/ $fcgip\n";
1390a1414,1415
> #$php = "ScriptAlias /php-fastcgi/ ".$mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"]."/\n";
> $php = "ScriptAlias /php-fastcgi/ $fcgip/\n";
1423a1449,1450
> //disbaled FASTCGI
> /*
1432a1460
> */
2513c2541
< ?>
\ No newline at end of file
---
> ?>
1119c1119
<
---
>
1120a1121,1123
> //mimo http://www.howtoforge.org/forums/showthread.php?t=4375
> // add www user to each new group
> $mod->system->add_user_to_group("web".$doc_id,$apache_user);
1127a1131,1135
>
> //mimo 2nd part
> exec("chmod 750 $web_path");
> exec("chmod 750 $web_path_realname");
>
1385a1394,1405
> //FASTCGI (here we could add a handler for different versions of php and php.ini files
> //FASTCGI Modification
> #$fcgip = $mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"];
> $fcgip = $mod->system->server_conf["server_path_httpd_root"]."/php-fastcgi/"."web".$web["doc_id"];
> if(!file_exists($fcgip."/php-fcgi-starter")) {
> $mod->log->msg("creating $fcgip"."/php-fcgi-starter");
> if(!file_exists($fcgip)) {
> exec("mkdir -p $fcgip");
> }
> exec("cp -p /root/ispconfig/scripts/php-fcgi-starter ".$fcgip."/ && chown root:root ".$fcgip."/php-fcgi-starter");
> }
>
1387c1407,1410
< $php = "AddType application/x-httpd-php .php .php3 .php4 .php5";
---
> // FASTCGI
> //$php = "AddType application/x-httpd-php .php .php3 .php4 .php5";
> #$php = "ScriptAlias /php-fastcgi/ ".$mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"]."/\n";
> $php = "ScriptAlias /php-fastcgi/ $fcgip\n";
1390a1414,1415
> #$php = "ScriptAlias /php-fastcgi/ ".$mod->system->server_conf["server_path_httpd_root"]."/"."web".$web["doc_id"]."/\n";
> $php = "ScriptAlias /php-fastcgi/ $fcgip/\n";
1423a1449,1450
> //disbaled FASTCGI
> /*
1432a1460
> */
2513c2541
< ?>
\ No newline at end of file
---
> ?>
Create the base directory for the php-fastcgi starter scripts. The idea is to have a separate one for each web site so that later on it is possible to chose the version and settings of PHP on a per site basis.
Code:
mkdir /var/www/php-fastcgi
chown root.root /var/www/php-fastcgi
- Finally, start or restart apache2. All done!
For new web sites ISPConfig will create this structure
/var/www/--+/webX/ <- normal content, user has full access
/var/www/--+/php-fastcgi/webX/php-fastcgi-starter
Recent comments
9 hours 21 min ago
14 hours 26 min ago
18 hours 51 min ago
20 hours 39 min ago
1 day 10 hours ago
1 day 10 hours ago
1 day 15 hours ago
1 day 22 hours ago
1 day 23 hours ago
2 days 38 min ago