LNMP是Linux、Nginx、MySQL和PHP的縮寫,它是一種非常流行的Web服務器軟件組合。配置PHP環境的過程如下:
sudo apt-get update
sudo apt-get install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-pear php-zip
在CentOS或RHEL上,可以使用以下命令:
sudo yum install epel-release
sudo yum install php-fpm php-mysqlnd php-curl php-gd php-mbstring php-xml php-pear php-zip
/etc/php/{版本號}/fpm/pool.d/www.conf
。在CentOS或RHEL上,配置文件通常位于/etc/php-fpm.d/www.conf
。編輯配置文件,找到listen
指令,將其值更改為Unix套接字或TCP/IP地址。例如,使用Unix套接字:
listen = /run/php/php{版本號}-fpm.sock
或者使用TCP/IP地址:
listen = 127.0.0.1:9000
同時,確保listen.owner
和listen.group
指令設置為正確的用戶和組,通常為www-data
或nginx
。
/etc/nginx/sites-available/{站點名}
),在location
塊中添加以下內容:location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php{版本號}-fpm.sock; # 或者使用TCP/IP地址:fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
這里的{版本號}
需要替換為實際安裝的PHP版本號。
在Ubuntu或Debian上:
sudo systemctl restart php{版本號}-fpm
sudo systemctl restart nginx
在CentOS或RHEL上:
sudo systemctl restart php-fpm
sudo systemctl restart nginx
info.php
的文件,將其放在Nginx的根目錄(例如/var/www/html
),并添加以下內容:<?php
phpinfo();
?>
在瀏覽器中訪問http://your_server_ip/info.php
,如果看到PHP信息頁面,則表示PHP環境配置成功。最后,為了安全起見,刪除info.php
文件。