Welcome Guest, Not a member yet? Register   Sign In
Automatic/Push Button site folder/vhost creation in Linux via CI/PHP
#2

[eluser]n0xie[/eluser]
You can just write a bash script, then call that from within PHP. This is my addsite.sh I call when starting a new project which takes care of vhost and hosts file:

Code:
#!/bin/bash
CMDLN_ARGS="$@" # Command line arguments for this script
export CMDLN_ARGS

# Run this script as root if not already.
chk_root () {

if [ ! $( id -u ) -eq 0 ]; then
   echo "Please enter your password."
   exec sudo su -c "${0} ${CMDLN_ARGS}" # Call this prog as root
   exit ${?}  # sice we're 'execing' above, we wont reach this exit
              # unless something goes wrong.
fi

}
chk_root
FILE=$(cat /etc/hosts)
echo $FILE |grep -o "test$";

if [ `echo $FILE |grep -o "\$1$"` ];
then
  echo "/etc/hosts file is ok"
else
  echo "127.0.0.1         $1" >> /etc/hosts
fi
cp /etc/apache2/sites-available/template.conf /etc/apache2/sites-available/$1
cat /etc/apache2/sites-available/$1 | sed "s/site/$1/g" |cat > /etc/apache2/sites-available/$1
ln -s /etc/apache2/sites-available/$1 /etc/apache2/sites-enabled/$1
/etc/init.d/apache2 restart
echo "vhost creation done"


Messages In This Thread
Automatic/Push Button site folder/vhost creation in Linux via CI/PHP - by El Forum - 05-20-2010, 03:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB