{"id":392,"date":"2025-06-10T19:45:46","date_gmt":"2025-06-10T11:45:46","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/392.html"},"modified":"2025-06-10T19:45:46","modified_gmt":"2025-06-10T11:45:46","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8macos%e4%b8%8a%e5%8d%87%e7%ba%a7php","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/392.html","title":{"rendered":"\u5982\u4f55\u5728MacOS\u4e0a\u5347\u7ea7PHP"},"content":{"rendered":"<p><body><\/p>\n<h2>&#20171;&#32461;<\/h2>\n<p>&#20445;&#25345;&#22312; macOS &#19978;&#30340; PHP &#26356;&#26032;&#23545;&#20110;&#24320;&#21457;&#32773;&#20805;&#20998;&#21033;&#29992;&#26368;&#26032;&#21151;&#33021;&#12289;&#20248;&#21270;&#21644;&#23433;&#20840;&#22686;&#24378;&#33267;&#20851;&#37325;&#35201;&#12290;&#20197;&#19979;&#26159;&#36880;&#27493;&#25351;&#21335;&#65292;&#25945;&#20320;&#22914;&#20309;&#22312; macOS &#31995;&#32479;&#19978;&#21319;&#32423; PHP&#12290;<\/p>\n<h2>&#20808;&#20915;&#26465;&#20214;<\/h2>\n<p>&#22312;&#24320;&#22987;&#22312;Mac&#19978;&#36827;&#34892;PHP&#21319;&#32423;&#20043;&#21069;&#65292;&#30830;&#20445;&#24744;&#24050;&#32463;&#65306;<\/p>\n<p>&#24744;&#30340;&#31995;&#32479;&#35775;&#38382;&#26435;&#38480;&#65306;<\/p>\n<p>&#20860;&#23481;&#30340;&#29256;&#26412;&#30340;macOS<\/p>\n<pre><code>$ whoami\nYourUsername\n$ sudo -v\nPassword:\n<\/code><\/pre>\n<p>&#22914;&#26524;&#20320;&#22312;&#36755;&#20837;&ldquo;whoami&rdquo;&#21518;&#30475;&#21040;&#21333;&#35789;&ldquo;root&rdquo;&#65292;&#37027;&#20040;&#20320;&#23601;&#20855;&#26377;&#31649;&#29702;&#21592;&#26435;&#38480;&#12290;<\/p>\n<h2>&#22791;&#20221;&#24403;&#21069;&#30340;PHP&#37197;&#32622;&#65306;<\/h2>\n<p>&#30830;&#20445;&#22312;&#26356;&#25913;&#20043;&#21069;&#23545;&#29616;&#26377;PHP&#37197;&#32622;&#36827;&#34892;&#22791;&#20221;&#38750;&#24120;&#37325;&#35201;&#12290;&#20320;&#21487;&#20197;&#31616;&#21333;&#22320;&#23558;&#24403;&#21069;&#30340;php.ini&#25991;&#20214;&#22797;&#21046;&#21040;&#22791;&#20221;&#20301;&#32622;&#65306;<\/p>\n<pre><code>$ cp \/etc\/php.ini \/etc\/php.ini.backup\n<\/code><\/pre>\n<h2>&#27491;&#22312;&#23433;&#35013;Homebrew<\/h2>\n<p>Homebrew &#26159; macOS &#19978;&#26368;&#27969;&#34892;&#30340;&#21253;&#31649;&#29702;&#22120;&#65292;&#23427;&#25552;&#20379;&#20102;&#23433;&#35013;&#25110;&#21319;&#32423; PHP &#30340;&#26041;&#20415;&#26041;&#27861;&#12290;&#22914;&#26524;&#20320;&#36824;&#27809;&#26377;&#23433;&#35013; Homebrew&#65306;<\/p>\n<pre><code>\/bin\/bash -c \"\n$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)\"\ncode&gt;<\/code><\/pre>\n<p>&#23433;&#35013;&#23436;&#25104;&#21518;&#65292;&#21487;&#20197;&#26816;&#26597;Brew&#30340;&#29256;&#26412;&#24182;&#30830;&#20445;&#20854;&#20934;&#22791;&#23601;&#32490;&#65306;<\/p>\n<pre><code>$ brew -v\nHomebrew 3.0.0\nHomebrew\/homebrew-core (git revision 1234; last commit 2021-02-17)\nHomebrew\/homebrew-cask (git revision 5678; last commit 2021-02-17)\n<\/code><\/pre>\n<h2>&#21368;&#36733;&#29616;&#26377;PHP&#29256;&#26412;<\/h2>\n<p>&#22914;&#26524;&#20043;&#21069;&#36890;&#36807; Homebrew &#23433;&#35013;&#36807; PHP&#65292;&#38656;&#35201;&#20808;&#21368;&#36733;&#23427;&#65306;<\/p>\n<pre><code>$ brew uninstall php\n<\/code><\/pre>\n<h2>&#21319;&#32423;&#21040;&#26368;&#26032;&#29256;&#26412;&#30340;PHP<\/h2>\n<p>&#23433;&#35013;&#20351;&#29992; Homebrew &#30340; PHP &#38750;&#24120;&#31616;&#21333;&#12290;&#39318;&#20808;&#65292;&#26356;&#26032; Homebrew&#65306;<\/p>\n<pre><code>$ brew update\n<\/code><\/pre>\n<p>&#28982;&#21518;&#65292;&#35201;&#23433;&#35013;&#26368;&#26032;&#29256;&#26412;&#30340;PHP&#65306;<\/p>\n<pre><code>$ brew install php\n<\/code><\/pre>\n<p>&#22312;&#23433;&#35013;&#23436;&#25104;&#21518;&#65292;&#21487;&#20197;&#30830;&#35748;&#24050;&#23433;&#35013;&#30340;PHP&#29256;&#26412;&#65306;<\/p>\n<pre><code>$ php -v\nPHP 8.1.0 (cli) (built: Aug 9 2023 12:00:00) ( NTS )\n<\/code><\/pre>\n<h2>&#22312;&#23433;&#35013;&#21518;&#37197;&#32622;PHP&#12290;<\/h2>\n<p>PHP&#30340;&#22522;&#26412;&#37197;&#32622;&#23545;&#20110;&#26356;&#22909;&#30340;&#20248;&#21270;&#33267;&#20851;&#37325;&#35201;&#65306;<\/p>\n<pre><code>$ cp \/usr\/local\/etc\/php\/8.1\/php.ini.default \/usr\/local\/etc\/php\/8.1\/php.ini\n$ vi \/usr\/local\/etc\/php\/8.1\/php.ini\n<\/code><\/pre>\n<p>&#23545;&#19981;&#36215;&#65292;&#25105;&#19981;&#22826;&#26126;&#30333;&#24744;&#30340;&#38382;&#39064;&#65292;&#35831;&#24744;&#37325;&#26032;&#25551;&#36848;&#19968;&#19979;&#12290;<code>php.ini<\/code>&#25991;&#20214;&#65292;&#20320;&#21487;&#20197;&#35843;&#25972;&#35774;&#32622;&#65292;&#22914;<code>date.timezone<\/code>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<code>memory_limit<\/code>&#65292;&#26681;&#25454;&#38656;&#35201;&#20026;&#24744;&#30340;&#29615;&#22659;&#28155;&#21152;&#20854;&#20182;&#20154;&#21592;&#12290;<\/p>\n<h2>&#26356;&#26032;&#31995;&#32479;&#30340;PATH&#35774;&#32622;<\/h2>\n<p>&#20026;&#20102;&#35753;&#31995;&#32479;&#40664;&#35748;&#20351;&#29992;&#26032;&#29256;&#26412;&#30340;PHP&#65292;&#23427;&#24517;&#39035;&#22312;PATH&#29615;&#22659;&#20013;&#65306;<\/p>\n<pre><code>$ echo 'export PATH=\"\/usr\/local\/opt\/php\/bin:$PATH\"' &gt;&gt; ~\/.bash_profile\n$ source ~\/.bash_profile\n<\/code><\/pre>\n<p>&#36825;&#23558;&#20248;&#20808;&#25191;&#34892;&#26032;&#23433;&#35013;&#30340;PHP&#31243;&#24207;&#26102;&#20351;&#29992;php&#21629;&#20196;&#12290;<\/p>\n<h2>&#20999;&#25442;PHP&#29256;&#26412;<\/h2>\n<p>&#22914;&#26524;&#20320;&#38656;&#35201;&#39057;&#32321;&#20999;&#25442;PHP&#29256;&#26412;&#65292;&#21487;&#20197;&#20351;&#29992;php-version&#25110;brew link&#12290;<\/p>\n<pre><code>$ brew unlink [email&nbsp;protected]\n$ brew link --overwrite --force php<\/code><\/pre>\n<p>&#25552;&#21450;&#30340;&#25805;&#20316;&#27493;&#39588;&#36890;&#24120;&#29992;&#20110;&#22312; MacOS &#21629;&#20196;&#34892;&#19978;&#20999;&#25442;&#21040;&#29305;&#23450;&#30340; PHP &#29256;&#26412;&#12290;<\/p>\n<h2>&#20351;&#29992;&#29256;&#26412;&#31649;&#29702;&#24037;&#20855;<\/h2>\n<p>&#23545;&#20110;&#39640;&#32423;&#30340;PHP&#31649;&#29702;&#65292;&#21487;&#20197;&#32771;&#34385;&#20351;&#29992;&#29256;&#26412;&#31649;&#29702;&#24037;&#20855;&#22914;phpenv&#25110;PHPBrew&#12290;<\/p>\n<h3>PHPBrew &#26159;&#19968;&#20010;&#29992;&#20110;&#22312; Mac &#19978;&#23433;&#35013;&#21644;&#31649;&#29702; PHP &#39033;&#30446;&#30340;&#24037;&#20855;&#65292;&#23427;&#20801;&#35768;&#29992;&#25143;&#36890;&#36807; Brew&#65288;Homebrew&#65289;&#26469;&#23433;&#35013;&#21644;&#37197;&#32622; PHP &#29615;&#22659;&#12290;<\/h3>\n<p>&#25191;&#34892;&#20102;&#65306;HasBeenSet up&#12290;<\/p>\n<pre><code>$ curl -L -O https:\/\/github.com\/phpbrew\/phpbrew\/raw\/master\/phpbrew\n$ chmod +x phpbrew\n$ sudo mv phpbrew \/usr\/local\/bin\/phpbrew\n<\/code><\/pre>\n<p>&#23433;&#35013;&#29305;&#23450;&#30340;PHP&#29256;&#26412;&#20351;&#29992;PHPBrew&#65306;<\/p>\n<pre><code>$ phpbrew init\n$ phpbrew install 7.4.0 +default\n<\/code><\/pre>\n<h3>phpenv &#26159;&#19968;&#20010;&#29992;&#20110;&#31649;&#29702; PHP &#29615;&#22659;&#30340;&#24037;&#20855;&#65292;&#23427;&#20801;&#35768;&#29992;&#25143;&#22312;&#19981;&#21516;&#30340; PHP &#29256;&#26412;&#20043;&#38388;&#36731;&#26494;&#20999;&#25442;&#12290;<\/h3>\n<p>&#21487;&#20197;&#23433;&#35013;&#30340;&#65306;<\/p>\n<pre><code>$ brew install phpenv\n$ phpenv install 7.4.0\n<\/code><\/pre>\n<p>&#36825;&#20004;&#31181;&#24037;&#20855;&#37117;&#20801;&#35768;&#24744;&#23433;&#35013;&#22810;&#20010;PHP&#29256;&#26412;&#65292;&#38656;&#35201;&#26102;&#21487;&#20197;&#38543;&#26102;&#20999;&#25442;&#23427;&#20204;&#12290;<\/p>\n<h2>&#35786;&#26029;&#38382;&#39064;<\/h2>\n<p>&#21319;&#32423;PHP&#26102;&#24120;&#35265;&#30340;&#38382;&#39064;&#21253;&#25324;&#32570;&#23569;&#25193;&#23637;&#25110;&#36335;&#24452;&#20914;&#31361;&#12290;&#30830;&#20445;&#23433;&#35013;&#20102;&#36866;&#24403;&#30340;PHP&#25193;&#23637;&#65292;&#26816;&#26597;&#24744;&#30340;PATH&#21464;&#37327;&#26159;&#21542;&#24341;&#29992;&#20102;&#27491;&#30830;&#30340;PHP&#29256;&#26412;&#12290;<\/p>\n<h2>&#32467;&#35770;<\/h2>\n<p>&#36825;&#31687;&#25991;&#31456;&#20840;&#38754;&#25351;&#23548;&#24744;&#22914;&#20309;&#22312;&#24744;&#30340;MacOS&#19978;&#21319;&#32423;PHP&#12290;&#25353;&#29031;&#36825;&#20123;&#27493;&#39588;&#25805;&#20316;&#65292;&#21487;&#20197;&#30830;&#20445;&#24744;&#36816;&#34892;&#21040;&#26368;&#26032;&#29256;&#26412;&#30340;PHP&#65292;&#20174;&#32780;&#21033;&#29992;&#26032;&#21151;&#33021;&#12289;&#20139;&#21463;&#24615;&#33021;&#25552;&#21319;&#20197;&#21450;&#22312;&#24320;&#21457;&#29615;&#22659;&#20013;&#20445;&#25345;&#39640;&#23433;&#20840;&#24615;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#20171;&#32461; &#20445;&#25345;&#22312; macOS &#19978;&#30340; PHP &#26356;&#26032;&#23545;&#20110;&#24320;&#21457;&#32773;&#20805;&#20998;&#21033;&#29992;&#038;#2..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-392","my1js","type-my1js","status-publish","hentry","my1js2nav-jcyy"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=392"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=392"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}