Created
June 22, 2013 20:38
-
-
Save marcj/5842501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.. | |
Include /etc/apache2/vhost-macro.conf | |
Include /srv/vhosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Macro VHost $host $dir $owner> | |
<VirtualHost *:80> | |
ServerName www.$host | |
ServerAlias $host | |
DocumentRoot /srv/www/$dir/htdocs/ | |
# LogLevel warn | |
LogLevel debug | |
CustomLog "/srv/www/$dir/logs/access.log" combined | |
ErrorLog "/srv/www/$dir/logs/error.log" | |
SuexecUserGroup $owner $owner | |
SetEnv open_basedir $host | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} !^www.$host | |
RewriteCond %{HTTP_HOST} !(.+)\.(.+)\.(.+)$ | |
RewriteRule ^/(.*) http://www.$host/$1 [R=301,L] | |
RewriteCond %{QUERY_STRING} ^(.*)http://(.*) [OR] | |
RewriteCond %{QUERY_STRING} ^(.*)UNION(.*) [OR] | |
RewriteCond %{QUERY_STRING} ^(.*)union(.*) | |
RewriteRule (.*) /srv/www/boo.html [L] | |
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
Use ModDeflate | |
Use ModExpires | |
IPCCommTimeout 400 | |
<Directory /srv/www/$dir> | |
FCGIWrapper /srv/www/$dir/_fconf .php | |
Options FollowSymLinks ExecCGI | |
AddHandler default-handler .html | |
AddHandler default-handler .jpg | |
<FilesMatch \.php$> | |
SetHandler fcgid-script | |
</FilesMatch> | |
AllowOverride All | |
Order allow,deny | |
Allow from all | |
</Directory> | |
</VirtualHost> | |
</Macro> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# usage addVhost.sh <domain> <folder> <user> | |
domain="$1"; | |
folder="$2"; | |
user="$3"; | |
wwwuser="www-data"; | |
target="/srv/www/$folder"; | |
conf="$target/_fconf"; | |
confpath="$target/conf"; | |
htdocs="$target/htdocs"; | |
tmp="$target/tmp"; | |
phpini="$target/conf/php.ini"; | |
logs="$target/logs/"; | |
if [ ! -d $target ]; then | |
echo "Folder $target not exists - create." | |
mkdir -p $target; | |
fi | |
if [ ! -d $confpath ]; then | |
echo "Folder $confpath not exists - create." | |
mkdir -p $confpath; | |
fi | |
if [ ! -d $htdocs ]; then | |
echo "Folder $htdocs not exists - create." | |
mkdir -p $htdocs; | |
fi | |
if [ ! -d $logs ]; then | |
echo "Folder $logs not exists - create." | |
mkdir -p $logs; | |
fi | |
if [ ! -d $tmp ]; then | |
echo "Folder $tmp not exists - create." | |
mkdir -p $tmp; | |
fi | |
echo; | |
id $user; | |
if [ $? -eq 1 ]; then | |
echo "adding user: $user"; | |
adduser --disabled-login --home $target --shell /bin/false $user | |
fi | |
# if [ ! -f $conf ]; then | |
echo "Create config."; | |
# cp /root/_default_fconf $conf; | |
chattr -V -i $conf; | |
cat > $conf << EOF | |
#!/bin/sh | |
PHPRC="/srv/www/$folder/conf/" | |
export PHPRC | |
export TMPDIR=$tmp | |
exec /usr/bin/php5-cgi -d open_basedir=$tmp:$htdocs | |
EOF | |
# fi | |
if [ ! -f $phpini ]; then | |
echo "Create php.ini."; | |
cp /etc/php5/cgi/php.ini $target/conf/; | |
fi | |
grep "$domain $folder" /srv/vhosts | |
if [ $? -eq 1 ]; then | |
echo "Adding to vhosts"; | |
echo "Use Vhost $domain $folder $user" >> /srv/vhosts; | |
fi | |
# chown -R $user:$user $target; | |
chown -R $wwwuser:$user $target; | |
chown $user:$user $target; | |
chmod -R 770 $target; | |
chmod 755 $target; | |
chmod 775 $target/htdocs; | |
chmod 750 $conf; | |
chown $user:$user $confpath; | |
chmod -R 550 $confpath; | |
chown $user:$user $conf; | |
chattr -V +i $conf; | |
echo "done."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use Vhost host.tld folderName userName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PHPRC="/srv/www/host.tld/conf/" | |
export PHPRC | |
export TMPDIR=/srv/www/host.tld/tmp | |
exec /usr/bin/php5-cgi -d open_basedir=/srv/www/host.tld/htdocs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment