lemp.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. /____/ /_/
  34. \033[0m'
  35. echo -e "\033[35;1minstalling Mysql \033[0m"
  36. sleep 3
  37. apt-get --yes install mariadb-server
  38. mysql_secure_installation
  39. cp "$_assets"/mysql/innodb-file-per-table.cnf /etc/mysql/conf.d/
  40. systemctl enable mariadb.service
  41. systemctl restart mariadb.service
  42. echo -e "\033[92;1mmysql installed\033[Om"
  43. echo -e '\033[35m
  44. ____ __ ______
  45. / __ \/ / / / __ \
  46. / /_/ / /_/ / /_/ /
  47. / ____/ __ / ____/
  48. /_/ /_/ /_/_/
  49. \033[0m'
  50. echo -e "\033[35;1mInstalling PHP 7.3 \033[0m"
  51. sleep 3
  52. # mv: cannot stat '/etc/php/7.0/fpm/php.ini': No such file or directory
  53. # cp: cannot create regular file '/etc/php/7.0/fpm/php.ini': No such file or directory
  54. # Configuring PHP
  55. # Failed to enable unit: Unit file php7.0-fpm.service does not exist.
  56. # Failed to start php7.0-fpm.service: Unit php7.0-fpm.service not found.
  57. apt-get --yes install php7.3-{fpm,mysql,opcache,curl,mbstring,zip,xml,gd,imagick,apcu} php-memcached
  58. # php7.3-mcrypt ??
  59. mv /etc/php/7.3/fpm/php.ini /etc/php/7.3/fpm/php.ini.back
  60. cp "$_assets"/php7.3-fpm.ini /etc/php/7.3/fpm/php.ini
  61. echo "Configuring PHP"
  62. mkdir /var/log/php
  63. chown www-data /var/log/php
  64. cp "$_assets"/logrotate-php /etc/logrotate.d/php
  65. systemctl enable php7.3-fpm
  66. systemctl start php7.3-fpm
  67. # echo "Installing memecached"
  68. # replaced by redis
  69. # apt-get --yes install memcached
  70. # sed -i "s/-m\s64/-m 128/g" /etc/memcached.conf
  71. #
  72. # systemctl start memcached
  73. echo -e "\033[35;1mInstalling PHP 7.4 \033[0m"
  74. apt-get -y install lsb-release apt-transport-https ca-certificates
  75. wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
  76. echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
  77. apt-get update
  78. apt-get -y install php7.4 php7.4-{fpm,mysql,opcache,curl,mbstring,zip,xml,gd,imagick,apcu}
  79. mv /etc/php/7.4/fpm/php.ini /etc/php/7.4/fpm/php.ini.back
  80. cp "$_assets"/php7.4-fpm.ini /etc/php/7.4/fpm/php.ini
  81. systemctl enable php7.4-fpm
  82. systemctl start php7.4-fpm
  83. echo -e "\033[92;1mphp installed\033[Om"
  84. echo -e '\033[35m
  85. _ __ _
  86. / | / /___ _(_)___ _ __
  87. / |/ / __ `/ / __ \| |/_/
  88. / /| / /_/ / / / / /> <
  89. /_/ |_/\__, /_/_/ /_/_/|_|
  90. /____/
  91. \033[0m'
  92. echo -e "\033[35;1mInstalling Nginx \033[0m"
  93. sleep 3
  94. apt-get --yes install nginx
  95. mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.ori
  96. cp "$_assets"/default.nginxconf /etc/nginx/sites-available/default
  97. systemctl enable nginx
  98. systemctl restart nginx
  99. echo -e "\033[92;1mNginx installed\033[Om"
  100. echo -e '\033[35m
  101. __ __ ___ ___ __ _
  102. ____ / /_ ____ / |/ /_ __/ | ____/ /___ ___ (_)___
  103. / __ \/ __ \/ __ \/ /|_/ / / / / /| |/ __ / __ `__ \/ / __ \
  104. / /_/ / / / / /_/ / / / / /_/ / ___ / /_/ / / / / / / / / / /
  105. / .___/_/ /_/ .___/_/ /_/\__, /_/ |_\__,_/_/ /_/ /_/_/_/ /_/
  106. /_/ /_/ /____/
  107. \033[0m'
  108. echo -e "\033[35;1mInstalling phpMyAdmin \033[0m"
  109. ##### Building dependency tree
  110. ##### Reading state information... Done
  111. ##### Package phpmyadmin is not available, but is referred to by another package.
  112. ##### This may mean that the package is missing, has been obsoleted, or
  113. ##### is only available from another source
  114. #####
  115. ##### E: Package 'phpmyadmin' has no installation candidate
  116. ##### cp: missing destination file operand after '/root/debian-web-server/assets/nginx-phpmyadmin.conf'
  117. ##### Try 'cp --help' for more information.
  118. # TODO no pma package available :(
  119. # apt-get --yes install phpmyadmin
  120. # ln -s /usr/share/phpmyadmin /var/www/html/
  121. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  122. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  123. # echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  124. # echo -e "\033[92;1mYou can access it at yourip/phpmyadmin\033[Om"
  125. # install from source
  126. apt-get --yes install php-{mbstring,zip,gd,xml,pear,gettext,cgi}
  127. cd /var/www/html/
  128. wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
  129. unzip phpMyAdmin-latest-all-languages.zip
  130. mv phpMyAdmin-*-all-languages pma
  131. rm phpMyAdmin-latest-all-languages.zip
  132. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  133. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  134. echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  135. echo -e "\033[92;1mYou can access it at yourip/pma\033[Om"
  136. echo -e '\033[35m
  137. ____ ___
  138. / __ \___ ____/ (_)____
  139. / /_/ / _ \/ __ / / ___/
  140. / _, _/ __/ /_/ / (__ )
  141. /_/ |_|\___/\__,_/_/____/
  142. \033[0m'
  143. echo -e "\033[35;1mInstalling Redis \033[0m"
  144. sleep 3
  145. apt-get --yes install redis-server php-redis
  146. # TODO set maxmemory=2gb
  147. # TODO set maxmemory-policy=volatile-lru
  148. # TODO comment all save line
  149. # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  150. # 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.
  151. # 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.
  152. # https://blog.opstree.com/2019/04/16/redis-best-practices-and-performance-tuning/
  153. systemctl enable redis-server
  154. systemctl restart redis-server
  155. systemctl restart php7.3-fpm
  156. echo -e "\033[92;1mRedis installed\033[Om"
  157. echo -e '\033[35m
  158. ______
  159. / ____/___ ____ ___ ____ ____ ________ _____
  160. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  161. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  162. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  163. /_/
  164. \033[0m'
  165. echo -e "\033[35;1mInstalling Composer \033[0m"
  166. sleep 3
  167. export COMPOSER_HOME=/usr/local/composer
  168. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  169. echo -e "\033[92;1mComposer installed\033[Om"
  170. echo -e '\033[35m
  171. ____ __
  172. / __ \_______ _______/ /_
  173. / / / / ___/ / / / ___/ __ \
  174. / /_/ / / / /_/ (__ ) / / /
  175. /_____/_/ \__,_/____/_/ /_/
  176. \033[0m'
  177. echo -e "\033[35;1mInstalling Drush and DrupalConsole\033[0m"
  178. sleep 3
  179. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  180. chmod +x /usr/local/bin/drupal
  181. # curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  182. wget -O /usr/local/bin/drush https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar
  183. chmod +x /usr/local/bin/drush
  184. echo -e "\033[92;1mDrush and DrupalConsoleinstalled\033[Om"