lemp.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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? [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
  64. echo -e "Configuring PHP"
  65. sed -i "s/memory_limit\ =\ 128M/memory_limit = 512M/g" /etc/php7/php.ini
  66. TIMEZONE="Europe/Helsinki"
  67. sed -i "s|;*date.timezone =.*|date.timezone = ${TIMEZONE}|i" /etc/php7/php.ini
  68. rc-update add php-fpm7
  69. service php-fpm7 start
  70. echo -e "php installed"
  71. echo -e '
  72. _ __ __ _ _ _
  73. _ __| |_ _ __| \/ |_ _ /_\ __| |_ __ (_)_ _
  74. | `_ \ ` \| `_ \ |\/| | || |/ _ \/ _` | ` \| | ` \
  75. | .__/_||_| .__/_| |_|\_, /_/ \_\__,_|_|_|_|_|_||_|
  76. |_| |_| |__/
  77. '
  78. echo -e "Installing phpMyAdmin"
  79. apk add phpmyadmin php7-mysqli
  80. service php-fpm7 restart
  81. chmod +r /etc/phpmyadmin/config.inc.php
  82. # ln -s /usr/share/phpmyadmin /var/www/html/
  83. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  84. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  85. # echo -e "securing phpMyAdmin"
  86. # sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php\nAllowOverride all/"
  87. # cp "$_assets"/phpmyadmin_htaccess > /usr/share/phpmyadmin/.htaccess
  88. # echo -n "define a user name for phpmyadmin : "
  89. # read un
  90. # htpasswd -c /etc/phpmyadmin/.htpasswd $un
  91. # service apache2 restart
  92. echo -e "phpMyAdmin installed"
  93. echo -e "You can access it at yourip/phpmyadmin"
  94. echo -e '
  95. _ _
  96. _ _ ___ __| (_)___
  97. | `_/ -_) _` | (_-<
  98. |_| \___\__,_|_/__/
  99. '
  100. echo -e "Installing Redis"
  101. sleep 3
  102. apk add redis php7-pecl-redis
  103. # TODO set maxmemory=2gb
  104. # TODO set maxmemory-policy=volatile-lru
  105. # TODO comment all save line
  106. rc-update add redis
  107. service redis start
  108. service php-fpm7 restart
  109. echo -e "Redis installed"
  110. echo -e '
  111. __ ___ _ __ _ __ ___ ___ ___ _ _
  112. / _/ _ \ ` \| `_ \/ _ (_-</ -_) `_|
  113. \__\___/_|_|_| .__/\___/__/\___|_|
  114. |_|
  115. '
  116. echo -e "Installing Composer"
  117. sleep 3
  118. export COMPOSER_HOME=/usr/local/composer
  119. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  120. echo -e "Composer installed"
  121. echo -e '
  122. _ _
  123. __| |_ _ _ _ __| |_
  124. / _` | `_| || (_-< ` \
  125. \__,_|_| \_,_/__/_||_|
  126. '
  127. echo -e "Installing Drush and DrupalConsole"
  128. sleep 3
  129. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  130. chmod +x /usr/local/bin/drupal
  131. curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  132. chmod +x /usr/local/bin/drush
  133. echo -e "Drush and DrupalConsoleinstalled"
  134. echo -e '
  135. _
  136. _ _ __ _(_)_ _ __ __
  137. | ` \/ _` | | ` \\ \ /
  138. |_||_\__, |_|_||_/_\_\
  139. |___/
  140. '
  141. echo -e "Installing Nginx"
  142. sleep 3
  143. apk add nginx
  144. adduser -D -g 'www' www
  145. mkdir -p /var/www/html
  146. chown -R www:www /var/lib/nginx
  147. chown -R www:www /var/www/html
  148. mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.ori
  149. cp "$_assets"/lemp/default.nginxconf /etc/nginx/conf.d/default.conf
  150. cp "$_assets"/lemp/index.php /var/www/html/
  151. rc-update add nginx
  152. service nginx start
  153. echo -e "Nginx installed"