{"id":1738,"date":"2018-07-07T00:00:36","date_gmt":"2018-07-06T16:00:36","guid":{"rendered":"https:\/\/zoco.me\/?p=151"},"modified":"2018-07-07T00:00:36","modified_gmt":"2018-07-06T16:00:36","slug":"macos-nginx-php-mysql","status":"publish","type":"post","link":"https:\/\/cloudbool.com\/archive\/macos-nginx-php-mysql.html","title":{"rendered":"macOS\u7cfb\u7edf\u914d\u7f6eNginx+PHP+MySQL\u5f00\u53d1\u73af\u5883"},"content":{"rendered":"<p>\u770b\u8fc7\u6211\u4e4b\u524d\u6587\u7ae0\u7684\u670b\u53cb\u90fd\u77e5\u9053\uff0c\u4e0d\u7ba1\u662f\u65e5\u5e38\u4f7f\u7528\uff0c\u8fd8\u662f\u5f53\u505a\u672c\u5730\u5f00\u53d1\u73af\u5883\uff0c\u6211\u90fd\u559c\u6b22\u4f7f\u7528macOS\u4f5c\u4e3a\u684c\u9762\u7cfb\u7edf\uff0c\u4e4b\u524d\u662f\u7528\u9ed1\u82f9\u679c\uff0c\u5165\u804c\u65b0\u516c\u53f8\u4e4b\u540e\uff0c\u73b0\u5728\u7ec8\u4e8e\u7528\u4e0a\u4e86\u767d\u82f9\u679c\uff0c\u4e5f\u7b97\u662f\u5bf9\u5f97\u8d77\u4e54\u8001\u7237\u5b50\u4e86\u54c8\u54c8\u54c8\u3002<\/p>\n<p>\u4f5c\u4e3a\u4e00\u4e2aPHP\u8001\u83dc\u9e1f\uff0c\u4ee5\u524d\u7528Windows\u7684\u65f6\u5019\uff0c\u90fd\u662f\u7528\u7684phpStudy\u4f5c\u4e3aPHP\u8fd0\u884c\u73af\u5883\uff0c\u73b0\u5728\u8981\u7528macOS\u4f5c\u4e3a\u5f00\u53d1\u5e73\u53f0\uff0c\u627e\u4e86\u4e00\u5708\u6ca1\u6709\u4e00\u4e2a\u6709phpStudy\u90a3\u4e48\u65b9\u4fbf\u7684PHP\u672c\u5730\u8fd0\u884c\u73af\u5883\uff0c\u552f\u4e00\u4e00\u4e2a\u597d\u7528\u70b9\u7684MAMP PRO\u8fd8\u6b7b\u8d35\u6b7b\u8d35\u7684\uff0c\u6ca1\u529e\u6cd5\uff0c\u8981\u5403\u996d\uff0c\u867d\u7136\u6709\u56f0\u96be\uff0c\u4f46\u8fd8\u662f\u8981\u60f3\u529e\u6cd5\u89e3\u51b3\uff0c\u6298\u817e\u4e86\u4e00\u5708\u5404\u79cd\u5e26\u56fe\u5f62\u5316\u754c\u9762\u7684\u5305\uff0c\u6700\u7ec8\u8fd8\u662f\u56de\u5230\u4e86\u547d\u4ee4\u884c\uff0c\u8fd8\u662f\u7528brew\u5b89\u88c5\u5404\u4e2a\u7ec4\u4ef6\u597d\u4f7f\u3002<br \/>\n<!--more--><\/p>\n<p>\u8bb2\u9053\u7406\uff0cMAMP PRO\u662f\u771f\u5fc3\u597d\u4f7f\uff0c\u7528\u4e86\u4e00\u6bb5\u65f6\u95f4\u6ca1\u53d1\u73b0\u4ec0\u4e48\u5927\u6bdb\u75c5\uff0c\u53ea\u662f\u8bd5\u7528\u671f\u4e4b\u540e\u4ef7\u683c\u6709\u70b9\u8089\u75bc\uff0c\u6211\u53c8\u4e0d\u60f3\u4f7f\u7528\u90a3\u4e9b\u4ec0\u4e48key gen\u5de5\u5177\uff0c\u4e0d\u7528\u60f3\uff0c\u5341\u6709\u516b\u4e5d\u90fd\u6709\u95ee\u9898\uff0c\u4e5f\u4e0d\u60f3\u592a\u6298\u817e\uff0c\u7b97\u4e86\uff0c\u8fd8\u662f\u6572\u547d\u4ee4\u81ea\u5df1\u88c5\u5427\uff0c\u4e8e\u662f\u624d\u6709\u4e86\u8fd9\u4e48\u4e00\u7bc7\u6298\u817e\u7b14\u8bb0\u3002<\/p>\n<h2>macOS\u5b89\u88c5Nginx\u3001PHP\u3001MySQL<\/h2>\n<p>\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u7684\u5f00\u53d1\u6846\u67b6\u5bf9PHP\u7248\u672c\u6709\u8981\u6c42\uff0c\u5728PHP7.1\u73af\u5883\u4e0b\u8fd0\u884c\u6700\u5408\u9002\uff0c\u6240\u4ee5\u6211\u8fd9\u91cc\u5b89\u88c5\u7684\u662fPHP7.1\uff0c\u5b89\u88c5\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>brew install nginx mysql php71\n<\/code><\/pre>\n<p>\u5b89\u88c5\u597d\u4e4b\u540e\uff0c\u628aPHP\u76f8\u5173\u547d\u4ee4\u6dfb\u52a0\u5230PATH\uff0c\u65b9\u4fbf\u4e8e\u547d\u4ee4\u884c\u4e0b\u8bbf\u95ee\uff1a<\/p>\n<pre><code>  echo 'export PATH=\"\/usr\/local\/opt\/php@7.1\/bin:$PATH\"' &gt;&gt; ~\/.zshrc\n  echo 'export PATH=\"\/usr\/local\/opt\/php@7.1\/sbin:$PATH\"' &gt;&gt; ~\/.zshrc\n<\/code><\/pre>\n<h2>\u76f8\u5173\u914d\u7f6e\u6587\u4ef6<\/h2>\n<p>brew\u5b89\u88c5\u7684Nginx\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>\/usr\/local\/etc\/nginx\/nginx.conf\n<\/code><\/pre>\n<p>Nginx\u7f51\u7ad9\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55\uff1a<\/p>\n<pre><code>\/usr\/local\/etc\/nginx\/servers\/\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u7f51\u7ad9\u6587\u4ef6\u76ee\u5f55\uff1a<\/p>\n<pre><code>\/usr\/local\/var\/www\n<\/code><\/pre>\n<p>PS\uff1abrew\u5b89\u88c5\u7684Nginx\uff0c\u5982\u679c\u6ca1\u6709\u66f4\u6539\u914d\u7f6e\u6587\u4ef6\u7684\u8bdd\uff0c\u9ed8\u8ba4\u662f\u8fd0\u884c\u57288080\u7aef\u53e3\uff0c\u542f\u52a8Nginx\u4e4b\u540e\uff0c\u8bbf\u95ee<strong>127.0.0.1:8080<\/strong>\u5373\u53ef\u770b\u5230\u9ed8\u8ba4\u9875\u9762\u3002<\/p>\n<p>PHP\u76f8\u5173\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\uff1a<\/p>\n<pre><code>\/usr\/local\/etc\/php\/7.1\/\n<\/code><\/pre>\n<h2>Nginx\u3001PHP-FPM\u3001MySQL\u5b89\u88c5\u540e\u76f8\u5173\u914d\u7f6e<\/h2>\n<p>\u56e0\u4e3a\u6211\u662f\u7528\u6765\u672c\u5730\u5f00\u53d1\uff0c\u6240\u4ee5\u6211\u6253\u7b97\u5c06\u7f51\u7ad9\u76ee\u5f55\u653e\u5230\u6211\u5f53\u524d\u4f7f\u7528\u7684\u7528\u6237\u76ee\u5f55\u4e0b\uff0c\u4e5f\u5c31\u662f<strong>\/User\/username\/www<\/strong>\u4e0b\uff0c\u6240\u4ee5\u8fd8\u9700\u8981\u5c06Nginx\u548cPHP-FPM\u7684\u914d\u7f6e\u76f8\u5e94\u66f4\u6539\u4e0b\uff0c\u7f51\u7ad9\u76f8\u5173\u7a0b\u5e8f\u624d\u6709\u5199\u5165\u6743\u9650\u3002<\/p>\n<h3>Nginx\u76f8\u5173\u914d\u7f6e<\/h3>\n<p>\u9996\u5148\u662f\u66f4\u6539Nginx\u7684\u8fd0\u884c\u7528\u6237\uff1a<\/p>\n<pre><code>vim \/usr\/local\/etc\/nginx\/nginx.conf\n\nuser username staff;\nworker_processes  auto;\n<\/code><\/pre>\n<h3>PHP-FPM\u76f8\u5173\u914d\u7f6e\uff1a<\/h3>\n<pre><code>vim \/usr\/local\/etc\/php\/7.1\/php-fpm.d\/www.conf\n\nuser = username\ngroup = username\n<\/code><\/pre>\n<p><strong>\u5c06\u4e0a\u8ff0username\u66ff\u6362\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u540d\u3002<\/strong><\/p>\n<h3>MySQL\u76f8\u5173\u914d\u7f6e<\/h3>\n<p>\u5b89\u88c5MySQL\u4e4b\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u76f8\u5173\u8bbe\u7f6e\uff0c\u9996\u5148\uff0c\u542f\u52a8MySQL\u670d\u52a1\uff0c\u7136\u540e\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>mysql_secure_installation\n<\/code><\/pre>\n<p>\u8fd0\u884c\u4e4b\u540e\uff0c\u53ef\u4ee5\u6839\u636e\u63d0\u793a\uff0c\u8bbe\u7f6eroot\u5bc6\u7801\u3001\u5173\u95ed\u8fdc\u7a0b\u767b\u5f55\u3001\u79fb\u9664\u533f\u540d\u7528\u6237\u3001\u5220\u9664\u6d4b\u8bd5\u6570\u636e\u5e93\u7b49\u64cd\u4f5c\uff0c\u6839\u636e\u63d0\u793a\u8f93\u5165\u6216\u8005\u56de\u8f66\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u6267\u884c\u5b8c\u4e4b\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u767b\u5f55MySQL\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>mysql -u root -p\n<\/code><\/pre>\n<h2>Nginx\u3001PHP-FPM\u3001MySQL\u76f8\u5173\u547d\u4ee4<\/h2>\n<p>\u5176\u5b9e\u548c\u522b\u7684brew\u5b89\u88c5\u7684\u8f6f\u4ef6\u5dee\u4e0d\u591a\uff0c\u90fd\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5f00\u542f\u3001\u91cd\u542f\u3001\u505c\u6b62\u76f8\u5173\u8fdb\u7a0b\uff1a<\/p>\n<p>Nginx\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\uff1a<\/p>\n<pre><code>sudo nginx\nsudo nginx -s reload\nsudo nginx -s stop\n<\/code><\/pre>\n<p>PHP-FPM\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\uff1a<\/p>\n<pre><code>brew services start php@7.1\nbrew services restart php@7.1\nbrew services stop php@7.1\n<\/code><\/pre>\n<p>MySQL\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\uff1a<\/p>\n<pre><code>brew services start mysql\nbrew services restart mysql\nbrew services stop mysql\n<\/code><\/pre>\n<p>\u6d4b\u8bd5Nginx\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u786e\uff1a<\/p>\n<pre><code>sudo nginx -t\n<\/code><\/pre>\n<h2>macOS\u7cfb\u7edfNginx\u65b0\u589eServer<\/h2>\n<p>\u4e0a\u9762\u8bf4\u4e86\uff0cNginx\u7684Server\u914d\u7f6e\u76ee\u5f55\u5728<strong>\/usr\/local\/etc\/nginx\/servers\/<\/strong>\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5230\u5982\u4e0b\u76ee\u5f55\u76f8\u5173\u914d\u7f6e\u6587\u4ef6\u5c31\u884c\u4e86\u3002\u5982\u4e0b\u662f\u4e00\u4e2a\u7f51\u7ad9\u914d\u7f6e\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n<pre><code>vim \/usr\/local\/etc\/nginx\/servers\/test.conf\n\nserver {\n    listen                          80;\n\n    server_name                     test.com;\n\n    index                           index.html index.php;\n\n    access_log                      \/usr\/local\/var\/log\/nginx\/test.access.log;\n    error_log                       \/usr\/local\/var\/log\/nginx\/test.error.log;\n\n    root                            \/Users\/zoco\/temp\/laravel\/public;\n\n    location ~ \\.php$ {\n        try_files                   $uri =404;\n        fastcgi_index               index.php;\n        fastcgi_param               SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        fastcgi_read_timeout        300;\n        fastcgi_keep_conn           on;\n        include                     \/usr\/local\/etc\/nginx\/fastcgi_params;\n        fastcgi_pass                127.0.0.1:9000;\n        index                       index.html index.php;\n    }\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$query_string;\n    }\n}\n<\/code><\/pre>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6574\u4e2amacOS\u7684MAMP\u5f00\u53d1\u73af\u5883\u5c31\u914d\u7f6e\u597d\u4e86\uff0c\u6298\u817e\u524d\u611f\u89c9\u633a\u9ebb\u70e6\u7684\uff0c\u914d\u7f6e\u5b8c\u53d1\u73b0\uff0c\u611f\u89c9\u8ddfLinux\u4e0b\u914d\u7f6eLNMP\u5dee\u4e0d\u591a\u554a\u54c8\u54c8\u54c8\u3002<\/p>\n<p>happy coding\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u770b\u8fc7\u6211\u4e4b\u524d\u6587\u7ae0\u7684\u670b\u53cb\u90fd\u77e5\u9053\uff0c\u4e0d\u7ba1\u662f\u65e5\u5e38\u4f7f\u7528\uff0c\u8fd8\u662f\u5f53\u505a\u672c\u5730\u5f00\u53d1\u73af\u5883\uff0c\u6211\u90fd\u559c\u6b22\u4f7f\u7528macOS\u4f5c\u4e3a\u684c\u9762\u7cfb\u7edf\uff0c\u4e4b\u524d\u662f\u7528 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/cloudbool.com\/archive\/macos-nginx-php-mysql.html\"> <span class=\"screen-reader-text\">macOS\u7cfb\u7edf\u914d\u7f6eNginx+PHP+MySQL\u5f00\u53d1\u73af\u5883<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[66,75,76,79],"class_list":["post-1738","post","type-post","status-publish","format-standard","hentry","category-tech","tag-macos","tag-mysql","tag-nginx","tag-php"],"_links":{"self":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/1738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/comments?post=1738"}],"version-history":[{"count":0,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/1738\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/media?parent=1738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/categories?post=1738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/tags?post=1738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}