From f88cd0bb00c677017ea2c023812ec646c95d5f71 Mon Sep 17 00:00:00 2001 From: p19x30 <34997060+p19x30@users.noreply.github.com> Date: Tue, 16 Mar 2021 01:14:12 +0500 Subject: [PATCH] Create newvhost.sh --- newvhost.sh | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 newvhost.sh diff --git a/newvhost.sh b/newvhost.sh new file mode 100644 index 0000000..7ff3dd1 --- /dev/null +++ b/newvhost.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# This script is used for create virtual hosts on CentOs. +# Created by alexnogard from http://alexnogard.com +# Improved by mattmezza from http://matteomerola.me +# Feel free to modify it +# PARAMETERS +# +# $usr - User +# $dir - directory of web files +# $servn - webserver address without www. +# $cname - cname of webserver +# EXAMPLE +# Web directory = /var/www/ +# ServerName = domain.com +# cname = devel +# +# +# Check if you execute the script as root user +# +# This will check if directory already exist then create it with path : /directory/you/choose/domain.com +# Set the ownership, permissions and create a test index.php file +# Create a vhost file domain in your /etc/httpd/conf.d/ directory. +# And add the new vhost to the hosts. +# +# +if [ "$(whoami)" != 'root' ]; then +echo "Dude, you should execute this script as root user..." +exit 1; +fi + +osname="ubuntu" +SERVICE_="apache2" +VHOST_PATH="/etc/apache2/sites-available" +CFG_TEST="apachectl -t" +if [ "$osname" == "centos" ]; then + SERVICE_="httpd" + VHOST_PATH="/etc/httpd/conf.d" + CFG_TEST="service httpd configtest" +elif [ "$osname" != "ubuntu" ]; then + echo "Sorry mate but I only support ubuntu or centos" + echo " " + echo "By the way, are you sure you have entered 'centos' or 'ubuntu' all lowercase???" + exit 1; +fi + +echo "Enter the server name you want" +read -p "e.g. mydomain.tld (without www) : " servn +cname="www" +dir="/var/www/" +docroot="public" +usr="apache/www-data" +listen="*" +port="80" + +if ! mkdir -p $dir$cname_$servn/$docroot; then +echo "Web directory already Exist !" +else +echo "Web directory created with success !" +fi +echo "