HOBALL 筆記簿

February 15, 2010

Running suPHP(System-wise) and FastCGI(user-specific) concurrently under cPanel/Apache2

Filed under: Linux — Tags: , , , — hoball @ 12:22 am

Step 1:
Compile PHP using EasyApache3, enables suPHP and FastCGI option

Step 2:
Go to “Apache Config”—>”PHP and SuExec Configuration”
Selects “suphp”, Save

Step 3:
Go to “Apache Config”—>”PHP and SuExec Configuration”
Selects “fcgi”, Save

Step 4:
make a copy of /usr/local/cpanel/cgi-sys/php5
cp /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5-bk

Step 5:
Switch back to suPHP [Repet Step 2]

Step 6:
rename “php-bk” to “php5″
mv /usr/local/cpanel/cgi-sys/php5-bk /usr/local/cpanel/cgi-sys/php5

Step 7:
Go to “Apache Config”–>”Include Editor”–>”Pre-VirtualHost file”
Append:
# Fastcgi configuration for PHP5 ( suPHP is active )
LoadModule fcgid_module modules/mod_fcgid.so

<IfModule mod_fcgid.c>
MaxRequestsPerProcess 10000000
</IfModule>

<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from [Your IP]
</Location>

Save

Step 8:
edit the custom directives file

http://www.cpanel.net/documentation/easyapache/customdirectives.html

/usr/local/apache/conf/userdata/std/2/[username]/[x].conf
# Config Fast CGI

<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
</IfModule>

!!!OR!!!
<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
FCGIWrapper /home/[username]/php-fcgi-wrapper .php
</IfModule>
Save

Step 9:
Create a wrapper script
touch /home/[username]/php-fcgi-wrapper
Edit
#!/bin/sh

# Both are the same.
exec /usr/local/cpanel/cgi-sys/php5
#exec /usr/bin/php-cgi
Save

chmod 755 /home/[username]/php-fcgi-wrapper

Step 10:
Verify and rebuild httpd.conf
/scripts/verify_vhost_includes
/scripts/ensure_vhost_includes –user=[user]

Step 10:
Open http://%5Byour domain in action]/server-info
Use top / ps aux / pstree -Aaup to check

suPHP will execute PHP by calling the ‘php’ under httpd child processes
If succeed,  FastCGI will execute PHP by calling ’suexec’ under httpd child process

Step 11:
If succeed,
Go to “Apache Config”–>”Include Editor”–>”Pre-VirtualHost file”
Remove
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from [Your IP]
</Location>

References:

http://forums.cpanel.net/f5/fastcgi-fcgid-php-ini-per-user-100133.html

http://www.morph3ous.net/2006/08/03/suexec-php-514-fastcgi-and-cpanel/

http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-ubuntu-8.10

http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html

http://wherethebitsroam.com/blogs/jeffw/apache-php-fastcgi-and-phpfcgichildren

http://ivan.gudangbaca.com/installing_apache2_and_php5_using_mod_fcgid

Apache mod_info helped me a lot:

http://httpd.apache.org/docs/2.2/mod/mod_info.html

http://serverfault.com/questions/42539/display-apache-configuration

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: