lemp.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/sh
  2. echo -e '
  3. _
  4. | |___ _ __ _ __
  5. | / -_) ' \| '_ \
  6. |_\___|_|_|_| .__/
  7. |_|
  8. '
  9. echo -e "LEMP server (Nginx Mysql Php-fpm)"
  10. . bin/checkroot.sh
  11. # get the current position
  12. _cwd="$(pwd)"
  13. # check for assets forlder
  14. _assets="$_cwd/assets"
  15. if [ ! -d "$_assets" ]; then
  16. _assets="$_cwd/../assets"
  17. if [ ! -d "$_assets" ]; then
  18. echo "!! can't find assets directory !!"
  19. exit
  20. fi
  21. fi
  22. sleep 2
  23. echo -e '
  24. _
  25. _ __ _ _ ___ __ _| |
  26. | . \ || (_-</ _` | |
  27. |_|_|_\_, /__/\__, |_|
  28. |__/ |_|
  29. '
  30. echo -e "installing Mysql"
  31. sleep 3
  32. # https://bugs.alpinelinux.org/issues/9046
  33. echo -n "are Maridb databases strored in a zfs file system? [y|n] "
  34. read yn
  35. if [ "$yn" = "Y" ] || [ "$yn" = "y" ]; then
  36. echo -e "Stick with mariadb 10.1.x due to incompatibility of newer version with zfs"
  37. echo -e "Please see this bug https://bugs.alpinelinux.org/issues/9046"
  38. echo "http://dl-5.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories
  39. echo -e "mariadb<10.1.99\nmariadb-client<10.1.99\nmariadb-common<10.1.99" >> /etc/apk/world
  40. apk update
  41. fi
  42. apk add mariadb mariadb-client
  43. mysql_install_db --user=mysql --datadir=/var/lib/mysql
  44. rc-update add mariadb
  45. service mariadb start
  46. mysql_secure_installation
  47. sed -i "s|max_allowed_packet\s*=\s*1M|max_allowed_packet = 200M|g" /etc/mysql/my.cnf
  48. sed -i "s|max_allowed_packet\s*=\s*16M|max_allowed_packet = 200M|g" /etc/mysql/my.cnf
  49. service mariadb restart
  50. echo -e "mysql installed"
  51. echo -e '
  52. _
  53. _ __| |_ _ __
  54. | `_ \ ` \| `_ \
  55. | .__/_||_| .__/
  56. |_| |_|
  57. '
  58. echo -e "Installing PHP 7.0"
  59. sleep 3
  60. apk add php7 php7-fpm php7-pdo_mysql php7-opcache php7-curl php7-mbstring php7-zip php7-xml php7-gd php7-mcrypt php7-imagick php7-phar php7-json
  61. echo -e "Configuring PHP"
  62. sed -i "s/memory_limit\ =\ 128M/memory_limit = 512M/g" /etc/php7/php.ini
  63. TIMEZONE="Europe/Helsinki"
  64. sed -i "s|;*date.timezone =.*|date.timezone = ${TIMEZONE}|i" /etc/php7/php.ini
  65. rc-update add php-fpm7
  66. service php-fpm7 start
  67. echo -e "php installed"
  68. echo -e '
  69. _
  70. _ _ __ _(_)_ _ __ __
  71. | ` \/ _` | | ` \\ \ /
  72. |_||_\__, |_|_||_/_\_\
  73. |___/
  74. '
  75. echo -e "Installing Nginx"
  76. sleep 3
  77. apk add nginx
  78. adduser -D -g 'www' www
  79. mkdir -p /var/www/html
  80. chown -R www:www /var/lib/nginx
  81. chown -R www:www /var/www/html
  82. mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.ori
  83. cp "$_assets"/lemp/default.nginxconf /etc/nginx/conf.d/default.conf
  84. cp "$_assets"/lemp/index.php /var/www/html/
  85. rc-update add nginx
  86. service nginx start
  87. echo -e "Nginx installed"
  88. # echo -e '
  89. # _ __ __ _ _ _
  90. # _ __| |_ _ __| \/ |_ _ /_\ __| |_ __ (_)_ _
  91. # | `_ \ ` \| `_ \ |\/| | || |/ _ \/ _` | ` \| | ` \
  92. # | .__/_||_| .__/_| |_|\_, /_/ \_\__,_|_|_|_|_|_||_|
  93. # |_| |_| |__/
  94. # '
  95. # echo -e "Installing phpMyAdmin"
  96. # apk add phpmyadmin
  97. # ln -s /usr/share/phpmyadmin /var/www/html/
  98. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  99. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  100. #
  101. # # echo -e "securing phpMyAdmin"
  102. # # sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php\nAllowOverride all/"
  103. # # cp "$_assets"/phpmyadmin_htaccess > /usr/share/phpmyadmin/.htaccess
  104. # # echo -n "define a user name for phpmyadmin : "
  105. # # read un
  106. # # htpasswd -c /etc/phpmyadmin/.htpasswd $un
  107. # # service apache2 restart
  108. # echo -e "phpMyAdmin installed"
  109. # echo -e "You can access it at yourip/phpmyadmin"
  110. echo -e '
  111. _ _
  112. _ _ ___ __| (_)___
  113. | `_/ -_) _` | (_-<
  114. |_| \___\__,_|_/__/
  115. '
  116. echo -e "Installing Redis"
  117. sleep 3
  118. apk add redis php7-pecl-redis
  119. # TODO set maxmemory=2gb
  120. # TODO set maxmemory-policy=volatile-lru
  121. # TODO comment all save line
  122. rc-update add redis
  123. service redis start
  124. service php-fpm7 restart
  125. echo -e "Redis installed"
  126. echo -e '
  127. __ ___ _ __ _ __ ___ ___ ___ _ _
  128. / _/ _ \ ` \| `_ \/ _ (_-</ -_) `_|
  129. \__\___/_|_|_| .__/\___/__/\___|_|
  130. |_|
  131. '
  132. echo -e "Installing Composer"
  133. sleep 3
  134. export COMPOSER_HOME=/usr/local/composer
  135. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  136. echo -e "Composer installed"
  137. echo -e '
  138. _ _
  139. __| |_ _ _ _ __| |_
  140. / _` | `_| || (_-< ` \
  141. \__,_|_| \_,_/__/_||_|
  142. '
  143. echo -e "Installing Drush and DrupalConsole"
  144. sleep 3
  145. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  146. chmod +x /usr/local/bin/drupal
  147. curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  148. chmod +x /usr/local/bin/drush
  149. echo -e "Drush and DrupalConsoleinstalled"