lemp.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/sh
  2. echo -e '\033[35m
  3. __
  4. / /__ ____ ___ ____
  5. / / _ \/ __ `__ \/ __ \
  6. / / __/ / / / / / /_/ /
  7. /_/\___/_/ /_/ /_/ .___/
  8. /_/
  9. \033[0m'
  10. echo -e "\033[35;1mLEMP server (Nginx Mysql Php-fpm) \033[0m"
  11. if [ "$EUID" -ne 0 ]; then
  12. echo "Please run as root"
  13. exit
  14. fi
  15. # get the current position
  16. _cwd="$(pwd)"
  17. # check for assets forlder
  18. _assets="$_cwd/assets"
  19. if [ ! -d "$_assets" ]; then
  20. _assets="$_cwd/../assets"
  21. if [ ! -d "$_assets" ]; then
  22. echo "!! can't find assets directory !!"
  23. exit
  24. fi
  25. fi
  26. sleep 2
  27. echo -e '\033[35m
  28. ____ __ ______
  29. / __ \/ / / / __ \
  30. / /_/ / /_/ / /_/ /
  31. / ____/ __ / ____/
  32. /_/ /_/ /_/_/
  33. \033[0m'
  34. echo -e "\033[35;1mInstalling PHP 7.4 \033[0m"
  35. sleep 3
  36. # mv: cannot stat '/etc/php/7.0/fpm/php.ini': No such file or directory
  37. # cp: cannot create regular file '/etc/php/7.0/fpm/php.ini': No such file or directory
  38. # Configuring PHP
  39. # Failed to enable unit: Unit file php7.0-fpm.service does not exist.
  40. # Failed to start php7.0-fpm.service: Unit php7.0-fpm.service not found.
  41. apt-get --yes install php7.4-fpm php7.4-mysql php7.4-opcache php7.4-curl php7.4-mbstring php7.4-zip php7.4-xml php7.4-gd php-memcached php7.4-imagick php7.4-apcu
  42. # php7.4-mcrypt ??
  43. mv /etc/php/7.4/fpm/php.ini /etc/php/7.4/fpm/php.ini.back
  44. cp "$_assets"/php7.4-fpm.ini /etc/php/7.4/fpm/php.ini
  45. echo "Configuring PHP"
  46. mkdir /var/log/php
  47. chown www-data /var/log/php
  48. cp "$_assets"/logrotate-php /etc/logrotate.d/php
  49. systemctl enable php7.4-fpm
  50. systemctl start php7.4-fpm
  51. # echo "Installing memecached"
  52. # replaced by redis
  53. # apt-get --yes install memcached
  54. # sed -i "s/-m\s64/-m 128/g" /etc/memcached.conf
  55. #
  56. # systemctl start memcached
  57. echo -e "\033[92;1mphp installed\033[Om"
  58. echo -e '\033[35m
  59. _ __ _
  60. / | / /___ _(_)___ _ __
  61. / |/ / __ `/ / __ \| |/_/
  62. / /| / /_/ / / / / /> <
  63. /_/ |_/\__, /_/_/ /_/_/|_|
  64. /____/
  65. \033[0m'
  66. echo -e "\033[35;1mInstalling Nginx \033[0m"
  67. sleep 3
  68. apt-get --yes install nginx
  69. mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.ori
  70. cp "$_assets"/default.nginxconf /etc/nginx/sites-available/default
  71. systemctl enable nginx
  72. systemctl restart nginx
  73. echo -e "\033[92;1mNginx installed\033[Om"
  74. while [ "$installmysql" != "yes" ] && [ "$installmysql" != "no" ]
  75. do
  76. echo -n "install mysql? [yes|no] "
  77. read installmysql
  78. # installmysql=${installmysql:-y}
  79. done
  80. if [ "$installmysql" = "yes" ]; then
  81. echo -e '\033[35m
  82. __ ___ __
  83. / |/ /_ ___________ _/ /
  84. / /|_/ / / / / ___/ __ `/ /
  85. / / / / /_/ (__ ) /_/ / /
  86. /_/ /_/\__, /____/\__, /_/
  87. /____/ /_/
  88. \033[0m'
  89. echo -e "\033[35;1minstalling Mysql \033[0m"
  90. sleep 3
  91. apt-get --yes install mariadb-server
  92. mysql_secure_installation
  93. cp "$_assets"/mysql/innodb-file-per-table.cnf /etc/mysql/conf.d/
  94. systemctl enable mariadb.service
  95. systemctl restart mariadb.service
  96. echo -e "\033[92;1mmysql installed\033[Om"
  97. echo -e '\033[35m
  98. __ __ ___ ___ __ _
  99. ____ / /_ ____ / |/ /_ __/ | ____/ /___ ___ (_)___
  100. / __ \/ __ \/ __ \/ /|_/ / / / / /| |/ __ / __ `__ \/ / __ \
  101. / /_/ / / / / /_/ / / / / /_/ / ___ / /_/ / / / / / / / / / /
  102. / .___/_/ /_/ .___/_/ /_/\__, /_/ |_\__,_/_/ /_/ /_/_/_/ /_/
  103. /_/ /_/ /____/
  104. \033[0m'
  105. echo -e "\033[35;1mInstalling phpMyAdmin \033[0m"
  106. ##### Building dependency tree
  107. ##### Reading state information... Done
  108. ##### Package phpmyadmin is not available, but is referred to by another package.
  109. ##### This may mean that the package is missing, has been obsoleted, or
  110. ##### is only available from another source
  111. #####
  112. ##### E: Package 'phpmyadmin' has no installation candidate
  113. ##### cp: missing destination file operand after '/root/debian-web-server/assets/nginx-phpmyadmin.conf'
  114. ##### Try 'cp --help' for more information.
  115. # TODO no pma package available :(
  116. # apt-get --yes install phpmyadmin
  117. # ln -s /usr/share/phpmyadmin /var/www/html/
  118. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  119. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  120. # echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  121. # echo -e "\033[92;1mYou can access it at yourip/phpmyadmin\033[Om"
  122. # install from source
  123. apt-get --yes install php-{mbstring,zip,gd,xml,pear,gettext,cgi}
  124. cd /var/www/html/
  125. wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
  126. unzip phpMyAdmin-latest-all-languages.zip
  127. mv phpMyAdmin-*-all-languages pma
  128. rm phpMyAdmin-latest-all-languages.zip
  129. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  130. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  131. echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  132. echo -e "\033[92;1mYou can access it at yourip/pma\033[Om"
  133. fi
  134. echo -e '\033[35m
  135. ____ ___
  136. / __ \___ ____/ (_)____
  137. / /_/ / _ \/ __ / / ___/
  138. / _, _/ __/ /_/ / (__ )
  139. /_/ |_|\___/\__,_/_/____/
  140. \033[0m'
  141. echo -e "\033[35;1mInstalling Redis \033[0m"
  142. sleep 3
  143. apt-get --yes install redis-server php-redis
  144. # TODO set maxmemory=2gb
  145. # TODO set maxmemory-policy=volatile-lru
  146. # TODO comment all save line
  147. # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  148. # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
  149. # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
  150. # https://blog.opstree.com/2019/04/16/redis-best-practices-and-performance-tuning/
  151. systemctl enable redis-server
  152. systemctl restart redis-server
  153. systemctl restart php7.4-fpm
  154. echo -e "\033[92;1mRedis installed\033[Om"
  155. echo -e '\033[35m
  156. ______
  157. / ____/___ ____ ___ ____ ____ ________ _____
  158. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  159. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  160. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  161. /_/
  162. \033[0m'
  163. echo -e "\033[35;1mInstalling Composer \033[0m"
  164. sleep 3
  165. export COMPOSER_HOME=/usr/local/composer
  166. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  167. echo -e "\033[92;1mComposer installed\033[Om"
  168. echo -e '\033[35m
  169. ____ __
  170. / __ \_______ _______/ /_
  171. / / / / ___/ / / / ___/ __ \
  172. / /_/ / / / /_/ (__ ) / / /
  173. /_____/_/ \__,_/____/_/ /_/
  174. \033[0m'
  175. echo -e "\033[35;1mInstalling Drush and DrupalConsole\033[0m"
  176. sleep 3
  177. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  178. chmod +x /usr/local/bin/drupal
  179. # curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  180. wget -O /usr/local/bin/drush https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar
  181. chmod +x /usr/local/bin/drush
  182. echo -e "\033[92;1mDrush and DrupalConsoleinstalled\033[Om"