lemp.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 php7.3-mysql php7.3-opcache php7.3-curl php7.3-mbstring php7.3-zip php7.3-xml php7.3-gd php-memcached php7.3-imagick php7.3-apcu
  58. # php7.3-mcrypt ??
  59. mv /etc/php/7.3/fpm/php.ini /etc/php/7.3/fpm/php.ini.back
  60. cp "$_assets"/php-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[92;1mphp installed\033[Om"
  74. echo -e '\033[35m
  75. _ __ _
  76. / | / /___ _(_)___ _ __
  77. / |/ / __ `/ / __ \| |/_/
  78. / /| / /_/ / / / / /> <
  79. /_/ |_/\__, /_/_/ /_/_/|_|
  80. /____/
  81. \033[0m'
  82. echo -e "\033[35;1mInstalling Nginx \033[0m"
  83. sleep 3
  84. apt-get --yes install nginx
  85. mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.ori
  86. cp "$_assets"/default.nginxconf /etc/nginx/sites-available/default
  87. systemctl enable nginx
  88. systemctl restart nginx
  89. echo -e "\033[92;1mNginx installed\033[Om"
  90. echo -e '\033[35m
  91. __ __ ___ ___ __ _
  92. ____ / /_ ____ / |/ /_ __/ | ____/ /___ ___ (_)___
  93. / __ \/ __ \/ __ \/ /|_/ / / / / /| |/ __ / __ `__ \/ / __ \
  94. / /_/ / / / / /_/ / / / / /_/ / ___ / /_/ / / / / / / / / / /
  95. / .___/_/ /_/ .___/_/ /_/\__, /_/ |_\__,_/_/ /_/ /_/_/_/ /_/
  96. /_/ /_/ /____/
  97. \033[0m'
  98. echo -e "\033[35;1mInstalling phpMyAdmin \033[0m"
  99. ##### Building dependency tree
  100. ##### Reading state information... Done
  101. ##### Package phpmyadmin is not available, but is referred to by another package.
  102. ##### This may mean that the package is missing, has been obsoleted, or
  103. ##### is only available from another source
  104. #####
  105. ##### E: Package 'phpmyadmin' has no installation candidate
  106. ##### cp: missing destination file operand after '/root/debian-web-server/assets/nginx-phpmyadmin.conf'
  107. ##### Try 'cp --help' for more information.
  108. # TODO no pma package available :(
  109. # apt-get --yes install phpmyadmin
  110. # ln -s /usr/share/phpmyadmin /var/www/html/
  111. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  112. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  113. # echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  114. # echo -e "\033[92;1mYou can access it at yourip/phpmyadmin\033[Om"
  115. # install from source
  116. apt-get install php-{mbstring,zip,gd,xml,pear,gettext,cgi}
  117. cd /var/www/html/
  118. wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
  119. unzip phpMyAdmin-latest-all-languages.zip
  120. mv phpMyAdmin-*-all-languages pma
  121. rm phpMyAdmin-latest-all-languages.zip
  122. # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  123. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  124. echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  125. echo -e "\033[92;1mYou can access it at yourip/pma\033[Om"
  126. echo -e '\033[35m
  127. ____ ___
  128. / __ \___ ____/ (_)____
  129. / /_/ / _ \/ __ / / ___/
  130. / _, _/ __/ /_/ / (__ )
  131. /_/ |_|\___/\__,_/_/____/
  132. \033[0m'
  133. echo -e "\033[35;1mInstalling Redis \033[0m"
  134. sleep 3
  135. apt-get --yes install redis-server php-redis
  136. # TODO set maxmemory=2gb
  137. # TODO set maxmemory-policy=volatile-lru
  138. # TODO comment all save line
  139. # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  140. # 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.
  141. # 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.
  142. # https://blog.opstree.com/2019/04/16/redis-best-practices-and-performance-tuning/
  143. systemctl enable redis-server
  144. systemctl restart redis-server
  145. systemctl restart php7.3-fpm
  146. echo -e "\033[92;1mRedis installed\033[Om"
  147. echo -e '\033[35m
  148. ______
  149. / ____/___ ____ ___ ____ ____ ________ _____
  150. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  151. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  152. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  153. /_/
  154. \033[0m'
  155. echo -e "\033[35;1mInstalling Composer \033[0m"
  156. sleep 3
  157. export COMPOSER_HOME=/usr/local/composer
  158. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  159. echo -e "\033[92;1mComposer installed\033[Om"
  160. echo -e '\033[35m
  161. ____ __
  162. / __ \_______ _______/ /_
  163. / / / / ___/ / / / ___/ __ \
  164. / /_/ / / / /_/ (__ ) / / /
  165. /_____/_/ \__,_/____/_/ /_/
  166. \033[0m'
  167. echo -e "\033[35;1mInstalling Drush and DrupalConsole\033[0m"
  168. sleep 3
  169. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  170. chmod +x /usr/local/bin/drupal
  171. # curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  172. wget -O /usr/local/bin/drush https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar
  173. chmod +x /usr/local/bin/drush
  174. echo -e "\033[92;1mDrush and DrupalConsoleinstalled\033[Om"