Linux服务器上PHP配置全流程
一 安装与基础检查
二 配置文件与关键参数
三 与 Web 服务器集成
server {
listen 80;
server_name yourdomain.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php{version}-fpm.sock; # 按实际版本调整
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
四 PHP-FPM 进程与性能优化
五 测试与排错
<?php
phpinfo();
?>
访问 http://服务器IP/info.php,确认 PHP 版本、SAPI、Loaded Configuration File、扩展 是否正常。