在Debian系統上,LNMP指的是Linux、Nginx、MySQL和PHP的組合。要在Debian上安裝PHP擴展,您需要首先確保已經安裝了PHP和PHP-FPM。以下是在Debian上安裝PHP擴展的步驟:
sudo apt-get update
sudo apt-get install php7.4 php7.4-cli php7.4-fpm php7.4-json php7.4-opcache php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-pear php7.4-bcmath
sudo systemctl restart php7.4-fpm
配置Nginx以使用PHP-FPM。編輯Nginx的站點配置文件,通常位于/etc/nginx/sites-available/
目錄下。例如,如果您有一個名為example.com
的站點,您可以編輯/etc/nginx/sites-available/example.com
文件。
在server
塊中,找到location ~ \.php$
部分,將其修改為以下內容:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
現在,您已經成功地在Debian LNMP環境中安裝了PHP擴展。您可以通過創建一個名為info.php
的文件來測試PHP是否正常工作,將以下內容添加到該文件中:
<?php
phpinfo();
?>
將此文件放置在Nginx的根目錄(例如/var/www/html/
),然后在瀏覽器中訪問http://your_server_ip/info.php
。您應該看到一個顯示PHP信息的頁面,其中包括您安裝的所有擴展。