-
-
Save akaguny/f111e33f546af1516e36f70ffcce0f60 to your computer and use it in GitHub Desktop.
Linux bash script to write to XAMPP vhost and add symbolic link.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Format of command: ./xampp.sh new.website.name.com | |
# arguments: name=virtual adress site | |
# edited files by script: /opt/lampp/etc/extra/httpd-vhosts.conf, /etc/hosts | |
XAMPP_DIR="/opt/lampp" # Youre installation folder | |
PROJECTS_DIR="/home/alexey/webprojects" # Youre projects folder | |
#todo: change /home/alexey to variable $HOME, but if run script whit sudo $home = root | |
PROJECT_DIR="$PROJECTS_DIR/$1" | |
# Number of expected arguments | |
EXPECTED_ARGS=1 | |
function modify_vhosts { | |
$PROJECT_DIR = $2 | |
sudo printf "\n<VirtualHost *:80>\n\tServerName $1\n\tDocumentRoot \"$PROJECT_DIR\"\n\t<Directory \"$PROJECT_DIR\">\n\tOptions Indexes FollowSymLinks Includes ExecCGI\n\tAllowOverride All\n\tRequire all granted\n\t</Directory>\n\tErrorLog \"logs/$1-error_log\"\n</VirtualHost>" >> $XAMPP_DIR/etc/extra/httpd-vhosts.conf | |
} | |
clear | |
if [ $# -ne $EXPECTED_ARGS ]; then | |
echo "Inputed wrong number of arguments" | |
else | |
#Modify vhost file with given url | |
modify_vhosts $1 $PROJECT_DIR | |
#Modify hosts sistem file | |
sudo printf "\n127.0.0.1\t$1\n127.0.0.1\twww.$1" >> /etc/hosts | |
#todo: restart server | |
fi |
nothing about it, sorry.
maybe ask about it in the original of this fork?
https://gist.github.com/dflynn15/e4743e6d7ce360cd3fa6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Akaguny,
I was looking for something like this and I found your script. My project directory is /data/lampp/htdocs
when I execute the the code with sudo it able to change the vhost file and hosts file but can't create project folder. If I execute without sudo it can't do anything.
So for testing I edited the code a little bit
but still get a warning
./xampp.sh: line 14: /data/lampp/htdocs/newtestsite3.local: Is a directory
Any advice?
Thanks
Shahi