如何在 nginx 中启动 PHP?在 nginx 中启动 PHP 的步骤:1. 安装 PHP;2. 安装 PHP-FPM;3. 配置 nginx 虚拟主机以使用 PHP-FPM。

如何启动 nginx 中的 PHP
简要回答:
在 nginx 中启动 PHP 的步骤:
详细说明:
立即学习“PHP免费学习笔记(深入)”;
1. 安装 PHP:
使用以下命令安装 PHP:
<code>sudo apt-get update sudo apt-get install php7.4-fpm</code>
2. 安装 PHP-FPM:
使用以下命令安装 PHP-FPM:
<code>sudo apt-get install php7.4-fpm</code>
3. 配置 nginx 虚拟主机:
打开虚拟主机配置文件(例如,/etc/nginx/sites-available/example.com),并添加以下配置:
<code>location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}</code>其中:
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:
<code>sudo systemctl restart nginx</code>
PHP 现在应该在 nginx 中启动并运行。
以上就是nginx怎么启动php的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号