CentOS7 LNMP FPM 環(huán)境部署全流程解析
環(huán)境準備與系統(tǒng)更新
執(zhí)行系統(tǒng)更新命令確保軟件包處于最新狀態(tài):
yum update -y
Nginx 安裝與配置
通過EPEL倉庫安裝Nginx服務:
yum install epel-release -y
yum install nginx -y
systemctl start nginx
systemctl enable nginx
在/etc/nginx/conf.d/
目錄創(chuàng)建虛擬主機配置文件,設置域名解析與根目錄路徑。
MariaDB 數(shù)據(jù)庫部署
安裝最新版MariaDB并初始化安全設置:
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
PHP-FPM 集成方案
添加Webtatic倉庫安裝PHP7.4+版本:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php74w-fpm php74w-mysqlnd php74w-opcache -y
修改/etc/php-fpm.d/www.conf
文件,設置進程運行用戶為nginx:
user = nginx
group = nginx
服務聯(lián)動與測試驗證
在Nginx配置文件中添加PHP解析規(guī)則:
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
創(chuàng)建phpinfo.php
測試文件驗證環(huán)境:
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/phpinfo.php
性能調(diào)優(yōu)建議
- 調(diào)整PHP-FPM進程池參數(shù)
pm.max_children
- 啟用Nginx的gzip壓縮與緩存機制
- 配置MySQL的InnoDB緩沖池大小
- 設置OPcache加速PHP腳本執(zhí)行
防火墻與安全加固
開放HTTP/HTTPS服務端口:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload