--
Script to Add FTP user
#format
#script domain.com username foldername password sizeinMB
echo -e "Chking if domin name exist "
if [ -d /websites/"$1" ]; then
echo -e "the domin exist"
echo -e "chking to see if user exist"
if [ "`cat /usr/local/pureftpd/etc/pureftpd.passwd | sed 's/:/ /g' |awk '{print $1}' |sed -n "/${2}/P"`" != "$2" ]; then
echo -e "chking to see if dir exist"
if [ -d /websites/"$1"/"$3" ]; then
echo -e "the dir $3 exist"
echo -e "adding ftp user"
(echo $4; echo $4 ) | /usr/local/pureftpd/bin/pure-pw useradd "$2" -f /usr/local/pureftpd/etc/pureftpd.passwd -u "$2" -d /websites/"$1"/"$3" -m
else
echo -e "the dir $3 does not exist"
fi
else
echo -e "the user is all read present"
fi
else
echo -e "the domin does not exist"
fi
--
script to add domain / ftp user account
1. check if domain is present
2. if domain is present then it creates a system user
3. It creates the home directory structure
4 . within the home directory structure it creates the various dir.
5. sets permission to those dir
6. write the vhost directive in to the http.conf configuration file
7 . Restart apace ( gracefully )
#!/bin/bash
#steps to set up a website
echo -e " Enter you domain name "
read $1
domain_com=` echo $domain |sed s/\.com//g `
domain_in=`echo $domain |sed s/\.in//g`
domain_net=`echo $domain |sed s/\.net//g`
domain_co_in=`echo $domain |sed s/\.co.in//g`
domain_02=`cat /etc/passwd |grep $domain |sed s/:/\ /g |awk '{print $1}'`
if [ "$domain_com" = "$domain_02" ]; then
echo -e " the domain exist "
exit 1
fi
echo -e "Please enter user for for $domain "
read user
if [ "$user" = "$domain_02" ]; then
echo -e " user exist quiting proces "
else
useradd -d /websites/"$domain" -s /sbin/nologin "$user"
echo -e " created domain $domain "
echo -e "adding ftp user "
echo "$domain"
(echo $domain_com; echo $domain_com ) | /usr/local/pureftpd/bin/pure-pw useradd "$user" -f /usr/local/pureftpd/etc/pureftpd.passwd -u "$user" -d /websites/"$domain" -m
echo -e " adding user sucessful "
echo -e "creating directory structure "
mkdir /websites/"$domain"/web /websites/"$domain"/logs /websites/"$domain"/private /websites/"$domain"/data /websites/"$domain"/cgi-bin
echo -e "sucessfully created directory structure "
echo -e " we chang the permission for the the $user "
chmod 711 /websites/"$domain"/ && chmod 711 /websites/"$domain"/*
echo -e " we change the ownership for the $domain "
chown "$user":"$user" /websites/"$domain" && chown "$user":"$user" /websites/"$domain"/*
echo -e " changes for $user was sucessful "
echo -e "Creating the Vhost directive domain $domain "
echo -e "
######################"$domain"2631###################
<VirtualHost 192.168.0.244:80>
ServerAdmin admin@ashish.sys.qualiproj.com
ServerName "$user".sys.qualiproj.qualispace.com
ServerAlias www."$user".sys.qualiproj.qualispace.com
DocumentRoot /websites/"$domain"/web
##############MIME_TYPE_"$domain"2631##################
<Directory /websites/"$domain"/web>
Options -MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
AllowOverride FileInfo AuthConfig Limit
Order allow,deny
Allow from all
</Directory>
ErrorLog /websites/"$domain"/logs/"$user".sys.qualiproj.error_log
CustomLog /websites/"$domain"/logs/$user.sys.qualiproj.access_log common
ScriptAlias /cgi-bin/ "/websites/"$domain"/cgi-bin/"
<Directory "/websites/"$domain"/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
" >> /usr/local/apache2/conf/extra/httpd_vhost.conf
echo -e "Sucessfully created the Vhost directive domain $domain "
echo -e " restarting httpd "
/etc/init.d/httpd graceful
echo -e "copying test html page to web folder "
cp -R /websites/agnello.com/web/bob.html /websites/"$domain"/web/index.html
echo -e "done "
echo -e " you can now log on to http://www."$user".sys.qualiproj.qualispace.com"
fi
--
A shell script to append MIME Type after a certain pattern
in the bellow script
a ---> stands for append
\n ---> to next line
#!/bin/bash -x
#script to add mime type
add_mime_type_01 ()
{
echo -e enter domain name
if [ -d /websites/"$1" ]; then
sed -i "/MIME_TYPE_$12631/a\AddType application x-httpd-php .php
\nAddType application x-httpd-php-source .phps"
/usr/local/apache2/conf/extra/httpd_vhost.conf
echo -e " add mime type to $1 "
else
"the domin does not exist or has been deleted "
echo -e "execuiting this command "
fi
}
echo -e "Are you sure you want to add mime type for $1"
read answer
case $answer in
Y|yes|YES ) add_mime_type_01 $1
;;
N|No|NO|n ) echo " you have exited the progam "
;;
* ) echo " please type yes or no "
esac
Now aon you commany line jsut typme
script_command.sh yourdomain.com
--
adding passwod to ftpuser as one single command
pure-pw useradd nokia -f /usr/local/pureftpd/etc/pureftpd.passwd -u
nokia -d /home/website/nokia.com -m
it will prompt you to type and retype your password . Now if we want
to add the password on the same command line we can add
(echo name123; echo name123) | /usr/local/pureftpd/bin/pure-pw
passwd passsword -f /usr/local/pureftpd/etc/pureftpd.passwd -m
the -m creates a db file
--
steps to Installing mod_ssl for multiple domains
Apache : mod_ssl for virtual hosting
1. The apache server should be compiled with mod_ssl enabled,. You can check this in the httpd.conf file
LoadModule ssl_module modules/mod_ssl.so
2. Make the followin directory structure
mkdir /usr/local/apache2/conf/domains_ssl/
mkdir /usr/local/apache2/conf/domains_ssl/nokia.com/
3. once this is done create your self-signed ssl certificate and your ssl private key using the openssl toolkit. ( for production purpose you may want to purchase your certificate)
( in orde that apache should not ask fora passwork when it restart we do the following )
cd /usr/local/apache2/conf/domains_ssl/name1.com/ ------>
your location of the keys for domain name1Step 1: Generate Private Key
openssl genrsa -des3 -out server.key 1024
(
N.B: make sure that that the CN matches that of the domain name )Step 2: Generate CSR
openssl req -new -key server.key -out server.csr
Step 3: Remove Passphrase
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
Step 4: Sign the Certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
you would have the follwing keys generated.
server.crt server.csr server.key server.key.org
Once this is done go to the very last line in the httpd.conf file
( addthe following if not already there )
<IfModule ssl_module>
Listen 443
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
now in the httpd-vhost.conf file ( /usr/local/apache2/conf/extra/httpd-vhosts.conf ) add the following
NameVirtualHost 192.168.0.244:443
<VirtualHost 192.168.0.244:443>
ServerAdmin admin@name1.sys.qualiproj.com
ServerName name1.sys.qualiproj.qualispace.com
ServerAlias www.name1.sys.qualiproj.qualispace.com
DocumentRoot /websites/name1.com/web
SSLEngine on
SSLCertificateKeyFile /usr/local/apache2/conf/domains_ssl/name1.com/server.key
SSLCertificateFile /usr/local/apache2/conf/domains_ssl/name1.com/server.crt
ErrorLog /websites/name1.com/logs/name1.sys.qualiproj.error_log
CustomLog /websites/name1.com/logs/name1.sys.qualiproj.access_log common
</VirtualHost>
Now you can restart apache . it will not prompt you for a password .
Now view you site
steps to website setup ( apache 2.2.8 )
create system user
now we add a ftp user
chang the permission
create the directory structure
change the permission and ownnership
edit the httpd-vhost.conf
how to rotate the logs
mod_rewrite
alias for his domain
add custom error page
deny certain IP
add certin mime type
redirect visitors to another page
B. Steps for building awstats for name1.com
see bellow
C . Steps to delete website name1.com
see bellow
Steps to set up a website for name1.com
1 create system user
useradd -d /websites/name1.com -s /sbin/nologin name1
2. now we adda ftp user
/usr/local/pureftpd/bin/pure-pw useradd name1 -f /usr/local/pureftpd/etc/pureftpd.passwd -u name1 -d /websites/name1.com -m
enterpassword
retype password
3. we chang the permission for the the user name1 ( 711 )
chmod 711 /websites/name1.com
4. we create the directory structure for the doamin name1.com
mkdir /websites/name1.com/web /websites/name1.com/logs /websites/name1.com/private /websites/name1.com/data /websites/name1.com/cgi-bin
5.we change the permission and ownnership of the directories we jsut created
chmod 711 /websites/name1.com/*
chown name1:name1 /websites/name1.com/*
6. Now we edit the httpd-vhost.conf ( /usr/local/apache2/conf/extra/httpd-vhosts.conf )
we the add the vhsot directive for name1.com
###########vhost for name1.com.com ############################
<VirtualHost 192.168.0.244:80>
ServerAdmin admin@name1.sys.qualiproj.com
ServerName name1.sys.qualiproj..com
ServerAlias www.name1.sys.qualiproj..com
DocumentRoot /websites/name1.com/web
<Directory /websites/name1.com/web>
Options -MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
AllowOverride FileInfo AuthConfig Limit
Order allow,deny
Allow from all
</Directory>
ErrorLog /websites/name1.com/logs/name1.sys.qualiproj.error_log
CustomLog /websites/name1.com/logs/name1.sys.qualiproj.access_log common
ScriptAlias /cgi-bin/ "/websites/nokia.com/cgi-bin/"
<Directory "/websites/nokia.com/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
8 . now we need to rotate the logs so we edit /etc/logrotate.conf
"/websites/name1.com/logs/name1.sys.qualiproj.access_log" /websites/name1.com/logs/name1.sys.qualiproj.error_log {
rotate 5
size=100k
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}
7 . Now if the client want to use mod_rewrite ( URL rewritting ) then add the folloing in the /usr/local/apache2/conf/extra/httpd-vhosts.conf
<Directory /websites/nokia.com/web>
RewriteEngine On
RewriteRule ^index.html$ bob.html
</Directory>
8. if client wants to add one omre alias for his domain Eg: www.name1.com and ftp.name1.com
ServerAlias www.name1.com ftp.name1.com
9 if client want to add custom error page then we need to add the followin in the http-vhost.conf within the vhost directive
ErrorDocument 500 http://www.devshed.com/c/a/Apache/Custom-Error-Pages-with-Apache
ErrorDocument 404 /cgcraft.gif
10. If client wants to deny certain IP from accessing his website then change the following in the vhost directive
<Directory /websites/name1.com/web>
Options -MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
AllowOverride FileInfo AuthConfig Limit
Order allow,deny
#Allow from all
Deny from 192.168.0.247
</Directory>
11. If client wants to add certin mime type for his domain wedi the vhost directive again and add the following ( eg: enables php )
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
12. if client wants to redirect visitors to another page or url then we edit the vhost directive again and add the following
Redirect /service http://www.google.com
Steps todelete website name1.com
1. delet the system user
userdel -r name1
2. delete the ftpuser
/usr/local/pureftpd/bin/pure-pw userdel name1 -f /usr/local/pureftpd/etc/pureftpd.passwd -m
3. remove move the log rotation script frm /etc/logrotate.comf for the doamin name1.com
"/websites/name1.com/logs/name1.sys.qualiproj.access_log" /websites/name1.com/logs/name1.sys.qualiproj.error_log {
rotate 5
size=100k
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}
5. remove the cron job ( if any ) for awstats in /etc/cron.daily/awstatsupdate perl /websites/name1.com/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/name1.com/webstats/wwwroot/cgi-bin/awstats.pl -update -config=name1.sys.qualiproj.com -dir=/websites/name1.com/web/awstats/
Steps for building awstats for name1.com
1. cp -R /usr/local/src/awstats.6.7 /webistes/name1.com/webstats
2. cp /websites/name1.com/webstats/wwwroot/cgi-bin/awstats.model.conf /websites/name1.com/webstats/wwwroot/cgi-bin/awstats.name1.sys.qualiproj.com.conf
3. mkdir /websites/name1.com/web/awstats
5 chown name1:name1 /websites/name1.com/web/awstats
4. cp -R /websites/name1.com/webstats/wwwroot/icon /websites/name1.com/web/awstats/
5 . Edit the conf file ( awstats.name1.sys.qualiproj.com.conf )
LogFile="/websites/name1.com/logs/name1.sys.qualiproj.access_log"
SiteDomain="name1.sys.qualiproj.com"
HostAliases="www.name1.sys.qualiproj.com name1.sys.qualiproj.com localhost 127.0.0.1 "
DirData="/websites/name1.com/webstats"
DirIcons="/web/awstats/icon"
DNSLookup=1
6 Run the perl script to generate /update the webstats
perl /websites/name1.com/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/name1.com/webstats/wwwroot/cgi-bin/awstats.pl -update -config=name1.sys.qualiproj.com -dir=/websites/name1.com/web/awstats/
8. now we add a cron job to run this every day !
add in /etc/cron.daily/awstatsupdate
perl /websites/name1.com/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/name1.com/webstats/wwwroot/cgi-bin/awstats.pl -update -config=name1.sys.qualiproj.q.com -dir=/websites/name1.com/web/awstats/
7. To add advenced browser security to this folder ( /websites/name1.com/web/awstats ) we first generatea password for the user
/usr/local/apache2/bin/htpasswd -c /websites/privatefolderpasswd/name1.com/htpasswd name1
enter a new password
8. Then we edit the vhost file for name1.com located in /usr/local/apache2/conf/extra/httpd-vhosts.conf
In the Vhost directive we add the following
<vhost>
.
.
.<Directory /websites/nokia.com/web/awstats>
AllowOverride AuthConfig
AuthName "MyPrivateStuff"
AuthType Basic
AuthGroupFile /dev/null
AuthUserFile /websites/privatefolderpasswd/name1.com/htpasswd
AuthName Enterpassword
Require valid-user
</Directory>
</vhost>
installing awstats for virtual domains
installing awstats for virtual domains
download awstats ina seperate folder
cd /usr/local/src
wget wget http://jaist.dl.sourceforge.net/sourceforge/awstats/awstats-6.7.tar.gz
tar -xzvf awstats-6.7.tar.gz
cd awstats-6.7/
cp -R * /websites/nokia.com/webstats
cd /websites/nokia.com/webstats
perl tools/awstats_configure.pl
Do you want to continue setup from this NON standard directory [yN] ? y
Config file path ('none' to skip web server setup): none
Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ? y
Your web site, virtual server or profile name: SITE_NAME.COM
Directory path to store config file(s): /websites/nokia.com/webstats/wwwroot/cgi-bin/
edi the config files located in /websites/nokia.com/webstats/wwwroot/cgi-bin/
LogFile="/websites/nokia.com/log/access.log"
SiteDomain="SITE_NAME.COM"
HostAliases="SITE_NAME.COM www.SITE_NAME.COM 127.0.0.1 localhost"
DNSLookup=1
DirData="/websites/nokia.com/webstats/"
DirIcons="/web/awstats/icon"
mkdir /websites/nokia.com/web/awstats
cp -R /websites/nokia.com/webstats/wwwroot/icon/ /websites/nokia.com/web/awstats/
this perl files will update the web staticts
perl /websites/nokia.com/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/nokia.com/webstats/wwwroot/cgi-bin/awstats.pl -update -config=nokia.sys.qualiproj.qualispace.com -dir=/websites/nokia.com/web/awstats/
To add advanced security to this folder - awstats we add a htacces type authentication.
<Directory /websites/nokia.com/web/awstats>
AllowOverride AuthConfig
AuthName "MyPrivateStuff"
AuthType Basic
AuthGroupFile /dev/null
AuthUserFile /websites/privatefolderpasswd/nokia.com/htpasswd
AuthName Enterpassword
Require valid-user
</Directory>
now view http://nokia.sys.qualiproj.qualispace.com/awstats/awstats.nokia.sys.qualiproj.qualispace.com.html
it will prompt you fro user name password
now you can view you site stats
--
how to compile mod_rewrite from source
LoadModule ssl_module modules/mod_ssl.so
LoadModule rewrite_module modules/mod_rewrite.so
--