lemp.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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
  33. # https://bugs.alpinelinux.org/issues/9046
  34. DB_DATA_PATH="/var/lib/mysql"
  35. DB_ROOT_PASS="mariadb_root_password"
  36. DB_USER="mariadb_user"
  37. DB_PASS="mariadb_user_password"
  38. MAX_ALLOWED_PACKET="200M"
  39. mysql_install_db --user=mysql --datadir=${DB_DATA_PATH}
  40. rc-update add mariadb
  41. service mariadb start
  42. echo -e "mysql installed"
  43. echo -e '
  44. _
  45. _ __| |_ _ __
  46. | `_ \ ` \| `_ \
  47. | .__/_||_| .__/
  48. |_| |_|
  49. '
  50. echo -e "Installing PHP 7.0"
  51. sleep 3
  52. apk add php7 php7-fpm php7-pdo_mysql php7-opcache php7-curl php7-mbstring php7-zip php7-xml php7-gd php7-mcrypt php7-imagick
  53. echo -e "Configuring PHP"
  54. sed -i "s/memory_limit\ =\ 128M/memory_limit = 512M/g" /etc/php7/php.ini
  55. TIMEZONE="Europe/Helsinki"
  56. sed -i "s|;*date.timezone =.*|date.timezone = ${TIMEZONE}|i" /etc/php7/php.ini
  57. rc-update add php-fpm7
  58. service php-fpm7 start
  59. echo -e "php installed"
  60. echo -e '
  61. _
  62. _ _ __ _(_)_ _ __ __
  63. | ` \/ _` | | ` \\ \ /
  64. |_||_\__, |_|_||_/_\_\
  65. |___/
  66. '
  67. echo -e "Installing Nginx"
  68. sleep 3
  69. apk add nginx
  70. adduser -D -g 'www' www
  71. mkdir -p /var/www/html
  72. chown -R www:www /var/lib/nginx
  73. chown -R www:www /var/www/html
  74. mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.ori
  75. cp "$_assets"/default.nginxconf /etc/nginx/conf.d/default.conf
  76. cp "$_assets"/index.php /var/www/html/
  77. rc-update add nginx
  78. service nginx start
  79. echo -e "Nginx installed"
  80. # echo -e '
  81. # _ __ __ _ _ _
  82. # _ __| |_ _ __| \/ |_ _ /_\ __| |_ __ (_)_ _
  83. # | `_ \ ` \| `_ \ |\/| | || |/ _ \/ _` | ` \| | ` \
  84. # | .__/_||_| .__/_| |_|\_, /_/ \_\__,_|_|_|_|_|_||_|
  85. # |_| |_| |__/
  86. # '
  87. # echo -e "Installing phpMyAdmin"
  88. # apk add phpmyadmin
  89. # ln -s /usr/share/phpmyadmin /var/www/html/
  90. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  91. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  92. #
  93. # # echo -e "securing phpMyAdmin"
  94. # # sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php\nAllowOverride all/"
  95. # # cp "$_assets"/phpmyadmin_htaccess > /usr/share/phpmyadmin/.htaccess
  96. # # echo -n "define a user name for phpmyadmin : "
  97. # # read un
  98. # # htpasswd -c /etc/phpmyadmin/.htpasswd $un
  99. # # service apache2 restart
  100. # echo -e "phpMyAdmin installed"
  101. # echo -e "You can access it at yourip/phpmyadmin"
  102. echo -e '
  103. ____ ___
  104. / __ \___ ____/ (_)____
  105. / /_/ / _ \/ __ / / ___/
  106. / _, _/ __/ /_/ / (__ )
  107. /_/ |_|\___/\__,_/_/____/
  108. '
  109. echo -e "Installing Redis"
  110. sleep 3
  111. apk add redis-server php-redis
  112. # TODO set maxmemory=2gb
  113. # TODO set maxmemory-policy=volatile-lru
  114. # TODO comment all save line
  115. systemctl enable redis-server
  116. systemctl restart redis-server
  117. systemctl restart php7.0-fpm
  118. echo -e "Redis installed"
  119. echo -e '
  120. ______
  121. / ____/___ ____ ___ ____ ____ ________ _____
  122. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  123. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  124. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  125. /_/
  126. '
  127. echo -e "Installing Composer"
  128. sleep 3
  129. export COMPOSER_HOME=/usr/local/composer
  130. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  131. echo -e "Composer installed"
  132. echo -e '
  133. ____ __
  134. / __ \_______ _______/ /_
  135. / / / / ___/ / / / ___/ __ \
  136. / /_/ / / / /_/ (__ ) / / /
  137. /_____/_/ \__,_/____/_/ /_/
  138. '
  139. echo -e "Installing Drush and DrupalConsole"
  140. sleep 3
  141. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  142. chmod +x /usr/local/bin/drupal
  143. curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  144. chmod +x /usr/local/bin/drush
  145. echo -e "Drush and DrupalConsoleinstalled"
  146. # TODO supervising
  147. # echo -e '
  148. # __ ___ _ __ __ __ ___ _
  149. # / |/ /__ ___ (_) /_ _/_/ / |/ /_ _____ (_)__
  150. # / /|_/ / _ \/ _ \/ / __/ _/_/ / /|_/ / // / _ \/ / _ \
  151. # /_/ /_/\___/_//_/_/\__/ /_/ /_/ /_/\_,_/_//_/_/_//_/
  152. #'
  153. # echo -e "Installing Munin"
  154. # sleep 3
  155. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/
  156. # apt-get --yes --force-yes install munin munin-node munin-plugins-extra
  157. # # Configure Munin
  158. # # enable plugins
  159. # ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_
  160. # ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
  161. # ln -s /usr/share/munin/plugins/mysql_innodb /etc/munin/plugins/mysql_innodb
  162. # ln -s /usr/share/munin/plugins/mysql_isam_space_ /etc/munin/plugins/mysql_isam_space_
  163. # ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
  164. # ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
  165. # ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads
  166. #
  167. # ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/
  168. # ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/
  169. # ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/
  170. #
  171. # # ln -s /usr/share/munin/plugins/fail2ban /etc/munin/plugins/
  172. #
  173. # # dbdir, htmldir, logdir, rundir, and tmpldir
  174. # sed -i 's/^#dbdir/dbdir/' /etc/munin/munin.conf
  175. # sed -i 's/^#htmldir/htmldir/' /etc/munin/munin.conf
  176. # sed -i 's/^#logdir/logdir/' /etc/munin/munin.conf
  177. # sed -i 's/^#rundir/rundir/' /etc/munin/munin.conf
  178. # sed -i 's/^#tmpldir/tmpldir/' /etc/munin/munin.conf
  179. #
  180. # sed -i "s/^\[localhost.localdomain\]/[${HOSTNAME}]/" /etc/munin/munin.conf
  181. #
  182. # # ln -s /etc/munin/apache24.conf /etc/apache2/conf-enabled/munin.conf
  183. # sed -i 's/Require local/Require all granted\nOptions FollowSymLinks SymLinksIfOwnerMatch/g' /etc/munin/apache24.conf
  184. # htpasswd -c /etc/munin/munin-htpasswd admin
  185. # sed -i 's/Require all granted/AuthUserFile \/etc\/munin\/munin-htpasswd\nAuthName "Munin"\nAuthType Basic\nRequire valid-user/g' /etc/munin/apache24.conf
  186. #
  187. #
  188. # service apache2 restart
  189. # service munin-node restart
  190. # echo -e "Munin installed"
  191. #
  192. # echo -e "Installing Monit"
  193. # sleep 3
  194. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/2/
  195. # apt-get --yes --force-yes install monit
  196. # # TODO setup monit rc
  197. # cat "$_assets"/monitrc > /etc/monit/monitrc
  198. #
  199. # # TODO setup webaccess
  200. # passok=0
  201. # while [ "$passok" = "0" ]
  202. # do
  203. # echo -n "Write web access password to monit"
  204. # read passwda
  205. # echo -n "ReWrite web access password to monit"
  206. # read passwdb
  207. # if [ "$passwda" = "$passwdb" ]; then
  208. # sed -i 's/PASSWD_TO_REPLACE/$passwda/g' /etc/monit/monitrc
  209. # passok=1
  210. # else
  211. # echo -e "pass words don't match, please try again"
  212. # fi
  213. # done
  214. #
  215. # # TODO setup mail settings
  216. # sed -i "s/server1\.example\.com/$HOSTNAME/g" /etc/monit/monitrc
  217. #
  218. # mkdir /var/www/html/monit
  219. # echo -e "hello" > /var/www/html/monit/token
  220. #
  221. # service monit start
  222. #
  223. # echo -e "Monit installed"
  224. # echo -e '
  225. # ___ __ __
  226. # / |_ _______/ /_____ _/ /_
  227. # / /| | | /| / / ___/ __/ __ `/ __/
  228. # / ___ | |/ |/ (__ ) /_/ /_/ / /_
  229. # /_/ |_|__/|__/____/\__/\__,_/\__/
  230. #'
  231. # echo -e "Installing Awstat"
  232. # sleep 3
  233. # apt-get --yes --force-yes install awstats
  234. # # Configure AWStats
  235. # temp=`grep -i sitedomain /etc/awstats/awstats.conf.local | wc -l`
  236. # if [ $temp -lt 1 ]; then
  237. # echo SiteDomain="$_domain" >> /etc/awstats/awstats.conf.local
  238. # fi
  239. # # Disable Awstats from executing every 10 minutes. Put a hash in front of any line.
  240. # sed -i 's/^[^#]/#&/' /etc/cron.d/awstats
  241. # echo -e "Awstat installed"