apache create virtual host shell script




The following script will help you to create a website in apache with basic configuration. Please make sure that you have taken a backup of /etc/httpd/conf/httpd.conf file before you proceed, and this script will create a user too so make sure you understand what it is doing.



#! Shell script to add domains/websites in apache
echo "Make sure that you took backup of your /etc/httpd/conf/httpd.conf file before proceeding"
echo "Enter the name of the domain you wish to create"
read a

echo "Enter the username of the website you wish to create"
read username
/usr/sbin/useradd $username
echo "Enter the password for the user $username"
/usr/bin/passwd $username
echo "Enter the website path in the server"
echo "Example /home/$username/public_html"
read i
mkdir -p "$i"
chmod 750 /home/$username
echo "Enter the IP address to which the domain should listen to"
read ip
echo "<VirtualHost $ip:80>" >> /etc/httpd/conf/httpd.conf
echo "ServerAdmin webmaster@$a" >> /etc/httpd/conf/httpd.conf
echo "DocumentRoot $i" >> /etc/httpd/conf/httpd.conf
echo "ServerName $a" >> /etc/httpd/conf/httpd.conf
echo "ErrorLog logs/$a-error_log" >> /etc/httpd/conf/httpd.conf
echo "CustomLog logs/$a-access_log common" >> /etc/httpd/conf/httpd.conf
echo "</VirtualHost>" >> /etc/httpd/conf/httpd.conf
echo "Please make sure that you have set apache user to read permission at /home/$username folder"

Thank you for viewing https://helpinlinux.com

Leave a Reply

Protected by WP Anti Spam