once-as-root.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. #== Import script args ==
  3. timezone=$(echo "$1")
  4. #== Bash helpers ==
  5. function info {
  6. echo " "
  7. echo "--> $1"
  8. echo " "
  9. }
  10. #== Provision script ==
  11. info "Provision-script user: `whoami`"
  12. export DEBIAN_FRONTEND=noninteractive
  13. info "Configure timezone"
  14. timedatectl set-timezone ${timezone} --no-ask-password
  15. info "Prepare root password for MySQL"
  16. debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password \"''\""
  17. debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password \"''\""
  18. echo "Done!"
  19. info "Update OS software"
  20. apt-get update
  21. apt-get upgrade -y
  22. info "Install additional software"
  23. apt-get install -y php7.0-curl php7.0-cli php7.0-intl php7.0-mysqlnd php7.0-gd php7.0-fpm php7.0-mbstring php7.0-xml unzip nginx mysql-server-5.7 php.xdebug
  24. info "Configure MySQL"
  25. sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
  26. mysql -uroot <<< "CREATE USER 'root'@'%' IDENTIFIED BY ''"
  27. mysql -uroot <<< "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"
  28. mysql -uroot <<< "DROP USER 'root'@'localhost'"
  29. mysql -uroot <<< "FLUSH PRIVILEGES"
  30. echo "Done!"
  31. info "Configure PHP-FPM"
  32. sed -i 's/user = www-data/user = vagrant/g' /etc/php/7.0/fpm/pool.d/www.conf
  33. sed -i 's/group = www-data/group = vagrant/g' /etc/php/7.0/fpm/pool.d/www.conf
  34. sed -i 's/owner = www-data/owner = vagrant/g' /etc/php/7.0/fpm/pool.d/www.conf
  35. cat << EOF > /etc/php/7.0/mods-available/xdebug.ini
  36. zend_extension=xdebug.so
  37. xdebug.remote_enable=1
  38. xdebug.remote_connect_back=1
  39. xdebug.remote_port=9000
  40. xdebug.remote_autostart=1
  41. EOF
  42. echo "Done!"
  43. info "Configure NGINX"
  44. sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
  45. echo "Done!"
  46. info "Enabling site configuration"
  47. ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
  48. echo "Done!"
  49. info "Initailize databases for MySQL"
  50. mysql -uroot <<< "CREATE DATABASE yii2advanced"
  51. mysql -uroot <<< "CREATE DATABASE yii2advanced_test"
  52. echo "Done!"
  53. info "Install composer"
  54. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer