nginx 启动php
时间: 2023-07-31 13:11:28 浏览: 52
要在 Nginx 中启用 PHP,你需要安装 FastCGI 进程管理器和 PHP-FPM(PHP FastCGI 进程管理器)。然后,你需要配置 Nginx 服务器块以使用 PHP-FPM 进程管理器来处理 PHP 脚本。
以下是一些基本步骤:
1. 安装 FastCGI 进程管理器和 PHP-FPM:
```
sudo apt-get install php-fpm
```
2. 配置 PHP-FPM:
你需要编辑 /etc/php/7.x/fpm/pool.d/www.conf 文件来配置 PHP-FPM。你可以使用以下命令打开此文件:
```
sudo nano /etc/php/7.x/fpm/pool.d/www.conf
```
在文件中找到以下行,并更改以下值:
```
listen = /run/php/php7.x-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
```
将 php7.x 替换为你正在使用的 PHP 版本。
3. 配置 Nginx 服务器块:
你需要编辑 /etc/nginx/sites-available/default 文件并添加以下行:
```
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.x-fpm.sock;
}
```
将 php7.x 替换为你正在使用的 PHP 版本。
4. 重启 PHP-FPM 和 Nginx:
```
sudo systemctl restart php7.x-fpm
sudo systemctl restart nginx
```
现在,当你在 Nginx 上访问 PHP 文件时,Nginx 将使用 PHP-FPM 进程管理器来处理它们。