lemp.sh 7.8 KB

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