├── .gitattributes ├── LICENSE.md ├── README.md ├── install.sh └── vhost-creator.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010-2016 Matteo Merola http://matteomerola.me 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vhost-creator 2 | ============ 3 | 4 | This is a useful bash script that will let you save time creating vhosts for you. 5 | 6 | It supports both ubuntu and centos (be careful to write `ubuntu` or `centos` in lowercase). 7 | 8 | Instructions: 9 | - `mkdir ~/scripts && cd $_` 10 | - `wget https://raw.githubusercontent.com/mattmezza/vhost-creator/master/vhost-creator.sh` 11 | - `chmod +x vhost-creator.sh` 12 | - `sudo ./vhost-creator.sh` 13 | - follow Instructions 14 | 15 | or for the most adventurous just run `curl -s https://raw.githubusercontent.com/mattmezza/vhost-creator/master/install.sh | sh` to install it globally for your user (you can use the script afterwards with `sudo vhost-creator`) 16 | 17 | Don't forget to add a A record from your DNS pointing to your web server IP address. 18 | 19 | You can also mv the script to a system wide bin folder or add it to your bash profile. 20 | 21 | The original idea was this [one](https://gist.github.com/mattmezza/2e326ba2f1352a4b42b8) 22 | 23 | 24 | ###### Thanks to: 25 | - `alexnogard` for his original version 26 | - [Fred Bradley](https://github.com/fredbradley) for [this](https://gist.github.com/fredbradley/296bce8eba544647f10f) gist. 27 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OLD=`pwd` 4 | INSTALL_DIR=/usr/local/bin 5 | cd $INSTALL_DIR 6 | wget https://raw.githubusercontent.com/mattmezza/vhost-creator/master/vhost-creator.sh 7 | mv vhost-creator.sh vhost-creator 8 | chmod +x vhost-creator 9 | echo "Installed successfully in $INSTALL_DIR" 10 | cd $OLD -------------------------------------------------------------------------------- /vhost-creator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script is used for create virtual hosts on CentOs. 3 | # Created by alexnogard from http://alexnogard.com 4 | # Improved by mattmezza from http://matteomerola.me 5 | # Feel free to modify it 6 | # PARAMETERS 7 | # 8 | # $usr - User 9 | # $dir - directory of web files 10 | # $servn - webserver address without www. 11 | # $cname - cname of webserver 12 | # EXAMPLE 13 | # Web directory = /var/www/ 14 | # ServerName = domain.com 15 | # cname = devel 16 | # 17 | # 18 | # Check if you execute the script as root user 19 | # 20 | # This will check if directory already exist then create it with path : /directory/you/choose/domain.com 21 | # Set the ownership, permissions and create a test index.php file 22 | # Create a vhost file domain in your /etc/httpd/conf.d/ directory. 23 | # And add the new vhost to the hosts. 24 | # 25 | # 26 | if [ "$(whoami)" != 'root' ]; then 27 | echo "Dude, you should execute this script as root user..." 28 | exit 1; 29 | fi 30 | echo "First of all, is this server an Ubuntu or is it a CentOS?" 31 | read -p "ubuntu or centos (lowercase, please) : " osname 32 | 33 | SERVICE_="apache2" 34 | VHOST_PATH="/etc/apache2/sites-available" 35 | CFG_TEST="apachectl -t" 36 | if [ "$osname" == "centos" ]; then 37 | SERVICE_="httpd" 38 | VHOST_PATH="/etc/httpd/conf.d" 39 | CFG_TEST="service httpd configtest" 40 | elif [ "$osname" != "ubuntu" ]; then 41 | echo "Sorry mate but I only support ubuntu or centos" 42 | echo " " 43 | echo "By the way, are you sure you have entered 'centos' or 'ubuntu' all lowercase???" 44 | exit 1; 45 | fi 46 | 47 | echo "Enter the server name you want" 48 | read -p "e.g. mydomain.tld (without www) : " servn 49 | echo "Enter a CNAME" 50 | read -p "e.g. www or dev for dev.website.com : " cname 51 | echo "Enter the path of directory you wanna use" 52 | read -p "e.g. /var/www/, dont forget the / : " dir 53 | echo "Enter the name of the document root folder" 54 | read -p "e.g. htdocs : " docroot 55 | echo "Enter the user you wanna use" 56 | read -p "e.g. apache/www-data : " usr 57 | echo "Enter the listened IP for the web server" 58 | read -p "e.g. * : " listen 59 | echo "Enter the port on which the web server should respond" 60 | read -p "e.g. 80 : " port 61 | 62 | if ! mkdir -p $dir$cname_$servn/$docroot; then 63 | echo "Web directory already Exist !" 64 | else 65 | echo "Web directory created with success !" 66 | fi 67 | echo "