DirectAdmin / Switching a direct admin server to suphp server

  • Sunny
  • 4521 Views
  • 0 Comment
  • No tags

You can convert your cli Direct Admin server to suphp server by following below steps.

Step: 01
cd /usr/local/directadmin/custombuild

Step: 02

Open options.conf and make following changes in it
Replace
php5_cli=yes
php5_cgi=no
with
php5_cli=no
php5_cgi=yes

Step: 03

Then
./build update
./build all d

Note: All logs for suPhp are stored in: /var/log/suphp.log

Step: 04

 

cd /usr/local/directadmin/scripts/custom && \

Create two files as below,

  1. vi user_create_post.sh    ## add following contents to the file,

 

#!/bin/sh
mkdir /usr/local/directadmin/data/users/$username/php/
chown $username:$username /usr/local/directadmin/data/users/$username/php/
touch /usr/local/directadmin/data/users/$username/php/php.ini
echo “open_basedir = /home/$username/:/tmp/:/var/tmp/:/usr/local/php5/lib/php/” >> /usr/local/directadmin/data/users/$username/php/php.ini
chown root:root /usr/local/directadmin/data/users/$username/php/php.ini
chattr +i /usr/local/directadmin/data/users/$username/php/
exit 0;

 

/usr/share/cagefs-plugins/hooks/directadmin/user_create_post.sh

/usr/bin/da-addsudoer “$username” add_cagefs_user
/usr/bin/da_add_admin “$username”


 

2. vi user_destroy_pre.sh     ## add below contents


 

#!/bin/sh
chattr -i /usr/local/directadmin/data/users/$username/php/
exit 0;


chmod 755 /usr/local/directadmin/scripts/custom/*.sh && \
chown diradmin:diradmin /usr/local/directadmin/scripts/custom/*.sh

Step: 05

Execute following one liner to create php.ini file for each user.
1
    
ls -l /home | grep '^d' | awk '{system("username="$3" /usr/local/directadmin/scripts/custom/user_create_post.sh")}' 2>/dev/null

Step: 06

Copy VirtualHost templates to custom directory so they are not overwritten when DirectAdmin updates and do Step: 07 on each copied file.
1
    
cp /usr/local/directadmin/data/templates/virtual_host2* /usr/local/directadmin/data/templates/custom/

Step: 07

Open each file in /usr/local/directadmin/data/templates/custom/ and insert following
1
    
SetEnv PHP_INI_SCAN_DIR /usr/local/directadmin/data/users/|USER|/php/

between
1
    
|*if SUPHP=”1″|

and
1
    
|*endif|

Step: 08

Rewrite httpd configs for current users

cd /usr/local/directadmin/custombuild
1
    
./build rewrite_confs

You will get “Internal Server Error” for many sites becuase of permissions and php flgs in .htaccess file.

Note: After swithcing to suphp, php will no longer a apache module and so you can’t control php variables with .htaccess. If you do so, it will result in “Internal Server Error”.

If you get any “Internal Server Error” messages, check the suphp.log to see why.
Usually, things like writeable by “all” or “group” or having the incorrect ownership of the file or php flags in .htaccess file would cause this.

To easy up the permission things download the permission fixer from following script and execute it.
1
    
Create a script for change all file and folder permission.

vi per_fix.sh


#!/bin/bash

#### FIXING PERMISSIONS ####

for i in `cat /etc/virtual/domainowners | awk ‘{ print $2 }’ | sort | uniq`
do
chmod 711 /home/$i
chmod 711 /home/$i/domains
chmod 711 /home/$i/domains/*
find /home/$i/domains/*/public_html -type f -exec chmod 0644 {} \; -print
find /home/$i/domains/*/private_html -type f -exec chmod 0644 {} \; -print
find /home/$i/domains/*/public_html -type d -exec chmod 0755 {} \; -print
find /home/$i/domains/*/private_html -type d -exec chmod 0755 {} \; -print
done

chown webapps.webapps /var/www/html -R

### FIXING OWNERSHIPS ###

for i in `cat /etc/virtual/domainowners | awk ‘{ print $2 }’ | sort | uniq`
do
chown -R $i.$i /home/$i/domains
echo “Ownership of files in /home/$i is fixed”
done


 

Also you can find out all “.htaccess” file which contains php flags by following one liner.
1
    
find /home/*/domains/*/public_html -name “.htaccess” | xargs grep “php_”

Note: You can easily automate replacing php flags from .htaccess using sed

Don’t for get to set open_base dir in server wide php.ini file. The server wide open base dir should be like following
1
    
open_basedir = /var/www/html/:/tmp/:/etc/virtual/

 

0 Comments
Leave a comment
OUR SERVICES
OUR TECHNOLOGIES