{"id":19145,"date":"2016-03-22T13:31:23","date_gmt":"2016-03-22T05:31:23","guid":{"rendered":"https:\/\/2blog.ilc.edu.tw\/25793\/2016\/03\/22\/lemp-server-on-centos-7-x-with-fastcgi\/"},"modified":"2021-03-18T17:24:41","modified_gmt":"2021-03-18T09:24:41","slug":"lemp-server-on-centos-7-x-with-fastcgi","status":"publish","type":"post","link":"https:\/\/2blog.ilc.edu.tw\/25793\/2016\/03\/22\/lemp-server-on-centos-7-x-with-fastcgi\/","title":{"rendered":"LEMP server on CentOS 7.x with FastCGI"},"content":{"rendered":"<p>\u53c3\u8003\u7db2\u9801\uff1a<a href=\"https:\/\/www.linode.com\/docs\/websites\/lemp\/lemp-server-on-centos-7-with-fastcgi\" target=\"_blank\" rel=\"noopener noreferrer\">LEMP server on CentOS 7 with FastCGI<\/a><\/p>\n<p>\u5b89\u88dd epel-release \u5957\u4ef6<br \/># <span style=\"color: #ff0000\">yum install epel-release<\/span><\/p>\n<p>\u5b89\u88dd Mariadb SQL Server<br \/># <span style=\"color: #ff0000\">yum install mariadb-server mariadb<\/span><\/p>\n<p>\u555f\u52d5 Mariadb SQL Server<br \/># <span style=\"color: #ff0000\">systemctl enable mariadb<\/span><br \/># <span style=\"color: #ff0000\">systemctl start mariadb<\/span><\/p>\n<p>\u7b2c\u4e00\u6b21\u4f7f\u7528\u6642\u7684\u8a2d\u5b9a<br \/># <span style=\"color: #ff0000\">\/usr\/bin\/mysql_secure_installation<\/span>[@more@]\u5b89\u88dd Nginx Web Server<br \/># <span style=\"color: #ff0000\">yum install nginx<\/span><\/p>\n<p>\u4fee\u6539\u8a2d\u5b9a\u6a94 <span style=\"color: #0000ff\">\/etc\/nginx\/nginx.conf<\/span><br \/># <span style=\"color: #ff0000\">vim \/etc\/nginx\/nginx.conf<\/span><br \/>\u5728 <span style=\"color: #ff0000\">server<\/span> \u5340\u6bb5\u4e2d\u52a0\u5165<br \/><span style=\"color: #0000ff\">\u00a0\u00a0 server {<\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 listen\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 80 default_server;<\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (\u7565)<\/span><\/p>\n<p><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 error_page 500 502 503 504 \/50x.html;<\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location = \/50x.html {<\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #ff0000\">\u00a0 location ~ .php$ {<\/span><br \/><span style=\"color: #ff0000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/usr\/share\/nginx\/html;<\/span><br \/><span style=\"color: #ff0000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_pass\u00a0\u00a0 127.0.0.1:9000;<\/span><br \/><span style=\"color: #ff0000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_index\u00a0 index.php;<\/span><br \/><span style=\"color: #ff0000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_param\u00a0 SCRIPT_FILENAME\u00a0 $document_root$fastcgi_script_name;<\/span><br \/><span style=\"color: #ff0000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 include\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_params;<\/span><br \/><span style=\"color: #ff0000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p>\u555f\u52d5 Nginx Web Server<br \/># <span style=\"color: #ff0000\">systemctl enable nginx<\/span><br \/># <span style=\"color: #ff0000\">systemctl start nginx<\/span><\/p>\n<p>\u958b\u555f\u9632\u706b\u7246\u8a2d\u5b9a<br \/># <span style=\"color: #ff0000\">firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=http<\/span><br \/># <span style=\"color: #ff0000\">firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=https<\/span><\/p>\n<p>\u5b89\u88dd PHP with FastCGI \u5957\u4ef6<br \/># <span style=\"color: #ff0000\">yum install php-cli php spawn-fcgi<\/span><\/p>\n<p>\u65b0\u589e <span style=\"color: #0000ff\">\/usr\/bin\/php-fastcgi<\/span> \u8a2d\u5b9a\u6a94<br \/># <span style=\"color: #ff0000\">vim \/usr\/bin\/php-fastcgi<\/span><br \/><span style=\"color: #0000ff\">#!\/bin\/sh<\/span><br \/><span style=\"color: #0000ff\">if [ `grep -c &#8220;nginx&#8221; \/etc\/passwd` = &#8220;1&#8221; ]; then <\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0 FASTCGI_USER=nginx<\/span><br \/><span style=\"color: #0000ff\">elif [ `grep -c &#8220;www-data&#8221; \/etc\/passwd` = &#8220;1&#8221; ]; then <\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0 FASTCGI_USER=www-data<\/span><br \/><span style=\"color: #0000ff\">elif [ `grep -c &#8220;http&#8221; \/etc\/passwd` = &#8220;1&#8221; ]; then <\/span><br \/><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0 FASTCGI_USER=http<\/span><br \/><span style=\"color: #0000ff\">else <\/span><br \/><span style=\"color: #0000ff\"># Set the FASTCGI_USER variable below to the user that <\/span><br \/><span style=\"color: #0000ff\"># you want to run the php-fastcgi processes as<\/span><\/p>\n<p><span style=\"color: #0000ff\">FASTCGI_USER=<\/span><br \/><span style=\"color: #0000ff\">fi<\/span><\/p>\n<p><span style=\"color: #0000ff\">\/usr\/bin\/spawn-fcgi -a 127.0.0.1 -p 9000 -C 6 -u $FASTCGI_USER -f \/usr\/bin\/php-cgi<\/span><\/p>\n<p>\u66f4\u65b0\u6a94\u6848\u6b0a\u9650<br \/># <span style=\"color: #ff0000\">chmod +x \/usr\/bin\/php-fastcgi<\/span><\/p>\n<p>\u65b0\u589e <span style=\"color: #0000ff\">\/etc\/systemd\/system\/php-fastcgi.service<\/span> \u8a2d\u5b9a\u6a94<br \/># <span style=\"color: #ff0000\">vim \/etc\/systemd\/system\/php-fastcgi.service<\/span><br \/><span style=\"color: #0000ff\">[Unit]<\/span><br \/><span style=\"color: #0000ff\">Description= php-fastcgi systemd service script<\/span><\/p>\n<p><span style=\"color: #0000ff\">[Service]<\/span><br \/><span style=\"color: #0000ff\">Type=forking<\/span><br \/><span style=\"color: #0000ff\">ExecStart=\/usr\/bin\/php-fastcgi start<\/span><\/p>\n<p><span style=\"color: #0000ff\">[Install]<\/span><br \/><span style=\"color: #0000ff\">WantedBy=multi-user.target<\/span><\/p>\n<p>\u555f\u52d5\u76f8\u95dc\u670d\u52d9<br \/># <span style=\"color: #ff0000\">systemctl daemon-reload<\/span><br \/># <span style=\"color: #ff0000\">systemctl enable php-fastcgi.service<\/span><br \/># <span style=\"color: #ff0000\">systemctl start php-fastcgi.service<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c3\u8003\u7db2\u9801\uff1aLEMP server on CentOS 7 with FastCGI \u5b89\u88dd epel-relea &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/2blog.ilc.edu.tw\/25793\/2016\/03\/22\/lemp-server-on-centos-7-x-with-fastcgi\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008LEMP server on CentOS 7.x with FastCGI\u3009<\/span><\/a><\/p>\n","protected":false},"author":55,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117,116,137],"tags":[],"class_list":["post-19145","post","type-post","status-publish","format-standard","hentry","category-c-78462","category-c-78461","category-c-78482"],"meta_key":{"_pingme":["1"],"_encloseme":["1"],"lt_post_id":["630741"]},"_links":{"self":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19145"}],"collection":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/comments?post=19145"}],"version-history":[{"count":1,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19145\/revisions"}],"predecessor-version":[{"id":20715,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19145\/revisions\/20715"}],"wp:attachment":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/media?parent=19145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/categories?post=19145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/tags?post=19145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}