lemp.sh 7.6 KB

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