Linux服务器上配置PHP的实用步骤
一 准备与安装
二 找到并修改 php.ini
三 与 Web 服务器集成
server {
listen 80;
server_name your_domain_or_ip;
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:/var/run/php/php{version}-fpm.sock; # 版本号需与实际一致
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
四 测试与验证
<?php
phpinfo();
五 常见问题与优化