手动编译安装的php没有fpm.sock文件,那nginx怎么配置才能调用php
如果手动编译安装的 PHP 没有创建 `fpm.sock` 文件,那么你可能需要配置 PHP-FPM 使用 TCP 端口而不是 Unix socket 文件。以下是配置 Nginx 以通过 TCP 端口调用 PHP 的步骤:
1. **配置 PHP-FPM 使用 TCP 端口**:
编辑 PHP-FPM 的配置文件,通常是 `/usr/local/etc/php-fpm.conf` 或 `/etc/php/5.6/fpm/php-fpm.conf`,找到以下配置块:
```ini
[www]
listen = 127.0.0.1:9000
```
确保这一行被取消注释,并且设置为你希望 PHP-FPM 监听的端口。默认端口是 9000。
保存并关闭文件后,重启 PHP-FPM 服务:
```bash
sudo systemctl restart php5.6-fpm
# 或者
sudo service php5.6-fpm restart
```
如果你没有创建 PHP-FPM 的服务文件,可能需要直接运行 PHP-FPM:
```bash
sudo /usr/local/php5.6/sbin/php-fpm
```
2. **配置 Nginx 以使用 TCP 端口与 PHP-FPM 通信**:
编辑 Nginx 的配置文件,通常是 `/etc/nginx/nginx.conf` 或特定于站点的配置文件(位于 `/etc/nginx/sites-available/` 或 `/etc/nginx/conf.d/`)。
在 `server` 块中,找到处理 PHP 请求的 `location` 块,并修改 `fastcgi_pass` 指令以指向 PHP-FPM 的 TCP 端口:
```nginx
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000; # 使用 TCP 端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
确保以上配置中的 `fastcgi_pass` 指令指向的是 PHP-FPM 监听的 IP 地址和端口。
3. **检查 Nginx 配置文件语法**:
在重新加载 Nginx 之前,检查配置文件的语法是否正确:
```bash
sudo nginx -t
```
4. **重新加载 Nginx**:
应用修改后的配置,重新加载 Nginx:
```bash
sudo systemctl reload nginx
# 或者
sudo service nginx reload
```
现在,Nginx 应该能够通过 TCP 端口与 PHP-FPM 通信,并且能够处理 PHP 请求。如果你遇到任何问题,请检查 Nginx 和 PHP-FPM 的日志文件以获取错误信息。