{"id":52197,"date":"2024-10-09T00:37:17","date_gmt":"2024-10-08T16:37:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/52197\/"},"modified":"2024-11-14T10:39:57","modified_gmt":"2024-11-14T02:39:57","slug":"ubuntu-%e4%b8%8a-php-%e7%9a%84%e5%ae%89%e8%a3%9d%e5%8f%8a%e5%a4%9a%e7%89%88%e6%9c%ac%e5%85%b1%e5%ad%98%e5%88%87%e6%8f%9b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/52197\/","title":{"rendered":"Ubuntu \u4e0a PHP \u7684\u5b89\u88dd\u53ca\u591a\u7248\u672c\u5171\u5b58\u5207\u63db"},"content":{"rendered":"<h1 id=\"ubuntu-%e4%b8%8a-php-%e7%9a%84%e5%ae%89%e8%a3%9d%e5%8f%8a%e5%a4%9a%e7%89%88%e6%9c%ac%e5%85%b1%e5%ad%98%e5%88%87%e6%8f%9b-EYAkDSTQWA\">Ubuntu \u4e0a PHP \u7684\u5b89\u88dd\u53ca\u591a\u7248\u672c\u5171\u5b58\u5207\u63db<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u9801\u958b\u767c\u74b0\u5883\u4e2d\uff0cPHP \u662f\u4e00\u7a2e\u5ee3\u6cdb\u4f7f\u7528\u7684\u4f3a\u670d\u5668\u7aef\u8173\u672c\u8a9e\u8a00\u3002\u96a8\u8457\u4e0d\u540c\u7248\u672c\u7684 PHP \u4e0d\u65b7\u63a8\u51fa\uff0c\u958b\u767c\u8005\u53ef\u80fd\u9700\u8981\u5728\u540c\u4e00\u53f0\u4f3a\u670d\u5668\u4e0a\u5b89\u88dd\u591a\u500b\u7248\u672c\u7684 PHP\uff0c\u4ee5\u4fbf\u65bc\u6e2c\u8a66\u548c\u517c\u5bb9\u6027\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu \u7cfb\u7d71\u4e0a\u5b89\u88dd PHP \u53ca\u5176\u591a\u7248\u672c\u5171\u5b58\u7684\u5207\u63db\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%ae%89%e8%a3%9d-php-EYAkDSTQWA\">\u4e00\u3001\u5b89\u88dd PHP<\/h2>\n<p>\u5728 Ubuntu \u4e0a\u5b89\u88dd PHP \u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u66f4\u65b0\u60a8\u7684\u5305\u7ba1\u7406\u5668\uff0c\u7136\u5f8c\u5b89\u88dd PHP \u53ca\u5176\u76f8\u95dc\u64f4\u5c55\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install php libapache2-mod-php php-mysql<\/code><\/pre>\n<p>\u9019\u5c07\u5b89\u88dd PHP \u7684\u6700\u65b0\u7a69\u5b9a\u7248\u672c\u4ee5\u53ca Apache \u4f3a\u670d\u5668\u7684 PHP \u6a21\u7d44\u548c MySQL \u64f4\u5c55\u3002<\/p>\n<h2 id=\"%e4%ba%8c%e3%80%81%e5%ae%89%e8%a3%9d%e5%a4%9a%e5%80%8b-php-%e7%89%88%e6%9c%ac-EYAkDSTQWA\">\u4e8c\u3001\u5b89\u88dd\u591a\u500b PHP \u7248\u672c<\/h2>\n<p>\u5982\u679c\u60a8\u9700\u8981\u5b89\u88dd\u591a\u500b PHP \u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>ondrej\/php<\/code> PPA\u3002\u9019\u662f\u4e00\u500b\u6d41\u884c\u7684\u7b2c\u4e09\u65b9 PPA\uff0c\u63d0\u4f9b\u591a\u500b PHP \u7248\u672c\u7684\u5b89\u88dd\u3002\u4ee5\u4e0b\u662f\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo add-apt-repository ppa:ondrej\/php\nsudo apt update<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u5b89\u88dd\u6240\u9700\u7684 PHP \u7248\u672c\uff0c\u4f8b\u5982 PHP 7.4 \u548c PHP 8.0\uff1a<\/p>\n<pre><code>sudo apt install php7.4 php7.4-cli php7.4-fpm\nsudo apt install php8.0 php8.0-cli php8.0-fpm<\/code><\/pre>\n<h2 id=\"%e4%b8%89%e3%80%81%e5%88%87%e6%8f%9b-php-%e7%89%88%e6%9c%ac-EYAkDSTQWA\">\u4e09\u3001\u5207\u63db PHP \u7248\u672c<\/h2>\n<p>\u5b89\u88dd\u591a\u500b PHP \u7248\u672c\u5f8c\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5728\u4e0d\u540c\u7248\u672c\u4e4b\u9593\u9032\u884c\u5207\u63db\u3002\u9019\u53ef\u4ee5\u901a\u904e\u4f7f\u7528 <code>update-alternatives<\/code> \u547d\u4ee4\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo update-alternatives --set php \/usr\/bin\/php7.4<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07 PHP \u7684\u9ed8\u8a8d\u7248\u672c\u8a2d\u7f6e\u70ba 7.4\u3002\u5982\u679c\u60a8\u60f3\u5207\u63db\u5230 PHP 8.0\uff0c\u53ea\u9700\u904b\u884c\uff1a<\/p>\n<pre><code>sudo update-alternatives --set php \/usr\/bin\/php8.0<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>php -v<\/code> \u547d\u4ee4\u4f86\u6aa2\u67e5\u7576\u524d\u7684 PHP \u7248\u672c\uff1a<\/p>\n<pre><code>php -v<\/code><\/pre>\n<h2 id=\"%e5%9b%9b%e3%80%81%e9%85%8d%e7%bd%ae-apache-%e4%bd%bf%e7%94%a8%e4%b8%8d%e5%90%8c%e7%9a%84-php-%e7%89%88%e6%9c%ac-EYAkDSTQWA\">\u56db\u3001\u914d\u7f6e Apache \u4f7f\u7528\u4e0d\u540c\u7684 PHP \u7248\u672c<\/h2>\n<p>\u5982\u679c\u60a8\u4f7f\u7528 Apache \u4f5c\u70ba\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u60a8\u53ef\u4ee5\u70ba\u4e0d\u540c\u7684\u865b\u64ec\u4e3b\u6a5f\u914d\u7f6e\u4e0d\u540c\u7684 PHP \u7248\u672c\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88dd\u76f8\u61c9\u7684 PHP \u6a21\u7d44\uff1a<\/p>\n<pre><code>sudo apt install libapache2-mod-php7.4\nsudo apt install libapache2-mod-php8.0<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u5728\u865b\u64ec\u4e3b\u6a5f\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u4f7f\u7528\u7684 PHP \u7248\u672c\u3002\u4f8b\u5982\uff0c\u7de8\u8f2f\u865b\u64ec\u4e3b\u6a5f\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/apache2\/sites-available\/example.com.conf<\/code><\/pre>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6dfb\u52a0\u4ee5\u4e0b\u884c\u4f86\u6307\u5b9a PHP \u7248\u672c\uff1a<\/p>\n<pre><code>SetHandler application\/x-httpd-php7.4<\/code><\/pre>\n<p>\u5b8c\u6210\u5f8c\uff0c\u91cd\u555f Apache \u4f3a\u670d\u5668\u4ee5\u61c9\u7528\u66f4\u6539\uff1a<\/p>\n<pre><code>sudo systemctl restart apache2<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-EYAkDSTQWA\">\u7e3d\u7d50<\/h2>\n<p>\u5728 Ubuntu \u4e0a\u5b89\u88dd PHP \u53ca\u5176\u591a\u7248\u672c\u5171\u5b58\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\uff0c\u901a\u904e\u4f7f\u7528 PPA \u548c <code>update-alternatives<\/code> \u547d\u4ee4\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5728\u4e0d\u540c\u7248\u672c\u4e4b\u9593\u5207\u63db\u3002\u9019\u5c0d\u65bc\u9700\u8981\u517c\u5bb9\u6027\u6e2c\u8a66\u7684\u958b\u767c\u8005\u4f86\u8aaa\u5c24\u70ba\u91cd\u8981\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\uff0c\u63d0\u4f9b\u9748\u6d3b\u7684\u914d\u7f6e\u9078\u64c7\u548c\u7a69\u5b9a\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 Ubuntu \u4e0a\u5b89\u88dd PHP \u53ca\u5be6\u73fe\u591a\u7248\u672c\u5171\u5b58\u8207\u5207\u63db\uff0c\u8f15\u9b06\u7ba1\u7406\u4e0d\u540c\u958b\u767c\u74b0\u5883\u9700\u6c42\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-52197","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=52197"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52197\/revisions"}],"predecessor-version":[{"id":52198,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52197\/revisions\/52198"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=52197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=52197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=52197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}