Created
December 14, 2015 20:01
-
-
Save oviniciusfeitosa/03306d7aa59cdfccb788 to your computer and use it in GitHub Desktop.
Create dynamic VirtualHost - Apache2 | Useful for Vagrant provision
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
# Português | |
# Tem como responsabilidade criar e ativar um VirtualHost no Apache2 dinamicamente. Muito útil para quem utiliza Vagrant e procura uma maneira mais simples para criar VirtualHosts . | |
# Como vários frameworks PHP, como ZendFramework 2, seguem uma estrutura parecida para que os arquivos .htaccess funcionem corretamente, essa é uma alternativa simples e que pode ser integrada com outras ferramentas. | |
# English | |
# It has the responsibility to create and activate a VirtualHost in Apache 2 dynamically. Very useful for those using Vagrant and seeks a simpler way to create VirtualHosts. | |
# How many PHP frameworks, as ZendFramework 2, follow a similar structure to that .htaccess files work correctly, this is a simple alternative that can be integrated with other tools. | |
# Parameters: | |
# $1 > ServerName | |
# $2 > Directory | |
createDynamicVirtualHost() { | |
sudo echo -e "<VirtualHost *:80> \n" \ | |
" ServerName $1 \n" \ | |
" DocumentRoot /var/www/ZendFramework2/$2/public \n" \ | |
" SetEnv APPLICATION_ENV \"development\" \n" \ | |
" ErrorLog /var/www/log/$1/error.log \n" \ | |
" CustomLog /var/www/log/$1/access.log combined \n" \ | |
" <Directory /var/www/ZendFramework2/$2/public> \n" \ | |
" DirectoryIndex index.php \n" \ | |
" AllowOverride All \n" \ | |
" Order allow,deny \n" \ | |
" Allow from all \n" \ | |
" Require all granted \n" \ | |
" </Directory> \n" \ | |
"</VirtualHost> " > /etc/apache2/sites-available/$1.conf ; | |
sudo chmod 777 /etc/apache2/sites-available/$1.conf; | |
sudo mkdir -p /var/www/log/$1; | |
sudo touch /var/www/log/$1/error.log; | |
sudo touch /var/www/log/$1/access.log; | |
sudo a2ensite $1.conf; | |
sudo apachectl restart; | |
} | |
# Usage : | |
# createDynamicVirtualHost mylocalsystem.local mylocalsystemDirectory | |
# Example : | |
# createDynamicVirtualHost mycartsystem.local mycartsystem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment