lemp.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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
  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. systemctl enable redis-server
  140. systemctl restart redis-server
  141. systemctl restart php7.0-fpm
  142. echo -e "\033[92;1mRedis installed\033[Om"
  143. echo -e '\033[35m
  144. ______
  145. / ____/___ ____ ___ ____ ____ ________ _____
  146. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  147. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  148. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  149. /_/
  150. \033[0m'
  151. echo -e "\033[35;1mInstalling Composer \033[0m"
  152. sleep 3
  153. export COMPOSER_HOME=/usr/local/composer
  154. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  155. echo -e "\033[92;1mComposer installed\033[Om"
  156. echo -e '\033[35m
  157. ____ __
  158. / __ \_______ _______/ /_
  159. / / / / ___/ / / / ___/ __ \
  160. / /_/ / / / /_/ (__ ) / / /
  161. /_____/_/ \__,_/____/_/ /_/
  162. \033[0m'
  163. echo -e "\033[35;1mInstalling Drush and DrupalConsole\033[0m"
  164. sleep 3
  165. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  166. chmod +x /usr/local/bin/drupal
  167. curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  168. chmod +x /usr/local/bin/drush
  169. echo -e "\033[92;1mDrush and DrupalConsoleinstalled\033[Om"
  170. # TODO supervising
  171. # echo -e '\033[35m
  172. # __ ___ _ __ __ __ ___ _
  173. # / |/ /__ ___ (_) /_ _/_/ / |/ /_ _____ (_)__
  174. # / /|_/ / _ \/ _ \/ / __/ _/_/ / /|_/ / // / _ \/ / _ \
  175. # /_/ /_/\___/_//_/_/\__/ /_/ /_/ /_/\_,_/_//_/_/_//_/
  176. # \033[0m'
  177. # echo -e "\033[35;1mInstalling Munin \033[0m"
  178. # sleep 3
  179. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/
  180. # apt-get --yes install munin munin-node munin-plugins-extra
  181. # # Configure Munin
  182. # # enable plugins
  183. # ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_
  184. # ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
  185. # ln -s /usr/share/munin/plugins/mysql_innodb /etc/munin/plugins/mysql_innodb
  186. # ln -s /usr/share/munin/plugins/mysql_isam_space_ /etc/munin/plugins/mysql_isam_space_
  187. # ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
  188. # ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
  189. # ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads
  190. #
  191. # ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/
  192. # ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/
  193. # ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/
  194. #
  195. # # ln -s /usr/share/munin/plugins/fail2ban /etc/munin/plugins/
  196. #
  197. # # dbdir, htmldir, logdir, rundir, and tmpldir
  198. # sed -i 's/^#dbdir/dbdir/' /etc/munin/munin.conf
  199. # sed -i 's/^#htmldir/htmldir/' /etc/munin/munin.conf
  200. # sed -i 's/^#logdir/logdir/' /etc/munin/munin.conf
  201. # sed -i 's/^#rundir/rundir/' /etc/munin/munin.conf
  202. # sed -i 's/^#tmpldir/tmpldir/' /etc/munin/munin.conf
  203. #
  204. # sed -i "s/^\[localhost.localdomain\]/[${HOSTNAME}]/" /etc/munin/munin.conf
  205. #
  206. # # ln -s /etc/munin/apache24.conf /etc/apache2/conf-enabled/munin.conf
  207. # sed -i 's/Require local/Require all granted\nOptions FollowSymLinks SymLinksIfOwnerMatch/g' /etc/munin/apache24.conf
  208. # htpasswd -c /etc/munin/munin-htpasswd admin
  209. # sed -i 's/Require all granted/AuthUserFile \/etc\/munin\/munin-htpasswd\nAuthName "Munin"\nAuthType Basic\nRequire valid-user/g' /etc/munin/apache24.conf
  210. #
  211. #
  212. # service apache2 restart
  213. # service munin-node restart
  214. # echo -e "\033[92;1mMunin installed\033[Om"
  215. #
  216. # echo -e "\033[35;1mInstalling Monit \033[0m"
  217. # sleep 3
  218. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/2/
  219. # apt-get --yes install monit
  220. # # TODO setup monit rc
  221. # cat "$_assets"/monitrc > /etc/monit/monitrc
  222. #
  223. # # TODO setup webaccess
  224. # passok=0
  225. # while [ "$passok" = "0" ]
  226. # do
  227. # echo -n "Write web access password to monit"
  228. # read passwda
  229. # echo -n "ReWrite web access password to monit"
  230. # read passwdb
  231. # if [ "$passwda" = "$passwdb" ]; then
  232. # sed -i 's/PASSWD_TO_REPLACE/$passwda/g' /etc/monit/monitrc
  233. # passok=1
  234. # else
  235. # echo "pass words don't match, please try again"
  236. # fi
  237. # done
  238. #
  239. # # TODO setup mail settings
  240. # sed -i "s/server1\.example\.com/$HOSTNAME/g" /etc/monit/monitrc
  241. #
  242. # mkdir /var/www/html/monit
  243. # echo "hello" > /var/www/html/monit/token
  244. #
  245. # service monit start
  246. #
  247. # echo -e "\033[92;1mMonit installed\033[Om"
  248. # echo -e '\033[35m
  249. # ___ __ __
  250. # / |_ _______/ /_____ _/ /_
  251. # / /| | | /| / / ___/ __/ __ `/ __/
  252. # / ___ | |/ |/ (__ ) /_/ /_/ / /_
  253. # /_/ |_|__/|__/____/\__/\__,_/\__/
  254. # \033[0m'
  255. # echo -e "\033[35;1mInstalling Awstat \033[0m"
  256. # sleep 3
  257. # apt-get --yes install awstats
  258. # # Configure AWStats
  259. # temp=`grep -i sitedomain /etc/awstats/awstats.conf.local | wc -l`
  260. # if [ $temp -lt 1 ]; then
  261. # echo SiteDomain="$_domain" >> /etc/awstats/awstats.conf.local
  262. # fi
  263. # # Disable Awstats from executing every 10 minutes. Put a hash in front of any line.
  264. # sed -i 's/^[^#]/#&/' /etc/cron.d/awstats
  265. # echo -e "\033[92;1mAwstat installed\033[Om"