How to install mod_fcgid on DirectAdmin

Tags: 

Linux

From How to choosing PHP module for Apache so I decided to use mod_fcgid on my DirectAdmin private hosting. This is how to

  • Install DirectAdmin on your server. I suggest to use this how to on fresh DirectAdmin without any users. But if you want to install on DirectAdmin that have users, you must create and setting file and folder for users manually.
  • I used Debian 6 64-bit but I think you can adapt my how to to install on CentOS and Redhat
  • Run these command
1
2
3
4
5
6
7
cd /usr/local/src
wget http://mirrors.issp.co.th/apache/httpd/mod_fcgid/mod_fcgid-2.3.7.tar.gz
tar xvfz mod_fcgid-2.3.7.tar.gz
cd mod_fcgid-2.3.7
APXS=/usr/sbin/apxs ./configure.apxs && make && make install
mkdir /var/lib/httpd && chmod 755 -R /var/lib/httpd
mkdir /fcgi

line 1-5 to install mod_fcgid
line 6-7 to prepare some necessary directories for mod_fcgid

  • Edit /usr/local/directadmin/custombuild/options.conf by only edit these values, leave the rest.
php4_cli=no
php4_cgi=no
php5_cli=no
php5_cgi=yes
  • Compile PHP with command
cd /usr/local/directadmin/custombuild/
./build php d
  • Edit /etc/httpd/conf/extra/httpd-suphp.conf by add these lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
  FcgidInitialEnv RAILS_ENV production
  MaxRequestLen 15728640
#  FcgidInitialEnv PHP_FCGI_CHILDREN 4
#  MaxRequestsPerProcess 500
</IfModule>

line 2 is socket file path of mod_fcgid that we created on first step
line 5-12 are value of mod_fcgid. you can edit these later to match your need.

  • Custom Virtual Host Apache DirectAdmin by run these command
cd /usr/local/directadmin/data/templates
mkdir custom
cp virtual_host2*.conf custom
cd custom
  • edit these files virtual_host2.conf, virtual_host2_secure.conf, virtual_host2_secure_sub.conf, virtual_host2_sub.conf in /usr/local/directadmin/data/templates/custom/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<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>
|*if CLI="1"|
#               php_admin_flag engine |PHP|
#               <IfModule !mod_php6.c>
#                       php_admin_flag safe_mode |SAFE_MODE|
#               </IfModule>
#               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|

line 1-14 are adding configuration
line 15-28 are edit current configuration by adding comment (#) at the front of line

  • Create script at /usr/local/directadmin/scripts/custom/fcgid.sh
#!/bin/sh
export PHP_FCGI_MAX_REQUESTS=0
exec /usr/local/php5/bin/php-cgi
  • Create another script /usr/local/directadmin/scripts/custom/domain_create_post.sh
#!/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
  • Copy php.ini to /usr/local/directadmin/scripts/custom/ with this command
cp /usr/local/etc/php5/cgi/php.ini /usr/local/directadmin/scripts/custom/
  • Edit /usr/local/directadmin/scripts/custom/php.ini that we just copied and find for value open_basedir and change to
open_basedir = PHPCFG_BASEDIR:/tmp:/var/tmp
  • Run this command
chmod a+x /usr/local/directadmin/scripts/custom/*.sh

I'll explain about how is mod_fcgid working and how to manually setting mod_fcgid for users that already created before we install mod_fcgid in next article (if possible)

Thanks to