lemp.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. apk add mariadb mariadb-client mariadb-common
  33. # https://bugs.alpinelinux.org/issues/9046
  34. echo -n "are Maridb databases strored in a zfs file system (eg. through proxmox container)? [y|n] "
  35. read yn
  36. if [ "$yn" = "Y" ] || [ "$yn" = "y" ]; then
  37. echo -e "Stick with mariadb 10.1.x due to incompatibility of newer version with zfs"
  38. echo -e "Please see this bug https://bugs.alpinelinux.org/issues/9046"
  39. echo "http://dl-cdn.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories
  40. # echo -e "mariadb<10.1.99\nmariadb-client<10.1.99\nmariadb-common<10.1.99" >> /etc/apk/world
  41. sed -i "s|^mariadb$|mariadb<10.1.99|g" /etc/apk/world
  42. sed -i "s|^mariadb-client$|mariadb-client<10.1.99|g" /etc/apk/world
  43. sed -i "s|^mariadb-common$|mariadb-common<10.1.99|g" /etc/apk/world
  44. apk update && apk upgrade
  45. fi
  46. mysql_install_db --user=mysql --datadir="/var/lib/mysql"
  47. rc-update add mariadb
  48. service mariadb start
  49. mysql_secure_installation
  50. sed -i "s|max_allowed_packet\s*=\s*1M|max_allowed_packet = 200M|g" /etc/mysql/my.cnf
  51. sed -i "s|max_allowed_packet\s*=\s*16M|max_allowed_packet = 200M|g" /etc/mysql/my.cnf
  52. service mariadb restart
  53. echo -e "mysql installed"
  54. echo -e '
  55. _
  56. _ __| |_ _ __
  57. | `_ \ ` \| `_ \
  58. | .__/_||_| .__/
  59. |_| |_|
  60. '
  61. echo -e "Installing PHP 7.0"
  62. sleep 3
  63. 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 php7-dom php7-tokenizer php7-iconv php7-xmlwriter php7-simplexml
  64. # to make php5 availabe
  65. # echo "http://dl-cdn.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories
  66. # apk add php5-fpm php5-pdo_mysql php5-opcache php5-curl php5-zip php5-xml php5-gd php5-mcrypt php5-phar php5-json php5-dom php5-iconv
  67. echo -e "Configuring PHP"
  68. sed -i "s/memory_limit\ =\ 128M/memory_limit = 512M/g" /etc/php7/php.ini
  69. sed -i "s/post_max_size\ =\ 8M/post_max_size = 20M/g" /etc/php7/php.ini
  70. sed -i "s/upload_max_filesize\ =\ 2M/upload_max_filesize = 20M/g" /etc/php7/php.ini
  71. TIMEZONE="Europe/Paris"
  72. sed -i "s|;*date.timezone =.*|date.timezone = ${TIMEZONE}|i" /etc/php7/php.ini
  73. sed -i "s|user = nobody|user = www|i" /etc/php7/php-fpm.d/www.conf
  74. sed -i "s|group = nobody|group = www|i" /etc/php7/php-fpm.d/www.conf
  75. rc-update add php-fpm7
  76. service php-fpm7 start
  77. echo -e "php installed"
  78. echo -e '
  79. _ __ __ _ _ _
  80. _ __| |_ _ __| \/ |_ _ /_\ __| |_ __ (_)_ _
  81. | `_ \ ` \| `_ \ |\/| | || |/ _ \/ _` | ` \| | ` \
  82. | .__/_||_| .__/_| |_|\_, /_/ \_\__,_|_|_|_|_|_||_|
  83. |_| |_| |__/
  84. '
  85. echo -e "Installing phpMyAdmin"
  86. apk add phpmyadmin php7-mysqli
  87. service php-fpm7 restart
  88. chmod +r /etc/phpmyadmin/config.inc.php
  89. # /**
  90. # * This is needed for cookie based authentication to encrypt password in
  91. # * cookie. Needs to be 32 chars long.
  92. # */
  93. _blowfish="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32)"
  94. sed -i "s|$cfg['blowfish_secret'] = ''|$cfg['blowfish_secret'] = '${_blowfish}'|i" /etc/phpmyadmin/config.inc.php
  95. mkdir /usr/share/webapps/phpmyadmin/tmp
  96. chmod 777 /usr/share/webapps/phpmyadmin/tmp
  97. # finishing the pma install after nginx
  98. echo -e '
  99. _ _
  100. _ _ ___ __| (_)___
  101. | `_/ -_) _` | (_-<
  102. |_| \___\__,_|_/__/
  103. '
  104. echo -e "Installing Redis"
  105. sleep 3
  106. apk add redis php7-pecl-redis
  107. # TODO set maxmemory=2gb
  108. # TODO set maxmemory-policy=volatile-lru
  109. # TODO comment all save line
  110. rc-update add redis
  111. service redis start
  112. service php-fpm7 restart
  113. echo -e "Redis installed"
  114. echo -e '
  115. __ ___ _ __ _ __ ___ ___ ___ _ _
  116. / _/ _ \ ` \| `_ \/ _ (_-</ -_) `_|
  117. \__\___/_|_|_| .__/\___/__/\___|_|
  118. |_|
  119. '
  120. echo -e "Installing Composer"
  121. sleep 3
  122. export COMPOSER_HOME=/usr/local/composer
  123. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  124. ln -sf /usr/local/bin/composer /usr/bin/composer
  125. composer about
  126. echo -e "Composer installed"
  127. echo -e '
  128. _ _
  129. __| |_ _ _ _ __| |_
  130. / _` | `_| || (_-< ` \
  131. \__,_|_| \_,_/__/_||_|
  132. '
  133. echo -e "Installing Drush and DrupalConsole"
  134. sleep 3
  135. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  136. chmod +x /usr/local/bin/drupal
  137. ln -sf /usr/local/bin/drupal /usr/bin/drupal
  138. drupal about
  139. # curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  140. wget -O /usr/local/bin/drush https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar
  141. chmod +x /usr/local/bin/drush
  142. ln -sf /usr/local/bin/drush /usr/bin/drush
  143. drush status
  144. echo -e "Drush and DrupalConsole installed"
  145. # for non composer installed D7 site add assets/d7-drush-composer.json in root-folder/composer.json and run composer install
  146. echo -e '
  147. _
  148. _ _ __ _(_)_ _ __ __
  149. | ` \/ _` | | ` \\ \ /
  150. |_||_\__, |_|_||_/_\_\
  151. |___/
  152. '
  153. echo -e "Installing Nginx"
  154. sleep 3
  155. apk add nginx
  156. adduser -D -g 'www' www
  157. mkdir -p /var/www/html
  158. chown -R www:www /var/lib/nginx
  159. chown -R www:www /var/www/html
  160. chown -R www:www /var/tmp/nginx
  161. sed -i "s|user nginx;|user www;|i" /etc/nginx/nginx.conf
  162. mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.ori
  163. cp "$_assets"/lemp/default.nginxconf /etc/nginx/conf.d/default.conf
  164. cp "$_assets"/lemp/index.php /var/www/html/
  165. rc-update add nginx
  166. service nginx start
  167. echo -e "Nginx installed"
  168. echo -e "securing phpMyAdmin"
  169. _pass="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c16)"
  170. _encrypted=$(openssl passwd -apr1 $_pass)
  171. echo -e "pma:$_encrypted" > /etc/nginx/passwds
  172. echo -e "phpMyAdmin installed"
  173. echo -e "You can access it at yourip/phpmyadmin"
  174. echo -e "please note the credentials user: pma passwd:$_pass"
  175. sleep 3