-
-
Save xctheo/e98ebd3f8d1fd25a5c446494b6721a99 to your computer and use it in GitHub Desktop.
Apache auto-vhost
This file contains hidden or 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/sh | |
| WEBROOT="/var/www/" | |
| VHOSTDIR="/etc/apache2/sites-available/" | |
| EXTENSION=".conf" | |
| RESTARTCMD="/usr/bin/sudo service apache2 reload" | |
| if [ "$1" != '' ]; then | |
| if [ ! -f "$VHOSTDIR$1.conf" ]; then | |
| cp "$VHOSTDIR/template.conf" "$VHOSTDIR$1$EXTENSION" | |
| echo "created $VHOSTDIR$1$EXTENSION" | |
| else | |
| mv "$VHOSTDIR$1.conf" "$VHOSTDIR$1$EXTENSION.bak" | |
| cp "$VHOSTDIR/template.conf" "$VHOSTDIR$1$EXTENSION" | |
| echo "created $VHOSTDIR$1$EXTENSION and made a backup of the existing conf" | |
| fi | |
| find "$VHOSTDIR$1$EXTENSION" -type f -exec sed -i "s/SITENAME/$1/" {} \; | |
| if [ ! -d "$WEBROOT$1/" ]; then | |
| mkdir "$WEBROOT$1/" | |
| chown -R :www-data "$WEBROOT$1/" | |
| echo "created $WEBROOT$1/" | |
| else | |
| echo "$WEBROOT$1/ already exists" | |
| fi | |
| sudo a2ensite $1 | |
| $RESTARTCMD | |
| echo "reloaded apache" | |
| elif [ "$1" = 'help' ] || [ "$1" = '' ]; then | |
| echo "usage:" | |
| echo "sudo addwebsite " | |
| echo "example: to create hostname.localhost just run the command 'sudo addwebsite hostname.localhost'" | |
| fi | |
| # sed -i "127.0.0.1 $1.local" /etc/hosts |
This file contains hidden or 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/sh | |
| WEBROOT="/var/www/" | |
| VHOSTDIR="/etc/apache2/sites-available/" | |
| EXTENSION=".conf" | |
| RESTARTCMD="/usr/bin/sudo service apache2 reload" | |
| if [ "$1" != '' ]; then | |
| if [ ! -f "$VHOSTDIR$1.conf" ]; then | |
| cp "$VHOSTDIR/template.conf" "$VHOSTDIR$1$EXTENSION" | |
| echo "created $VHOSTDIR$1$EXTENSION" | |
| else | |
| mv "$VHOSTDIR$1.conf" "$VHOSTDIR$1$EXTENSION.bak" | |
| cp "$VHOSTDIR/template.conf" "$VHOSTDIR$1$EXTENSION" | |
| echo "created $VHOSTDIR$1$EXTENSION and made a backup of the existing conf" | |
| fi | |
| find "$VHOSTDIR$1$EXTENSION" -type f -exec sed -i "s/SITENAME/$1/" {} \; | |
| if [ ! -d "$WEBROOT$1/" ]; then | |
| mkdir "$WEBROOT$1/" | |
| chown -R :www-data "$WEBROOT$1/" | |
| echo "created $WEBROOT$1/" | |
| else | |
| echo "$WEBROOT$1/ already exists" | |
| fi | |
| sudo a2ensite $1 | |
| $RESTARTCMD | |
| echo "reloaded apache" | |
| elif [ "$1" = 'help' ] || [ "$1" = '' ]; then | |
| echo "usage:" | |
| echo "sudo addwebsite " | |
| echo "example: to create hostname.localhost just run the command 'sudo addwebsite hostname.localhost'" | |
| fi | |
| # sed -i "127.0.0.1 $1.local" /etc/hosts |
This file contains hidden or 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
| <VIRTUALHOST *:80> | |
| ServerAdmin webmaster@SITENAME | |
| ServerName SITENAME | |
| ServerAlias SITENAME | |
| <Directory /> | |
| Options FollowSymLinks | |
| AllowOverride None | |
| </Directory> | |
| DocumentRoot /var/www/SITENAME/public | |
| <Directory /var/www/SITENAME/public> | |
| # enable the .htaccess rewrites | |
| AllowOverride All | |
| Require all granted | |
| Order allow,deny | |
| Allow from All | |
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^(.*)$ /app.php [QSA,L] | |
| </IfModule> | |
| </Directory> | |
| <IfModule mod_dir.c> | |
| DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm | |
| </IfModule> | |
| ErrorLog /var/log/apache2/SITENAME_error.log | |
| CustomLog /var/log/apache2/SITENAME_access.log combined | |
| </VIRTUALHOST> |
This file contains hidden or 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
| <VIRTUALHOST *:80> | |
| ServerAdmin webmaster@SITENAME | |
| ServerName SITENAME | |
| ServerAlias SITENAME | |
| <Directory /> | |
| Options FollowSymLinks | |
| AllowOverride None | |
| </Directory> | |
| DocumentRoot /var/www/SITENAME/public | |
| <Directory /var/www/SITENAME/public> | |
| # enable the .htaccess rewrites | |
| AllowOverride All | |
| Require all granted | |
| Order allow,deny | |
| Allow from All | |
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^(.*)$ /app.php [QSA,L] | |
| </IfModule> | |
| </Directory> | |
| <IfModule mod_dir.c> | |
| DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm | |
| </IfModule> | |
| ErrorLog /var/log/apache2/SITENAME_error.log | |
| CustomLog /var/log/apache2/SITENAME_access.log combined | |
| </VIRTUALHOST> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment