lemp.sh 7.9 KB

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