{"id":3921,"date":"2018-05-07T19:44:53","date_gmt":"2018-05-07T11:44:53","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=3921"},"modified":"2018-05-07T19:44:53","modified_gmt":"2018-05-07T11:44:53","slug":"centos-7%e4%b8%8aphp-fpm%e6%97%a0%e6%b3%95%e5%90%af%e5%8a%a8%e7%9a%84%e9%97%ae%e9%a2%98%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/3921.html","title":{"rendered":"CentOS 7\u4e0aphp-fpm\u65e0\u6cd5\u542f\u52a8\u7684\u95ee\u9898\u5904\u7406"},"content":{"rendered":"<p>=Start=<\/p>\n<h4 id=\"id-\u6a21\u677f-\u7f18\u7531\uff1a\">\u7f18\u7531\uff1a<\/h4>\n<p>\u73b0\u5728\u81ea\u7528\u7684Linux\u4e3b\u673a\u7cfb\u7edf\u6211\u90fd\u662f\u9009\u7684CentOS 7\uff0c\u7528\u7684PHP\u7248\u672c\u4e5f\u5347\u7ea7\u5230\u4e86PHP 7\u3002\u5728\u4e4b\u524d\u7684\u4e3b\u673a\u3001\u535a\u5ba2\u7ef4\u62a4\u8fc7\u7a0b\u4e2d\u5df2\u7ecf\u51fa\u8fc7\u4e0d\u5c11\u95ee\u9898\uff0c\u8fd9\u6b21\u53c8\u78b0\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\u2014\u2014\u5728\u4e3b\u673a\u56e0\u7ef4\u62a4\u800c\u91cd\u542f\u540ephp-fpm\u6ca1\u6709\u6b63\u786e\u542f\u52a8\u5bfc\u81f4\u535a\u5ba2\u65e0\u6cd5\u6b63\u5e38\u8bbf\u95ee\uff0c\u89e3\u51b3\u529e\u6cd5\u548c\u4e4b\u524d\u7684\u4e0d\u592a\u4e00\u6837\uff0c\u6240\u4ee5\u5728\u6b64\u8bb0\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4ee5\u540e\u67e5\u9605\u3001\u53c2\u8003\u3002<\/p>\n<h4 id=\"id-\u6a21\u677f-\u6b63\u6587\uff1a\">\u6b63\u6587\uff1a<\/h4>\n<h5 id=\"id-\u6a21\u677f-\u53c2\u8003\u89e3\u7b54\uff1a\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<h6><strong>0\u3001\u4e00\u4e9b\u8f85\u52a9\u547d\u4ee4<\/strong><\/h6>\n<pre class=\"lang:default decode:true\"># ls -lt \/etc\/systemd\/system\/multi-user.target.wants\/\r\n\r\n# find \/ -type f -iname \"php-fpm.conf\" | xargs ls -lt\r\n# grep -v '^;' \/etc\/opt\/remi\/php71\/php-fpm.d\/www.conf | grep 'listen'\r\n\r\n# nginx -t\r\n# grep \"fastcgi_pass\" \/etc\/nginx\/nginx.conf\r\n<\/pre>\n<h6><strong>1\u3001systemd\u7684\u7cfb\u7edf\u542f\u52a8\u9879<\/strong><\/h6>\n<p>\u5e94\u8be5\u662f\u4eceCentOS 7\u5f00\u59cb\uff0cLinux\u670d\u52a1\u7ba1\u7406\u5668\u5f00\u59cb\u7528systemd\u6765\u66ff\u6362\u4e4b\u524d\u7684SysVinit\uff0c\u5f88\u591a\u547d\u4ee4\u548c\u4e4b\u524d\u4e0d\u592a\u4e00\u6837\uff0c\u5177\u4f53\u7684\u53ef\u4ee5\u53c2\u8003\u4e4b\u524d\u8bb0\u5f55\u7684\u4e00\u7bc7\u6587\u7ae0\u300c<a href=\"https:\/\/ixyzero.com\/blog\/archives\/2464.html\" target=\"_blank\" rel=\"noopener\">Linux\u7684systemd\u76f8\u5173\u77e5\u8bc6\u5b66\u4e60<\/a>\u300d\uff0c\u8fd9\u91cc\u53ea\u63d0\u4e00\u70b9\uff1a<\/p>\n<pre class=\"lang:default decode:true \"># systemd\u91cc\u9762\u7684.service\u6587\u4ef6\u4e00\u822c\u662f\u653e\u5728\u4e0b\u9762\u8fd9\u4e2a\u76ee\u5f55\u4e0b\uff0c\u5f53\u4e0d\u8bb0\u5f97\u670d\u52a1\u540d\u79f0\u4e86\uff0c\u53ef\u4ee5\u53bb\u76ee\u5f55\u91cc\u770b\u770b\r\n# ls -lt \/usr\/lib\/systemd\/system\/\r\n# cat \/usr\/lib\/systemd\/system\/php71-php-fpm.service<\/pre>\n<p>&amp;<\/p>\n<pre class=\"lang:default decode:true \"># \u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u4e0a\u73b0\u5728\u6709\u54ea\u4e9b\u5f00\u673a\u542f\u52a8\u9879\uff0c\u5982\u679c\u4e0d\u5728\u7684\u8bdd\u4f7f\u7528enable\u8fdb\u884c\u6dfb\u52a0\r\n# ls -lt \/etc\/systemd\/system\/multi-user.target.wants\/\r\n# systemctl enable nginx\r\n# systemctl enable php71-php-fpm\r\n# systemctl enable mysqld\r\n<\/pre>\n<h6><strong>2\u3001php-fpm\u542f\u52a8\u5931\u8d25\u7684\u539f\u56e0<\/strong><\/h6>\n<pre class=\"lang:default decode:true \">\u25cf php71-php-fpm.service - The PHP FastCGI Process Manager\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/php71-php-fpm.service; disabled; vendor preset: disabled)\r\n   Active: failed (Result: exit-code) since Wed 2018-05-05 10:38:32 CST; 36s ago\r\n  Process: 5500 ExecStart=\/opt\/remi\/php71\/root\/usr\/sbin\/php-fpm --nodaemonize (code=exited, status=78)\r\n Main PID: 5500 (code=exited, status=78)\r\n\r\nMay 05 10:38:32 ixyzero-centos systemd[1]: Starting The PHP FastCGI Process Manager...\r\nMay 05 10:38:32 ixyzero-centos php-fpm[5500]: [02-May-2018 10:38:32] ERROR: unable to bind listening socket for address '\/var\/run\/php-fpm\/php-fpm.sock': No such file or directory (2)\r\nMay 05 10:38:32 ixyzero-centos php-fpm[5500]: [02-May-2018 10:38:32] ERROR: FPM initialization failed\r\nMay 05 10:38:32 ixyzero-centos systemd[1]: php71-php-fpm.service: main process exited, code=exited, status=78\/n\/a\r\nMay 05 10:38:32 ixyzero-centos systemd[1]: Failed to start The PHP FastCGI Process Manager.\r\nMay 05 10:38:32 ixyzero-centos systemd[1]: Unit php71-php-fpm.service entered failed state.\r\nMay 05 10:38:32 ixyzero-centos systemd[1]: php71-php-fpm.service failed.\r\n<\/pre>\n<p>\u5373\uff0c\u6ca1\u6709 `\/var\/run\/php-fpm\/php-fpm.sock` \u8fd9\u4e2a\u6587\u4ef6\uff0c\u5bfc\u81f4\u65e0\u6cd5\u7ed1\u5b9a\u76d1\u542c\u7aef\u53e3\/\u6587\u4ef6\uff0c\u521d\u59cb\u5316\u5931\u8d25\u3002<\/p>\n<p>\u4e4b\u524d\u51fa\u73b0\u8fd9\u79cd\u95ee\u9898\uff0c\u4e00\u822c\u662f\u4ee5\u4e0b\u539f\u56e0\u4e4b\u4e00\uff1a<\/p>\n<ul>\n<li>php-fpm\u7684\u914d\u7f6e\u6587\u4ef6\u91cc\u7684listen.owner\/group\u548cNginx\u914d\u7f6e\u6587\u4ef6\u91cc\u7684user\/group\u4e0d\u5339\u914d\uff0c\u5bfc\u81f4\u6743\u9650\u4e0d\u591f\uff1b<\/li>\n<li>php-fpm\u7684\u914d\u7f6e\u6587\u4ef6\u91cc\u7684listen\u548cNginx\u914d\u7f6e\u6587\u4ef6\u91cc\u7684fastcgi_pass\u4e0d\u5339\u914d\uff0c\u5bfc\u81f4\u76d1\u542c\u548c\u8bfb\u53d6\u7684\u4e0d\u662f\u540c\u4e00\u4e2asocket\u6587\u4ef6\uff1b<\/li>\n<\/ul>\n<h6><strong>3\u3001\u4e34\u65f6\u89e3\u51b3\u529e\u6cd5<\/strong><\/h6>\n<p>\u4f46\u8fd9\u6b21\u4e0d\u662f\uff0c\u8fd9\u6b21\u7684\u4e0a\u97622\u4e2a\u914d\u7f6e\u90fd\u662f\u5bf9\u7684\uff0c\u4f46\u5c31\u662f\u00a0`\/var\/run\/php-fpm\/php-fpm.sock` \u8fd9\u4e2a\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u89e3\u51b3\u529e\u6cd5\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\uff1a<\/p>\n<pre class=\"lang:default decode:true \"># sudo mkdir -p \/var\/run\/php-fpm\/\r\n# sudo touch \/var\/run\/php-fpm\/php-fpm.sock\r\n\r\n# sudo systemctl start php71-php-fpm\r\n<\/pre>\n<p>\u4e0d\u8fc7\uff0c\u4e00\u65e6\u673a\u5668\u91cd\u542f\uff0c`\/var\/run\/php-fpm\/php-fpm.sock` \u8fd9\u4e2a\u6587\u4ef6\u5c31\u53c8\u6ca1\u4e86\uff0c\u800c\u4e14\u00a0`\/var\/run\/php-fpm\/` \u8fd9\u4e2a\u76ee\u5f55\u4e5f\u6ca1\u4e86\uff0c\u6240\u4ee5\uff0c\u8fd9\u79cd\u624b\u5de5\u521b\u5efa\u76ee\u5f55\u3001\u6587\u4ef6\u7684\u65b9\u5f0f\u53ea\u80fd\u4e34\u65f6\u751f\u6548\u3002<\/p>\n<h6><strong>4\u3001\u957f\u671f\u89e3\u51b3\u529e\u6cd5<\/strong><\/h6>\n<p>\u5982\u679c\u60f3\u8981\u627e\u5230\u4e00\u4e2a\u957f\u671f\u6709\u6548\u7684\u529e\u6cd5\uff0c\u90a3\u5c31\u9700\u8981\u5b9a\u4f4d\u95ee\u9898\u4ee5\u53ca\u5176\u80cc\u540e\u7684\u539f\u56e0\uff0c\u5426\u5219\u95ee\u9898\u8fd8\u662f\u4f1a\u4e00\u76f4\u5b58\u5728\u3002<\/p>\n<pre class=\"lang:default decode:true\"># \u770b \/var\/run\/ \u76ee\u5f55\u6743\u9650\r\n[zero@ixyzero-centos ~]$ ls -lt \/var\/ | grep \"run\"\r\nlrwxrwxrwx.  1 root root   11 2\u6708   3 2017 lock -&gt; ..\/run\/lock\r\nlrwxrwxrwx.  1 root root    6 2\u6708   3 2017 run -&gt; ..\/run\r\n[zero@ixyzero-centos ~]$\r\n[zero@ixyzero-centos ~]$ ls -lt \/ | grep \"run\"\r\ndrwxr-xr-x  22 root root   620 5\u6708   2 16:30 run\r\n\r\n# \u4ece\u4e0a\u9762\u7684\u4fe1\u606f\u53ef\u4ee5\u770b\u51fa\uff0c \/var\/run \u8fd9\u4e2a\u76ee\u5f55\u53ea\u6709root\u624d\u6709\u300c\u5199\u300d\u6743\u9650\uff0c\u800cphp-fpm\u7684\u6267\u884c\u7528\u6237\u662f\u548cNginx\u4e00\u6837\u7684\u4f4e\u6743\u9650\u7528\u6237\uff0c\u6240\u4ee5\u65e0\u6cd5\u521b\u5efa \/var\/run\/php-fpm\/ \u5b50\u76ee\u5f55\uff0c\u4ece\u800c\u4e5f\u5c31\u65e0\u6cd5\u521b\u5efa \/var\/run\/php-fpm\/php-fpm.sock \u6587\u4ef6\r\n\r\n# \u76ee\u5f55 \/var\/run \u6709\u70b9\u300c\u5185\u5b58\u76d8\u300d\u7684\u611f\u89c9\uff0c\u5c31\u662f\u8bf4\u5b83\u4e0d\u662f\u4e00\u76f4\u7a33\u5b9a\u5b58\u5728\u7684\uff0c\u800c\u662f\u53ea\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\uff08\u7f51\u4e0a\u6709\u8bf4\u6cd5\u662f\u8fd9\u6837\u4f1a\u63d0\u9ad8\u901f\u5ea6\uff09\uff0c\u5f53\u7cfb\u7edf\u91cd\u542f\u65f6\uff0c\/var \u4e0b\u7684\u76ee\u5f55\u4fbf\u4f1a\u6d88\u5931\uff0c\u9700\u8981\u91cd\u65b0\u521b\u5efa<\/pre>\n<p>\u7efc\u4e0a\uff0c\u6211\u5c06\u539f\u5148php-fpm\u7684\u914d\u7f6e\u6587\u4ef6\u91cc\u7684listen\u548cNginx\u914d\u7f6e\u6587\u4ef6\u91cc\u7684fastcgi_pass\u90fd\u6539\u6210\u4e86\u00a0`\/var\/run\/php-fpm.sock` \uff0c\u7136\u540e\u5c06php-fpm\u548cNginx\u670d\u52a1\u90fd\u52a0\u5165\u7cfb\u7edf\u542f\u52a8\u9879\uff0c\u91cd\u542f\u7cfb\u7edf\uff0c\u4e00\u5207OK\u3002<\/p>\n<h5 id=\"id-\u6a21\u677f-\u53c2\u8003\u94fe\u63a5\uff1a\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li class=\"entry-title\"><a href=\"https:\/\/ixyzero.com\/blog\/archives\/1229.html\" target=\"_blank\" rel=\"noopener\">Nginx 502 Bad Gateway Error<\/a><\/li>\n<li><a href=\"https:\/\/blog.csdn.net\/youcijibi\/article\/details\/76546640\">https:\/\/blog.csdn.net\/youcijibi\/article\/details\/76546640<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u73b0\u5728\u81ea\u7528\u7684Linux\u4e3b\u673a\u7cfb\u7edf\u6211\u90fd\u662f\u9009\u7684CentOS 7\uff0c\u7528\u7684PHP\u7248\u672c\u4e5f\u5347\u7ea7\u5230\u4e86PHP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11],"tags":[28,337,48,1124,548],"class_list":["post-3921","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","tag-centos","tag-nginx-conf","tag-php","tag-php-fpm","tag-systemd"],"views":12865,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=3921"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3921\/revisions"}],"predecessor-version":[{"id":3922,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3921\/revisions\/3922"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=3921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=3921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=3921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}