{"id":94,"date":"2018-09-19T23:37:02","date_gmt":"2018-09-19T15:37:02","guid":{"rendered":"https:\/\/twmis.com\/?p=94"},"modified":"2024-10-10T15:01:16","modified_gmt":"2024-10-10T07:01:16","slug":"debian-9-%e5%ae%89%e8%a3%9d-nginx-php7-mariadb","status":"publish","type":"post","link":"https:\/\/twmis.com\/?p=94","title":{"rendered":"Debian 9 \u5b89\u88dd Nginx PHP7 Mariadb&#8230;"},"content":{"rendered":"<p>Debian 9 \u5b89\u88dd Nginx PHP7 Mariadb&#8230;<\/p>\n<p><!--more--><\/p>\n<p>1.\u66f4\u6539\u6642\u5340<\/p>\n<p>timedatectl set-timezone Asia\/Taipei<\/p>\n<p>2.Update &amp;&amp; Upgrade<br \/>\napt-get -y update &amp;&amp; apt-get upgrade -y<\/p>\n<p>3.\u5b89\u88dd\u57fa\u672c\u5957\u4ef6<br \/>\napt-get install -y openssl ssl-cert php7.0 php7.0-curl php7.0-gd php7.0-fpm php7.0-cli<br \/>\nphp7.0-opcache php7.0-mbstring php7.0-xml php7.0-zip php7.0-mysql php7.0-mcrypt bzip2 nginx mariadb-server mariadb-client<\/p>\n<p>sed -i &#8216;s\/;cgi.fix_pathinfo=1\/cgi.fix_pathinfo=0\/&#8217; \/etc\/php\/7.0\/fpm\/php.ini<\/p>\n<p>4.\u8a2d\u5b9a\u4e26\u9a57\u8b49 Mariadb<br \/>\nmysql_secure_installation<\/p>\n<p>mysql -u root -p<br \/>\nshow databases; #\u6aa2\u67e5\u76ee\u524d\u7684\u8cc7\u6599\u5eab\u9805\u76ee<br \/>\nexit #\u96e2\u958b<\/p>\n<p>5.\u65b0\u589e\u8cc7\u6599\u5eab<br \/>\nCREATE DATABASE wordpress;<\/p>\n<p>6.\u8cc7\u6599\u5eab\u6b0a\u9650<br \/>\nGRANT ALL PRIVILEGES ON wordpress.* TO root@localhost IDENTIFIED BY &#8216;password&#8217;;<\/p>\n<p>7.\u8cc7\u6599\u5eab\u8a2d\u5b9a\u751f\u6548<br \/>\nFLUSH PRIVILEGES;<\/p>\n<p>8.\u5efa\u7acb SSL<br \/>\nmkdir -p \/var\/www\/html\/ssl<br \/>\ncd \/var\/www\/html\/ssl<br \/>\nopenssl req -new -x509 -days 365 -nodes -out \/var\/www\/html\/ssl\/xxx.crt -keyout \/var\/www\/html\/ssl\/xxx.key<br \/>\nchmod 600 xxx.crt<br \/>\nchmod 600 xxx.key<\/p>\n<p>9.\u8a2d\u5b9a\u7ad9\u9ede\u6b0a\u9650\u70bawww-date;<br \/>\nchown -R www-data:www-data \/var\/www<\/p>\n<p>10.\u5efa\u7acb\u7ad9\u9ede<\/p>\n<p>nano \/etc\/nginx\/conf.d\/xxx.conf<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name xxx.com;<br \/>\nrewrite ^(.*) https:\/\/$server_name$1 permanent;<br \/>\n}<\/p>\n<p>server {<br \/>\nlisten 443;<br \/>\nserver_name xxx.com;<br \/>\nssl on;<\/p>\n<p>#SSL Certificate you created<br \/>\nssl_certificate \/var\/www\/html\/ssl\/xxx.crt;<br \/>\nssl_certificate_key \/var\/www\/html\/ssl\/xxx.key;<\/p>\n<p>location \/ {<br \/>\nroot \/var\/www\/html\/xxx.com;<br \/>\nindex index.php index.html index.htm;<br \/>\n}<\/p>\n<p>error_page 500 502 503 504 \/50x.html;<br \/>\nlocation = \/50x.html {<br \/>\nroot html;<br \/>\n}<\/p>\n<p>location ~ \\.php$ {<br \/>\nroot \/var\/www\/html\/xxx.com;<br \/>\ntry_files $uri =404;<br \/>\nfastcgi_split_path_info ^(.+\\.php)(\/.+)$;<br \/>\nfastcgi_pass unix:\/var\/run\/php\/php7.0-fpm.sock;<br \/>\nfastcgi_index index.php;<br \/>\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>\ninclude fastcgi_params;<br \/>\n}<br \/>\n}<\/p>\n<p>11.Install vsftpd<br \/>\napt-get install -y vsftpd<\/p>\n<p>nano \/etc\/vsftpd.conf<br \/>\nanonymous_enable=No<br \/>\nlocal_enable=YES<br \/>\nwrite_enable=YES<\/p>\n<p>nano \/etc\/ftpusers<br \/>\n#root<\/p>\n<p>12.iptables \u8a2d\u5b9a<br \/>\nnano \/etc\/firewall.server #\u5efa\u7acb\u898f\u5247<\/p>\n<p>##############################################################<br \/>\n# http port 80<br \/>\niptables -A INPUT -i venet0 -p tcp &#8211;dport 80 -j ACCEPT<\/p>\n<p># https port 443<br \/>\niptables -A INPUT -i venet0 -p tcp &#8211;dport 443 -j ACCEPT<\/p>\n<p># vsftpd port 21<br \/>\niptables -A INPUT -i venet0 -p tcp &#8211;dport 21 -j ACCEPT<\/p>\n<p># pptpd prot 1723<br \/>\niptables -A INPUT -p tcp &#8211;dport 1723 -j ACCEPT<br \/>\niptables -A OUTPUT -p tcp &#8211;sport 1723 -j ACCEPT<br \/>\niptables -A INPUT -p gre -j ACCEPT<br \/>\niptables -A OUTPUT -p gre -j ACCEPT<br \/>\n# NAT<br \/>\niptables -t nat -A POSTROUTING -s 192.168.0.0\/24 -o eth0 -j SNAT &#8211;to-source x.x.x.x<br \/>\niptables -A FORWARD -i ppp+ -j ACCEPT<br \/>\niptables -A FORWARD -o ppp+ -j ACCEPT<br \/>\niptables -A POSTROUTING -t nat -o ppp+ -j MASQUERADE<\/p>\n<p>##############################################################<br \/>\nchmod 700 \/etc\/firewall.server #\u66f4\u6539\u6b0a\u9650<br \/>\nsed -i &#8216;\/^exit 0\/i\\sh \/etc\/firewall.server&#8217; \/etc\/rc.local #\u5728 \/etc\/rc.local \u6700\u5f8c\u4e00\u884c exit 0 \u4e4b\u524d\u52a0\u5165 sh \/etc\/firewall.server<\/p>\n<p>13.\u5b89\u88ddPPTPD<br \/>\napt-get install pptpd<\/p>\n<p>nano \/etc\/pptpd.conf<br \/>\nlocalip 192.168.0.1<br \/>\nremoteip 192.168.0.234-238,192.168.0.245<br \/>\n#logwtmp<\/p>\n<p>nano \/etc\/ppp\/options<br \/>\nms-dns 8.8.8.8<br \/>\nms-dns 8.8.4.4<br \/>\nms-dns 168.95.1.1<br \/>\n#require-mppe-128<\/p>\n<p>nano \/etc\/ppp\/chap-secrets<br \/>\nname pptpd password *<\/p>\n<p>nano \/etc\/sysctl.conf<br \/>\nnet.ipv4.ip_forward=1<\/p>\n<p>sysctl -p<\/p>\n<p>14.\u5b89\u88ddfail2ban<br \/>\nyum -y install fail2ban<\/p>\n<p>15.\u555f\u7528rc.local<br \/>\nnano \/etc\/rc.local<\/p>\n<p>#!\/bin\/sh -e<br \/>\n#<br \/>\n# rc.local<br \/>\n#<br \/>\n# This script is executed at the end of each multiuser runlevel.<br \/>\n# Make sure that the script will &#8220;exit 0&#8221; on success or any other<br \/>\n# value on error.<br \/>\n#<br \/>\n# In order to enable or disable this script just change the execution<br \/>\n# bits.<br \/>\n#<br \/>\n# By default this script does nothing.<\/p>\n<p>exit 0<br \/>\nEOF<\/p>\n<p>chmod +x \/etc\/rc.local<\/p>\n<p>systemctl start rc-local<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Debian 9 \u5b89\u88dd Nginx PHP7 Mariadb&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-debian"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/twmis.com\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/twmis.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/twmis.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/twmis.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/twmis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":0,"href":"https:\/\/twmis.com\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"wp:attachment":[{"href":"https:\/\/twmis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/twmis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/twmis.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}