• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Automated suphp for new domains and subdomains

EgidijusS

Regular Pleskian
Hello,

after having lot of troubles with joomla, wordpress and others softwares I decided finaly install suphp on my servers. I spend few days for searching and investigating for full automated solution. And at last ... system is working. Here all install manual, how i did. Maybe somewhere I wrong, but this solution is working for me.

First of all, download and install atomic script:
# wget -q -O – http://www.atomicorp.com/installers/atomic | sh

after script is instaled, install mod_suphp
# yum install mod_suphp

Next step is enable suPhp in apache, create suphp.conf file in
# vi /etc/httpd/conf.d/suphp.conf

and insert the following:

LoadModule suphp_module modules/mod_suphp.so
php_admin_value engine off
suPHP_Engine On
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php

After that we need to create config for suphp in /etc suphp.conf
[global]
;Path to logfile
logfile=/var/log/suphp.log

;Loglevel
loglevel=warn

;User Apache is running as
webserver_user=apache

;Path all scripts have to be in
docroot=/var/www/vhosts:${ HOME}/httpdocs


;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=true
allow_file_others_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=false

;Send minor error messages to browser
errors_to_browser=true

;PATH environment variable
env_path=/bin:/usr/bin

;Umask to set, specify in octal notation
umask=0022

; Minimum UID
min_uid=30

; Minimum GID
min_gid=30

; Use correct permissions for mod_userdir sites
;handle_userdir=true

[handlers]
;Handler for php-scripts
php5-script=php:/usr/bin/php-cgi

;Handler for CGI-scripts
x-suphp-cgi=execute:!self

Now we can restart apache:
/etc/inid.d/httpd restart

Install of suphp is done.

Now it's time to configure plesk add suphp in hosts:
cd /usr/local/psa/bin
touch suphp_domain.sh
chown root:root
chmod 755

vi suphp_domain.sh
#!/bin/bash
sleep 30

echo '# PHP version detected 5' >> /var/www/vhosts/$1/conf/vhost.conf
echo '<IfModule mod_suphp.c>' >> /var/www/vhosts/$1/conf/vhost.conf
echo "<Directory \"/var/www/vhosts/$1/httpdocs/\">" >> /var/www/vhosts/$1/conf/vhost.conf
echo 'php_admin_flag engine on' >> /var/www/vhosts/$1/conf/vhost.conf
echo 'suPHP_Engine On' >> /var/www/vhosts/$1/conf/vhost.conf
echo "suPHP_ConfigPath \"/var/www/vhosts/$1/httpdocs/\"" >> /var/www/vhosts/$1/conf/vhost.conf
echo 'AddHandler php5-script .php' >> /var/www/vhosts/$1/conf/vhost.conf
echo 'AddHandler x-httpd-php .php5' >> /var/www/vhosts/$1/conf/vhost.conf
echo 'suPHP_AddHandler php5-script .php' >> /var/www/vhosts/$1/conf/vhost.conf
echo '<Files php.ini>' >> /var/www/vhosts/$1/conf/vhost.conf
echo 'order allow,deny' >> /var/www/vhosts/$1/conf/vhost.conf
echo 'deny from all' >> /var/www/vhosts/$1/conf/vhost.conf
echo '</Files>' >> /var/www/vhosts/$1/conf/vhost.conf
echo 'php_value open_basedir "/tmp/"' >> /var/www/vhosts/$1/conf/vhost.conf
echo "php_value upload_tmp_dir \"/var/www/vhosts/$1/httpdocs/tmp/\"" >> /var/www/vhosts/$1/conf/vhost.conf
echo '</Directory>' >> /var/www/vhosts/$1/conf/vhost.conf
echo '</IfModule>' >> /var/www/vhosts/$1/conf/vhost.conf

/usr/local/psa/admin/bin/websrvmng -u --vhost-name=$1
/etc/init.d/httpd restart

touch suphp_subdomain.sh
chown root:root
chmod 755

vi suphp_subdomain.sh
#!/bin/bash
sleep 30

echo '# PHP version detected 5' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo '<IfModule mod_suphp.c>' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo "<Directory \"/var/www/vhosts/$1/subdomains/$2/httpdocs/\">" >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'php_admin_flag engine on' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'suPHP_Engine On' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo "suPHP_ConfigPath \"/var/www/vhosts/$1/subdomains/$2/httpdocs/\"" >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'AddHandler php5-script .php' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'AddHandler x-httpd-php .php5' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'suPHP_AddHandler php5-script .php' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo '<Files php.ini>' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'order allow,deny' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'deny from all' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo '</Files>' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo 'php_value open_basedir "/tmp/"' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo "php_value upload_tmp_dir \"/var/www/vhosts/$1/subdomains/$2/httpdocs/tmp/\"" >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo '</Directory>' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf
echo '</IfModule>' >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf

/usr/local/psa/admin/bin/websrvmng -u --vhost-name=$1
/etc/init.d/httpd restart

Files are ready. Now login to plesk and goto Server --> Event Manager --> Add New Event Handler
select event "Domain created", priority -> lowest, user -> root and in command insert:/usr/local/psa/bin/suphp_domain.sh <new_domain_name>

This will create config file for every new domain you create. The same we have to do for subdomain:
Server --> Event Manager --> Add New Event Handler, select event "Subdomain created", priority -> lowest, user -> root and in command insert:
/usr/local/psa/bin/suphp_subdomain.sh <new_domain_name> <new_subdomain_name>

This will do the same for every subdomain.

Thats all, now you can easy install joomla, wordpress, gallery's and others without any problems with permissions in your new domains created in plesk. I don't know it is compatible with plesk 9.x.

If you already have domains with instaled aplications than you have to change permissions to use with suphp:
find . -type f -exec chmod 644 {} \;; find . -type d -exec chmod 755 {} \;; find . -exec chown <USER>sacln {} \;; service httpd restart

You must change <USER> to your own domain user.

Use it at your own risk.

Thank to atomicrocketturtle.com, linuxhostingsupport.net and other which resourses was very usefull.
 
Hello EgidijusS.

I find your post very usefull.

I am trying to set up suPHP only for specific domains (don't want to break anything, what is wokring now)

I tried creating vhost.conf using your generator, also modified /etc/suphp/suphp.conf like yours... - only difference is an apache user.

the only difference, I didn't do:
php_admin_value engine off
suPHP_Engine On
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php


but theoritecally it should work.. but it does not :(

Maybe you ar anyone else can share their ideas? thank you!
 
hello there,

we use nearly the same setup. it differs a little from the event handlers and the used bash script. it is only one script that will manage domains, subdomains and renaming of those. maybe it will be useful.


Skeleton in /var/www/vhosts/.skel/0/conf/vhost.conf
<code>
<Directory /var/www/vhosts/@domain_name@/httpdocs>
<IfModule mod_suphp.c>
php_admin_flag engine off
suPHP_Engine on
AddHandler x-httpd-php .php .asmx
#suPHP_UserGroup apache apache
suPHP_AddHandler x-httpd-php
suPHP_ConfigPath "/var/www/vhosts/@domain_name@/"
</IfModule>
</Directory>
</code>

suphp config is the same as above except the handler configuration
<code>
....
[handlers]
;Handler for php-scripts
x-httpd-php="php:/usr/local/sbin/php-wrapper"
x-httpd-php4="php:/usr/local/sbin/php-wrapper"
x-httpd-php5="php:/usr/local/sbin/php-wrapper"
x-httpd-php3="php:/usr/local/sbin/php-wrapper"
x-httpd-php51="php:/usr/local/sbin/php-wrapper_workaround"
</code>

php wrapper script /usr/local/sbin/php-wrapper
<code>
#!/bin/bash

vDOCROOT1=$(echo $DOCUMENT_ROOT | /usr/bin/xargs /usr/bin/dirname)
vDOCROOT2=$(/usr/bin/dirname $DOCUMENT_ROOT)

if [ -n "$vDOCROOT1" ]; then
OBASE="/tmp:/usr/bin:/usr/local/bin:/bin:/usr/share:/var/log/formmail/:/home/:$vDOCROOT1"
else
OBASE=/tmp:/usr/bin:/usr/local/bin:/bin:/usr/share:/var/log/formmail/:/home/:/var/www/vhosts/
fi

/usr/bin/php-cgi -d open_basedir=$OBASE
</code>

Event Handler script for "Domainadministrator-Account updated", "Subdomain created", "Subdomain updated".
<code>
#!/bin/bash

SCRIPTLOG="/tmp/plesk_subdomain_create.log"

vARGs=$#

case "$vARGs" in
4)
echo "`date` - Arguments: $# $@" >> $SCRIPTLOG
;;
5)
echo "`date` - DEBUG MODE - Arguments: $# $@" >> $SCRIPTLOG
;;
*)
echo "ERROR: wrong usage"
echo "Params: 4 OLDSUB+sub2 NEWSUB+sub2 OLDDOM+suphp5.domain.tld NEWDOM+suphp6.domain.tld"
exit 1
;;
esac



function debugoutput() {
if [ $vARGs == 5 ]; then
echo "`date` - DEBUG MODE - Argument: $*" >> $SCRIPTLOG
fi
return 0
}

#m1
OLDSUB="$1"
NEWSUB="$2"
OLDDOM="$3"
NEWDOM="$4"
debugoutput m1 $OLDSUB $NEWSUB $OLDDOM $NEWDOM

#m2
OLDSUBsubst=$(echo $OLDSUB | awk -F+ '{ print $2 }' )
NEWSUBsubst=$(echo $NEWSUB | awk -F+ '{ print $2 }' )
OLDDOMsubst=$(echo $OLDDOM | awk -F+ '{ print $2 }' )
NEWDOMsubst=$(echo $NEWDOM | awk -F+ '{ print $2 }' )
debugoutput m2 $OLDSUBsubst $NEWSUBsubst $OLDDOMsubst $NEWDOMsubst

#m3
DOMAINDIR="/var/www/vhosts"
SUBDOMAINDIR="$DOMAINDIR/$NEWDOMsubst/subdomains/$NEWSUBsubst"
debugoutput m3 $DOMAINDIR $SUBDOMAINDIR

#m4
if [ ! "$OLDSUB" = "OLDSUB+" ]; then

sed -i 's/'$OLDSUBsubst'/'$NEWSUBsubst'/g' $SUBDOMAINDIR/conf/vhost.conf
sed -i 's/'$OLDSUBsubst'/'$NEWSUBsubst'/g' $SUBDOMAINDIR/conf/vhost_ssl.conf

fi
debugoutput m4 '"$OLDSUB"==>'$OLDSUB' = "OLDSUB+"'

#m5
if [ "$OLDDOM" != "$NEWDOM" ]; then
## Subdomains ausbessern (rename)
sed -i 's/'$OLDDOMsubst'/'$NEWDOMsubst'/g' $SUBDOMAINDIR/conf/vhost.conf
sed -i 's/'$OLDDOMsubst'/'$NEWDOMsubst'/g' $SUBDOMAINDIR/conf/vhost_ssl.conf
fi
debugoutput m5 '"$OLDDOM"==>'$OLDDOM' != "$NEWDOM==>'$NEWDOM'"'

#m6
if [ "$OLDDOMsubst" != "$NEWDOMsubst" ]; then
## Domain ausbessern (rename)
sed -i 's/'$OLDDOMsubst'/'$NEWDOMsubst'/g' $DOMAINDIR/$OLDDOMsubst/conf/vhost.conf
sed -i 's/'$OLDDOMsubst'/'$NEWDOMsubst'/g' $DOMAINDIR/$OLDDOMsubst/conf/vhost_ssl.conf
sed -i 's/'$OLDDOMsubst'/'$NEWDOMsubst'/g' $DOMAINDIR/$NEWDOMsubst/conf/vhost.conf
sed -i 's/'$OLDDOMsubst'/'$NEWDOMsubst'/g' $DOMAINDIR/$NEWDOMsubst/conf/vhost_ssl.conf
fi
debugoutput m6 '"$OLDDOMsubst"==>'$OLDDOMsubst' != "$NEWDOMsubst==>'$NEWDOMsubst'"'

#m7
# nicht ssl
sed -i 's/'$NEWDOMsubst'\/httpdocs/'$NEWDOMsubst'\/subdomains\/'$NEWSUBsubst'\/httpdocs/g' $SUBDOMAINDIR/conf/vhost.conf

# ssl
sed -i 's/'$NEWDOMsubst'\/httpdocs/'$NEWDOMsubst'\/subdomains\/'$NEWSUBsubst'\/httpdocs/g' $SUBDOMAINDIR/conf/vhost_ssl.conf
sed -i 's/'$NEWDOMsubst'\/httpsdocs/'$NEWDOMsubst'\/subdomains\/'$NEWSUBsubst'\/httpsdocs/g' $SUBDOMAINDIR/conf/vhost_ssl.conf


exit 0
</code>
 
hm sorry forgot to post the event handler setup for /root/bin/plesk_subdomain_vhost.sh.

- Domainadministrator-Account aktualisiert (hoch75/root)
---cut---
/root/bin/plesk_subdomain_vhost.sh OLDSUB+<old_subdomain_name>
NEWSUB+<new_subdomain_name> OLDDOM+<old_domain_name>
NEWDOM+<new_domain_name>
---cut---

- Subdomain aktualisiert (hoch75/root)
---cut---
/root/bin/plesk_subdomain_vhost.sh OLDSUB+<old_subdomain_name>
NEWSUB+<new_subdomain_name> OLDDOM+<old_domain_name>
NEWDOM+<new_domain_name>
---cut---

- Subdomain erstellt (hoch75/root)
---cut---
/root/bin/plesk_subdomain_vhost.sh OLDSUB+<old_subdomain_name>
NEWSUB+<new_subdomain_name> OLDDOM+<old_domain_name>
NEWDOM+<new_domain_name>
---cut---
 
Back
Top