lemp.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. # you may increase memory
  102. # innodb_buffer_pool_size = 1024M
  103. systemctl enable mariadb.service
  104. systemctl restart mariadb.service
  105. echo -e "\033[92;1mmysql installed\033[Om"
  106. echo -e '\033[35m
  107. __ __ ___ ___ __ _
  108. ____ / /_ ____ / |/ /_ __/ | ____/ /___ ___ (_)___
  109. / __ \/ __ \/ __ \/ /|_/ / / / / /| |/ __ / __ `__ \/ / __ \
  110. / /_/ / / / / /_/ / / / / /_/ / ___ / /_/ / / / / / / / / / /
  111. / .___/_/ /_/ .___/_/ /_/\__, /_/ |_\__,_/_/ /_/ /_/_/_/ /_/
  112. /_/ /_/ /____/
  113. \033[0m'
  114. echo -e "\033[35;1mInstalling phpMyAdmin \033[0m"
  115. ##### Building dependency tree
  116. ##### Reading state information... Done
  117. ##### Package phpmyadmin is not available, but is referred to by another package.
  118. ##### This may mean that the package is missing, has been obsoleted, or
  119. ##### is only available from another source
  120. #####
  121. ##### E: Package 'phpmyadmin' has no installation candidate
  122. ##### cp: missing destination file operand after '/root/debian-web-server/assets/nginx-phpmyadmin.conf'
  123. ##### Try 'cp --help' for more information.
  124. # TODO no pma package available :(
  125. apt-get --yes install phpmyadmin
  126. ln -s /usr/share/phpmyadmin /var/www/html/
  127. cp "$_assets"/nginx-phpmyadmin.conf /etc/nginx/sites-available/phpmyadmin.conf
  128. echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  129. echo -e "\033[92;1mYou can access it at yourip/phpmyadmin\033[Om"
  130. # install from source
  131. # apt-get --yes install php-{mbstring,zip,gd,xml,pear,gettext,cgi}
  132. # cd /var/www/html/
  133. # wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
  134. # unzip phpMyAdmin-latest-all-languages.zip
  135. # mv phpMyAdmin-*-all-languages pma
  136. # rm phpMyAdmin-latest-all-languages.zip
  137. # # cp "$_assets"/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  138. # # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  139. # echo -e "\033[92;1mphpMyAdmin installed\033[Om"
  140. # echo -e "\033[92;1mYou can access it at yourip/pma\033[Om"
  141. fi
  142. echo -e '\033[35m
  143. ____ ___
  144. / __ \___ ____/ (_)____
  145. / /_/ / _ \/ __ / / ___/
  146. / _, _/ __/ /_/ / (__ )
  147. /_/ |_|\___/\__,_/_/____/
  148. \033[0m'
  149. echo -e "\033[35;1mInstalling Redis \033[0m"
  150. sleep 3
  151. apt-get --yes install redis-server php8.1-redis
  152. # TODO set maxmemory=2gb
  153. # TODO set maxmemory-policy=volatile-lru
  154. # TODO comment all save line
  155. # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  156. # 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.
  157. # 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.
  158. # https://blog.opstree.com/2019/04/16/redis-best-practices-and-performance-tuning/
  159. systemctl enable redis-server
  160. systemctl restart redis-server
  161. systemctl restart php8.1-fpm
  162. echo -e "\033[92;1mRedis installed\033[Om"
  163. echo -e '\033[35m
  164. ______
  165. / ____/___ ____ ___ ____ ____ ________ _____
  166. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  167. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  168. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  169. /_/
  170. \033[0m'
  171. echo -e "\033[35;1mInstalling Composer \033[0m"
  172. sleep 3
  173. export COMPOSER_HOME=/usr/local/composer
  174. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  175. echo -e "\033[92;1mComposer installed\033[Om"
  176. echo -e '\033[35m
  177. ____ __
  178. / __ \_______ _______/ /_
  179. / / / / ___/ / / / ___/ __ \
  180. / /_/ / / / /_/ (__ ) / / /
  181. /_____/_/ \__,_/____/_/ /_/
  182. \033[0m'
  183. echo -e "\033[35;1mInstalling Drush\033[0m"
  184. sleep 3
  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\033[Om"