once-as-root.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <<< "mariadb-server-10.0 mysql-server/root_password password \"''\""
  17. debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again 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 mariadb-server-10.0 php.xdebug
  24. info "Configure MySQL"
  25. sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mariadb.conf.d/50-server.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 "Removing default site configuration"
  50. rm /etc/nginx/sites-enabled/default
  51. echo "Done!"
  52. info "Initailize databases for MySQL"
  53. mysql -uroot <<< "CREATE DATABASE yii2basic"
  54. mysql -uroot <<< "CREATE DATABASE yii2basic_test"
  55. echo "Done!"
  56. info "Install composer"
  57. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer