{"id":3798,"date":"2025-06-28T13:17:20","date_gmt":"2025-06-28T05:17:20","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=3798"},"modified":"2025-06-28T13:17:20","modified_gmt":"2025-06-28T05:17:20","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8linux%e4%b8%8a%e5%ae%89%e8%a3%85php%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/06\/28\/%e5%a6%82%e4%bd%95%e5%9c%a8linux%e4%b8%8a%e5%ae%89%e8%a3%85php%ef%bc%9f\/","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e0a\u5b89\u88c5PHP\uff1f"},"content":{"rendered":"\n<p>\u5728 Linux \u4e0a\u5b89\u88c5 PHP \u7684\u65b9\u5f0f\u4f1a\u6839\u636e\u4f60\u4f7f\u7528\u7684 Linux \u53d1\u884c\u7248\uff08\u5982 Ubuntu\u3001Debian\u3001CentOS\u3001AlmaLinux\u3001Arch \u7b49\uff09\u7565\u6709\u4e0d\u540c\u3002\u4e0b\u9762\u5c06\u4ece<strong>\u4e13\u4e1a<\/strong>\u7684\u89d2\u5ea6\u63d0\u4f9b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u540c\u53d1\u884c\u7248\u4e0a\u7684\u5b89\u88c5\u547d\u4ee4<\/li>\n\n\n\n<li>\u63a8\u8350\u7684 PHP \u6269\u5c55<\/li>\n\n\n\n<li>\u914d\u5957\u5b89\u88c5 Apache\/Nginx<\/li>\n\n\n\n<li>\u6743\u5a01\u94fe\u63a5 &amp; \u914d\u7f6e\u9a8c\u8bc1\u65b9\u6cd5<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u786e\u5b9a\u4f60\u7684\u53d1\u884c\u7248<\/h2>\n\n\n\n<p>\u5148\u8fd0\u884c\u547d\u4ee4\u786e\u8ba4\u7cfb\u7edf\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/os-release<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u5728\u4e3b\u6d41\u53d1\u884c\u7248\u4e0a\u5b89\u88c5 PHP<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Ubuntu \/ Debian \u7cfb<\/h3>\n\n\n\n<p>\u63a8\u8350\u4f7f\u7528 <a href=\"https:\/\/launchpad.net\/~ondrej\/+archive\/ubuntu\/php\">Ond\u0159ej Sur\u00fd \u7684 PHP PPA<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common\nsudo add-apt-repository ppa:ondrej\/php\nsudo apt update\nsudo apt install -y php php-cli php-common<\/code><\/pre>\n\n\n\n<p>\u53ef\u5b89\u88c5\u989d\u5916\u6a21\u5757\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php-mysql php-gd php-curl php-mbstring php-xml php-zip php-bcmath<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">RHEL \/ CentOS \/ AlmaLinux \/ Rocky Linux<\/h3>\n\n\n\n<p>\u63a8\u8350\u4f7f\u7528 <a href=\"https:\/\/rpms.remirepo.net\/\">Remi \u4ed3\u5e93<\/a>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y epel-release\nsudo dnf install -y https:\/\/rpms.remirepo.net\/enterprise\/remi-release-8.rpm\nsudo dnf module reset php\nsudo dnf module enable php:remi-8.2\nsudo dnf install -y php php-cli php-common php-mysqlnd php-gd php-xml php-mbstring php-json php-zip<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Arch Linux \/ Manjaro<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pacman -Syu php<\/code><\/pre>\n\n\n\n<p>\u5e38\u7528\u6269\u5c55\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pacman -S php-gd php-curl php-intl php-mcrypt php-mysql php-xmlrpc<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u914d\u5408 Web \u670d\u52a1\u5668\u4f7f\u7528 PHP<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Apache + PHP\uff08Ubuntu \u793a\u4f8b\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y apache2 libapache2-mod-php\nsudo systemctl enable apache2\nsudo systemctl start apache2<\/code><\/pre>\n\n\n\n<p>Apache \u9ed8\u8ba4\u652f\u6301 PHP\uff0c\u7f51\u7ad9\u76ee\u5f55\u4e3a <code>\/var\/www\/html<\/code><\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"&lt;?php phpinfo(); ?&gt;\" | sudo tee \/var\/www\/html\/index.php<\/code><\/pre>\n\n\n\n<p>\u8bbf\u95ee\uff1a<code>http:\/\/localhost\/index.php<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Nginx + PHP-FPM\uff08Ubuntu \u793a\u4f8b\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y nginx php-fpm<\/code><\/pre>\n\n\n\n<p>\u4fee\u6539 <code>\/etc\/nginx\/sites-available\/default<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>location ~ \\.php$ {\n    include snippets\/fastcgi-php.conf;\n    fastcgi_pass unix:\/run\/php\/php8.2-fpm.sock;  # \u6839\u636e\u7248\u672c\u4fee\u6539\n}<\/code><\/pre>\n\n\n\n<p>\u91cd\u542f\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u6d4b\u8bd5 PHP \u5b89\u88c5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v             # \u67e5\u770b\u7248\u672c\nphp -m             # \u67e5\u770b\u5df2\u542f\u7528\u6269\u5c55\nphp -r \"phpinfo();\"  # \u8f93\u51fa\u7b80\u8981 phpinfo \u4fe1\u606f<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u5e38\u7528 PHP \u6269\u5c55\uff08\u5f00\u53d1\u73af\u5883\uff09<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6269\u5c55<\/th><th>\u7528\u9014<\/th><\/tr><\/thead><tbody><tr><td>php-mysql \/ php-mysqlnd<\/td><td>\u8fde\u63a5 MySQL<\/td><\/tr><tr><td>php-gd<\/td><td>\u56fe\u7247\u5904\u7406\uff08\u9a8c\u8bc1\u7801\u3001\u7f29\u7565\u56fe\uff09<\/td><\/tr><tr><td>php-curl<\/td><td>\u8bf7\u6c42\u63a5\u53e3<\/td><\/tr><tr><td>php-mbstring<\/td><td>\u591a\u5b57\u8282\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>php-xml<\/td><td>\u89e3\u6790 XML\uff08\u5982 DOMDocument\uff09<\/td><\/tr><tr><td>php-zip<\/td><td>\u5904\u7406\u538b\u7f29\u5305<\/td><\/tr><tr><td>php-bcmath<\/td><td>\u7cbe\u5ea6\u9ad8\u7684\u6570\u5b66\u8ba1\u7b97<\/td><\/tr><tr><td>php-intl<\/td><td>\u56fd\u9645\u5316<\/td><\/tr><tr><td>php-xdebug<\/td><td>\u8c03\u8bd5\u5de5\u5177\uff08\u5f00\u53d1\u65f6\u7528\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6. \u6743\u5a01\u8d44\u6599\u94fe\u63a5<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP \u5b98\u7f51\uff08\u5b89\u88c5\u8bf4\u660e\uff09\uff1a<a href=\"https:\/\/www.php.net\/manual\/en\/install.php\">https:\/\/www.php.net\/manual\/en\/install.php<\/a><\/li>\n\n\n\n<li>Ond\u0159ej PPA\uff08Ubuntu\uff09\uff1a<a href=\"https:\/\/launchpad.net\/~ondrej\/+archive\/ubuntu\/php\">https:\/\/launchpad.net\/~ondrej\/+archive\/ubuntu\/php<\/a><\/li>\n\n\n\n<li>Remi Repo\uff08CentOS\/RHEL\uff09\uff1a<a href=\"https:\/\/rpms.remirepo.net\/\">https:\/\/rpms.remirepo.net\/<\/a><\/li>\n\n\n\n<li>PHP \u6269\u5c55\u6587\u6863\uff1a<a href=\"https:\/\/www.php.net\/manual\/en\/extensions.alphabetical.php\">https:\/\/www.php.net\/manual\/en\/extensions.alphabetical.php<\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7. \u5feb\u901f\u9009\u62e9\u6307\u5357<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u76ee\u6807<\/th><th>\u63a8\u8350\u65b9\u6cd5<\/th><\/tr><\/thead><tbody><tr><td>\u65e5\u5e38 Linux \u5f00\u53d1<\/td><td>\u4f7f\u7528\u7cfb\u7edf\u5305\u7ba1\u7406\u5668\u5b89\u88c5 PHP + \u6269\u5c55<\/td><\/tr><tr><td>\u60f3\u8981\u6700\u65b0\u7248\u672c<\/td><td>Ubuntu \u7528 PPA\uff0cCentOS \u7528 Remi Repo<\/td><\/tr><tr><td>Web \u9879\u76ee\u90e8\u7f72<\/td><td>\u4f7f\u7528 Apache \/ Nginx \u914d\u5408 PHP-FPM<\/td><\/tr><tr><td>\u60f3\u7528\u5bb9\u5668\u73af\u5883<\/td><td>\u4f7f\u7528 Docker\uff1a<code>php:8.2-apache<\/code><\/td><\/tr><tr><td>\u60f3\u7528 Laravel \u7b49\u6846\u67b6<\/td><td>\u5b89\u88c5 PHP\u3001MySQL\u3001Composer\u3001Node.js \u914d\u5957\u73af\u5883<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Linux \u4e0a\u5b89\u88c5 PHP \u7684\u65b9\u5f0f\u4f1a\u6839\u636e\u4f60\u4f7f\u7528\u7684 Linux \u53d1\u884c\u7248\uff08\u5982 Ubuntu\u3001Debian\u3001Ce [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3799,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-3798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=3798"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3798\/revisions"}],"predecessor-version":[{"id":3800,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3798\/revisions\/3800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media\/3799"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=3798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=3798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=3798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}