DirectAdmin with mod_fcgid
Posted by adminSep 12
All steps below should be done with a new clean install of DirectAdmin. It is possible to make it work on the server that already have users on it. I did that and it works perfectly fine. However, the steps will be a bit different and it won’t work if you just follow instruction below.
1. Copy and paste below command into your SSH
cd /usr/local/src
wget http://mirrors.issp.co.th/apache/httpd/mod_fcgid/mod_fcgid-2.3.5.tar.bz2
tar jxf mod_fcgid-2.3.5.tar.bz2
cd mod_fcgid-2.3.5
APXS=/usr/sbin/apxs ./configure.apxs && make && make install
chmod 755 -R /var/lib/httpd
mkdir /fcgi
2. modify option file and recompile PHP.
cd /usr/local/directadmin/custombuild/
nano -w options.conf
Modify php5_cgi=yes. All else about PHP is set to no. Then, recompile PHP.
./build php n
3. Modify Apache to load mod_fcgid
3.1 Modify httpd-info.conf as below :
nano -w /etc/httpd/conf/extra/httpd-info.conf
Add below text into the file httpd-info.conf
<IfModule mod_fcgid.c>
FcgidIdleTimeout 3600
FcgidProcessLifeTime 7200
FcgidMaxProcesses 128
FcgidMaxProcessesPerClass 4
FcgidConnectTimeout 60
FcgidIOTimeout 90
FcgidInitialEnv RAILS_ENV production
# FcgidInitialEnv PHP_FCGI_CHILDREN 4
# MaxRequestsPerProcess 500<
</IfModule><Directory “/home”>
AllowOverride All
Options SymLinksIfOwnerMatch
Order allow,deny
Allow from all
<IfModule sapi_apache2.c>
php_admin_flag engine off
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine off
</IfModule>
</Directory>
3.2 Goes into “/usr/local/directadmin/data/templates”. Create custom folder. Modify virtual_host2*.conf ( 4 Files : virtual_host2.conf / virtual_host2_secure.conf / virtual_host2_secure_sub.conf / virtual_host2_sub.conf )
cd /usr/local/directadmin/data/templates
mkdir custom
cp virtual_host2*.conf custom
cd custom
Comment out each virtual_host2* files about PHP as below :
|*if CLI=”1″|
# php_admin_flag engine |PHP|
#
# php_admin_flag safe_mode |SAFE_MODE|
#
# php_admin_value sendmail_path ‘/usr/sbin/sendmail -t -i -f |USER|@|DOMAIN|’
|*endif|
|*if OPEN_BASEDIR=”ON”|
# php_admin_value open_basedir |OPEN_BASEDIR_PATH|
|*endif|
|*if SUPHP=”1″|
# suPHP_Engine |PHP|
# suPHP_UserGroup |USER| |GROUP|
|*endif|
Then, insert below text into above of the text in previous steps:
<IfModule mod_fcgid.c>
<Files ~ (\.fcgi)>
SetHandler fcgid-script
Options +FollowSymLinks +ExecCGI
</Files>
</IfModule>
<IfModule mod_fcgid.c>
<Files ~ (\.php)>
SetHandler fcgid-script
FCGIWrapper “/fcgi/|USER|/public_html/fcgid.sh” .php
Options +ExecCGI
allow from all
</Files>
</IfModule>
4. Create fcgid.sh script
cd /usr/local/directadmin/scripts/custom/
nano -w fcgid.sh
Paste below text into fcgid.sh and then, save it.
#!/bin/sh
export PHP_FCGI_MAX_REQUESTS=0
exec /usr/local/php5/bin/php-cgi
Also create file “domain_create_post.sh” in the same folder and copy text below into the file
#!/bin/sh
mkdir -p /fcgi/${username}/public_html
cp /usr/local/directadmin/scripts/custom/fcgid.sh /fcgi/${username}/public_html/fcgid.sh && chmod 0700 /fcgi/${username}/public_html/fcgid.sh
cp /usr/local/directadmin/scripts/custom/php.ini /fcgi/${username}/public_html/php.ini
perl -pi -w -e “s/PHPCFG_BASEDIR/\/home\/${username}\//g;” /fcgi/${username}/public_html/php.ini
chown -R ${username}:${username} /fcgi/${username}
echo “`date` ${domain} created ” >> /var/log/directadmin/domain_create.log
5. Copy php.ini files to ” /usr/local/directadmin/scripts/custom/ “
Edit ” /usr/local/directadmin/scripts/custom/php.ini ” that we just copied. Search for ” open_basedir ” that is normally comment out. Just uncomment it and have that line like below :
open_basedir = PHPCFG_BASEDIR:/tmp:/var/tmp
6. Run command below :
chmod a+x /usr/local/directadmin/scripts/custom/*.sh
Note 1 : I have tried mod_fcgid 2.3.6 which is the latest version as of today but I ran into the problem that mod_fcgid doesn’t obey ” FcgidMaxProcessesPerClass” variable. If you set it to 4, PHP processes for each user should not run more than 4. It works fine with mod_fcgid 2.3.4 / 2.3.5 but not with 2.3.6. I’m sure there is something that I need to set to make it work but I have no idea what is it. So, I have to stick with mod_fcid 2.3.5 for now.
Note 2 : When there is an update for Apache / PHP, you don’t have to worry if it will break your sites. You can run ” ./build update_versions ” without any problem.
Tested with below software :
CentOS 5.4 / 5.5 – 64 bits
DirectAdmin 1.362 – With Custombuild 1.2
Apache 2.2.17 – Worker MPM
PHP 5.2.15 – 5.2.17
mod_fcgid 2.3.4 / 2.3.5
No comments
You must be logged in to post a comment.