Last active
April 26, 2017 19:54
-
-
Save adampiotrowski/f77e25ad7095a9e69e18 to your computer and use it in GitHub Desktop.
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 | |
| # Usage: ./upcloud.sh domain.com preferred_mysql_root_password | |
| # Setup variables | |
| DOMAIN=$1 | |
| MYSQL_PASSWORD=$2 | |
| SITES_ENABLED='/etc/apache2/sites-enabled/' | |
| SITES_AVAILABLE='/etc/apache2/sites-available/' | |
| USER_DIR='/var/www/domains/' | |
| SITES_AVAILABLE_DOMAIN=$SITES_AVAILABLE$DOMAIN.conf | |
| ADMIN_MAIL='admin@localhost.com' | |
| # Add repositories | |
| echo deb http://apt.newrelic.com/debian/ newrelic non-free >> /etc/apt/sources.list.d/newrelic.list | |
| wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add - | |
| sudo add-apt-repository ppa:ondrej/php -y | |
| sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db | |
| sudo add-apt-repository 'deb http://mariadb.kisiek.net//repo/10.0/ubuntu trusty main' | |
| # Update & Upgrade | |
| sudo apt-get update | |
| sudo apt-get -y upgrade | |
| sudo apt-get -y dist-upgrade | |
| # Set non-interactive mode | |
| export DEBIAN_FRONTEND="noninteractive" | |
| sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $MYSQL_PASSWORD" | |
| sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $MYSQL_PASSWORD" | |
| # Install software | |
| sudo apt-get install -y software-properties-common htop ntp rsync unzip mc git mysqltuner newrelic-sysmond mariadb-server libxrender1 | |
| sudo apt-get install -y php7.0 php-xml php-mbstring php-mysql php-gd php-mcrypt php-intl php-cli php-curl php-bz2 php-soap | |
| sudo apt-get install -y apache2 libapache2-mod-php | |
| sudo service apache2 restart | |
| # Create vhost | |
| sudo mkdir -p "${USER_DIR}${DOMAIN}" | |
| sudo chmod -R 755 "${USER_DIR}${DOMAIN}" | |
| sudo chown -R www-data:www-data "${USER_DIR}${DOMAIN}" | |
| if ! echo " | |
| <VirtualHost *:80> | |
| ServerAdmin $ADMIN_MAIL | |
| ServerName $DOMAIN | |
| ServerAlias www.$DOMAIN | |
| DocumentRoot $USER_DIR$DOMAIN/web | |
| <Directory $USER_DIR$DOMAIN/web/> | |
| Options Indexes FollowSymLinks MultiViews | |
| AllowOverride All | |
| Order allow,deny | |
| allow from all | |
| </Directory> | |
| ErrorLog /var/log/apache2/$DOMAIN-error.log | |
| LogLevel error | |
| CustomLog /var/log/apache2/$DOMAIN-access.log combined | |
| </VirtualHost>" > $SITES_AVAILABLE_DOMAIN | |
| then | |
| echo -e $"There is an ERROR creating $DOMAIN file" | |
| exit; | |
| else | |
| echo -e $"\nNew Virtual Host Created\n" | |
| fi | |
| sudo a2ensite $DOMAIN | |
| sudo service apache2 restart | |
| # Run MySQL install scripts | |
| sudo mysql_secure_installation | |
| sudo service mysql start | |
| # Enable modules and start Apache | |
| a2enmod actions alias rewrite headers | |
| sudo service apache2 restart | |
| # Synchronize clock | |
| sudo dpkg-reconfigure tzdata | |
| sudo ntpdate pool.ntp.org | |
| sudo service ntp start | |
| # Init NewRelic | |
| nrsysmond-config --set license_key=d1e9184a7654a0172e6e3e960da361f6ec81ea8c | |
| /etc/init.d/newrelic-sysmond start | |
| # Finish | |
| sudo service apache2 restart | |
| # Install Composer globally | |
| curl -s https://getcomposer.org/installer | php | |
| mv composer.phar /usr/local/bin/composer | |
| echo -e $"Complete! \nYou now have a new Virtual Host \nYour new host is: http://$DOMAIN \nAnd its located at $USER_DIR$DOMAIN" | |
| exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment