nginx怎么启动php(启动.nginx.php...)

wufei123 发布于 2024-08-18 阅读(39)
如何在 nginx 中启动 php?在 nginx 中启动 php 的步骤:1. 安装 php;2. 安装 php-fpm;3. 配置 nginx 虚拟主机以使用 php-fpm。

nginx怎么启动php

如何启动 nginx 中的 PHP

简要回答:

在 nginx 中启动 PHP 的步骤:

  1. 安装 PHP
  2. 安装 PHP-FPM(FastCGI 进程管理器)
  3. 配置 nginx 虚拟主机以使用 PHP-FPM

详细说明:

1. 安装 PHP:

使用以下命令安装 PHP:

PHP
sudo apt-get update
sudo apt-get install php7.4-fpm

2. 安装 PHP-FPM:

使用以下命令安装 PHP-FPM:

PHP
sudo apt-get install php7.4-fpm

3. 配置 nginx 虚拟主机:

打开虚拟主机配置文件(例如,/etc/nginx/sites-available/example.com),并添加以下配置:

PHP
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

其中:

  • location ~ \.php$:匹配所有以 .php 结尾的文件
  • try_files $uri =404;:如果文件不存在,则返回 404 错误
  • fastcgi_pass unix:/run/php/php7.4-fpm.sock;:将请求转发到 PHP-FPM 套接字
  • fastcgi_index index.php;:指定默认索引文件
  • include fastcgi_params;:包含 FastCGI 参数

保存并退出配置文件。

重启 nginx:

PHP
sudo systemctl restart nginx

PHP 现在应该在 nginx 中启动并运行。

以上就是nginx怎么启动php的详细内容,更多请关注知识资源分享宝库其它相关文章!

标签:  启动 nginx php 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。