Last active
August 29, 2015 14:07
-
-
Save Beagon/3838b3744df2fe618431 to your computer and use it in GitHub Desktop.
addApache2Project.sh
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
| #!/usr/bin/env bash | |
| WEBSITE_DIRECTORY="/var/www/" | |
| getVhostName() | |
| { | |
| read -p "Please enter a project name: " vhostName | |
| if [ -z "${vhostName}" ] | |
| then | |
| echo "Please fill in a project name!" | |
| getVhostName | |
| else | |
| WEB_DIR=/var/www/$vhostName | |
| fi | |
| } | |
| createDirAndVhostFiles() | |
| { | |
| mkdir -p "${WEB_DIR}/public_html" | |
| mkdir "${WEB_DIR}/logs" | |
| chown -R www-data:www-data "${WEB_DIR}" | |
| chmod 755 "${WEB_DIR}/public_html" | |
| chmod 777 "${WEB_DIR}/logs" | |
| echo "Directories created." | |
| echo "===================" | |
| } | |
| buildVhost() | |
| { | |
| echo "Creating project" | |
| echo "===================" | |
| createDirAndVhostFiles | |
| echo "Creating vHost file" | |
| echo "<VirtualHost *:80> | |
| ServerName ${vhostName}.dev | |
| DocumentRoot ${WEB_DIR}/public_html | |
| CustomLog ${WEB_DIR}/logs/access.log combined | |
| ErrorLog ${WEB_DIR}/logs/error.log | |
| </VirtualHost> | |
| <Directory ${WEB_DIR}/public_html> | |
| Options Indexes FollowSymLinks MultiViews | |
| # I Have below line from none to FileInfo | |
| AllowOverride FileInfo | |
| Order allow,deny | |
| allow from all | |
| </Directory>" > "/etc/apache2/sites-available/${vhostName}.conf" | |
| echo "vHost created" | |
| a2ensite "${vhostName}.conf" | |
| echo "vHost Actived" | |
| echo "===================" | |
| service apache2 reload | |
| } | |
| editHosts() | |
| { | |
| echo "Editing hosts" | |
| echo "127.0.0.1 ${vhostName}.dev" >> /etc/hosts | |
| echo "Done!" | |
| } | |
| init() | |
| { | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run as root!" 1>&2 | |
| exit 1 | |
| fi | |
| getVhostName | |
| buildVhost | |
| editHosts | |
| echo "Done" | |
| } | |
| init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment