Jan_E
Verified User
HOWTO: mod_fcgid in CB 2.0, switchable to suphp and mod_php
This post will show you how to install mod_fcgid, using custombuild 2.0, and create a setup where the admin can choose for every individual DA-user between mod_php, suphp and mod_fcgid. I am using this on my Centos server with Apache 2.4.3, PHP 5.3 as mod_php and PHP 5.4 as suphp/mod_fcgid. The initial options.conf contains
As first step on a running server we have to build mod_fcgid. Perform these steps as root:
Remarks:
1. The build rewrite_confs will remove the mod_fcgid from the Apache config, but we will need this later on.
2. The operations on /var/lib/httpd prepare the system for the fcgid socket.
Next step: create a handler for mod_fcgid. We will use /etc/httpd/conf/extra/httpd-includes.conf for that. Please mind the fact that this is loaded before httpd-suphp.conf in Custombuild 2.0 and is empty on a clean install. Add this to httpd-includes.conf:
Next step: create a fcgid.sh to start php as fcgid. See the official Apache docs:
http://httpd.apache.org/mod_fcgid/
There are a lot of tutorials on how to create this fcgid.sh. One of the most structured is:
http://woshka.com/blog/apache/compi...i-in-directadmin-installed-control-panel.html
The trick is to create an fcgid.sh for every user that can be loaded from within the Apache config. Most tutorials use this directory:
mkdir -p /fcgi/${username}/public_html
The directory needs to have the user and group of each DA-user:
chown -R ${username}:${username} /fcgi/${username}
I am using this fcgid.sh:
Note that up until now you did not make any real changes to the system. But with a working fcgid.sh you can test your setup now, without interrupting your users (if you forget the restart of Apache). Add this to the Custom HTTPD Configuration of a domain:
Wait for the (hopefully graceful) restart of Apache, while creating three test files with phpinfo() inside:
phpinfo.php
phpinfo.php54
phpinfo.fcgi
With my setup these test files will use the following PHP's:
phpinfo.php - php1_release = PHP 5.3 as mod_php with /usr/local/lib/php.ini
phpinfo.php54 - php2_release = PHP 5.4 as suphp
phpinfo.fcgi - php2_release = PHP 5.4 as mod_fcgid
The difference between suphp and mod_fcgid is hard to tell from the phpinfo, but the clearest indication is the section Environment below Additional Modules, containing variables like:
If these three testfiles run as expected, you can now switch a domain freely from mod_php (5.3) to suphp (5.4) or mod_fcgid (5.4)
MOD_PHP
This is the default mode, without any addition to the Custom HTTPD Configuration.
phpinfo.php will report PHP 5.3 as mod_php (Apache 2.0 Handler)
SUPHP
You can switch a domain to suPHP by adding these lines to the Custom HTTPD Configuration:
The phpinfo.php will report PHP 5.4 as suPHP (check the Environment below Additional modules)
MOD_FCGID
You can switch a domain to mod_fcgid by adding these lines to the Custom HTTPD Configuration
Note the |USER| in the FcgidWrapper. Directadmin will replace that by the actual username.
phpinfo.php will report PHP 5.4 as mod_fcgid (check the Environment below Additional modules).
OK, there you have it. A versatile way to switch userdomains between mod_php, suPHP and mod_fcgid. The setup will (as far as I can see) survive upgrades and rewrite_confs. I did not test it, but there is a chance this will also work with php1_release as php-fpm.
I will discuss custom php.ini's per user and automating the process in separate posts.
This post will show you how to install mod_fcgid, using custombuild 2.0, and create a setup where the admin can choose for every individual DA-user between mod_php, suphp and mod_fcgid. I am using this on my Centos server with Apache 2.4.3, PHP 5.3 as mod_php and PHP 5.4 as suphp/mod_fcgid. The initial options.conf contains
Code:
php1_release=5.3
php2_release=5.4
php1_mode=mod_php
php2_mode=suphp
Code:
cd /usr/local/src
wget http://mirrors.issp.co.th/apache/httpd/mod_fcgid/mod_fcgid-2.3.7.tar.bz2
tar xjf mod_fcgid-2.3.7.tar.bz2
cd mod_fcgid-2.3.7
APXS=/usr/sbin/apxs ./configure.apxs && make && make install
/usr/local/directadmin/custombuild/build rewrite_confs
service httpd status
mkdir -p /var/lib/httpd/sock
chmod 755 -R /var/lib/httpd
1. The build rewrite_confs will remove the mod_fcgid from the Apache config, but we will need this later on.
2. The operations on /var/lib/httpd prepare the system for the fcgid socket.
Next step: create a handler for mod_fcgid. We will use /etc/httpd/conf/extra/httpd-includes.conf for that. Please mind the fact that this is loaded before httpd-suphp.conf in Custombuild 2.0 and is empty on a clean install. Add this to httpd-includes.conf:
Code:
LoadModule fcgid_module /usr/lib/apache/mod_fcgid.so
SharememPath /var/run/fcgid_shm
SocketPath /var/lib/httpd/fcgid/sock
<IfModule mod_fcgid.c>
FcgidIdleTimeout 3600
FcgidProcessLifeTime 7200
FcgidMaxProcesses 128
FcgidMaxProcessesPerClass 4
FcgidConnectTimeout 60
FcgidIOTimeout 90
# moved to fcgid.sh
# FcgidInitialEnv PHP_FCGI_CHILDREN 0
# MaxRequestsPerProcess 0
AddHandler fcgid-script .fcgi
</IfModule>
#.
http://httpd.apache.org/mod_fcgid/
There are a lot of tutorials on how to create this fcgid.sh. One of the most structured is:
http://woshka.com/blog/apache/compi...i-in-directadmin-installed-control-panel.html
The trick is to create an fcgid.sh for every user that can be loaded from within the Apache config. Most tutorials use this directory:
mkdir -p /fcgi/${username}/public_html
The directory needs to have the user and group of each DA-user:
chown -R ${username}:${username} /fcgi/${username}
I am using this fcgid.sh:
Code:
#!/bin/sh
# http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
# Set desired PHP_FCGI_* environment variables.
# Example:
# PHP FastCGI processes exit after 500 requests by default.
# JE: Do not limit it to facilitate XCache (or set it really high, like 10000)
PHP_FCGI_MAX_REQUESTS=0
export PHP_FCGI_MAX_REQUESTS
# See http://www.webhostingtalk.com/archive/index.php/t-1165678.html
PHP_FCGI_CHILDREN=0
export PHP_FCGI_CHILDREN
exec /usr/local/php54/bin/php-cgi54
Code:
<IfModule mod_fcgid.c>
FcgidWrapper /fcgi/|USER|/public_html/fcgid.sh
<FilesMatch "\.fcgi$">
Options +ExecCGI
SetHandler fcgid-script
</FilesMatch>
</IfModule>
phpinfo.php
phpinfo.php54
phpinfo.fcgi
With my setup these test files will use the following PHP's:
phpinfo.php - php1_release = PHP 5.3 as mod_php with /usr/local/lib/php.ini
phpinfo.php54 - php2_release = PHP 5.4 as suphp
phpinfo.fcgi - php2_release = PHP 5.4 as mod_fcgid
The difference between suphp and mod_fcgid is hard to tell from the phpinfo, but the clearest indication is the section Environment below Additional Modules, containing variables like:
Code:
PHP_FCGI_CHILDREN 0
PATH /usr/local/bin:/usr/bin:/bin
PWD /fcgi/username/public_html
SHLVL 0
PHP_FCGI_MAX_REQUESTS 0
MOD_PHP
This is the default mode, without any addition to the Custom HTTPD Configuration.
phpinfo.php will report PHP 5.3 as mod_php (Apache 2.0 Handler)
SUPHP
You can switch a domain to suPHP by adding these lines to the Custom HTTPD Configuration:
Code:
<IfModule mod_suphp.c>
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|phtml|phps)$">
SetHandler x-httpd-php54
</FilesMatch>
</IfModule>
#.
MOD_FCGID
You can switch a domain to mod_fcgid by adding these lines to the Custom HTTPD Configuration
Code:
<IfModule mod_fcgid.c>
FcgidWrapper /fcgi/|USER|/public_html/fcgid.sh
<FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|phtml|phps)$">
Options +ExecCGI
SetHandler fcgid-script
</FilesMatch>
</IfModule>
#.
phpinfo.php will report PHP 5.4 as mod_fcgid (check the Environment below Additional modules).
OK, there you have it. A versatile way to switch userdomains between mod_php, suPHP and mod_fcgid. The setup will (as far as I can see) survive upgrades and rewrite_confs. I did not test it, but there is a chance this will also work with php1_release as php-fpm.
I will discuss custom php.ini's per user and automating the process in separate posts.
Last edited: