nginx怎么启动php服务器

nginx 通过 FastCGI 或 php-FPM 启动 PHP 服务器,具体步骤包括:安装 FastCGI 模块并配置 Nginx 配置文件,指定 PHP-FPM 套接字文件的位置。安装并配置 PHP-FPM,设置监听套接字文件和启动 PHP-FPM。在 Nginx 配置文件中添加代理 pass 配置,将 PHP 请求转发给 PHP-FPM 服务器(通常是 127.0.0.1:9000)。启动 Nginx,测试访问 PHP 文件以验证 PHP 服务器是否已启动。

nginx怎么启动php服务器

Nginx 如何启动 PHP 服务器

方法:

Nginx 通过 FastCGI 或 PHP-FPM 来启动 PHP 服务器,具体步骤如下:

FastCGI

  1. 安装 FastCGI 模块:sudo apt-get install libnginx-mod-fastcgi
  2. 配置 FastCGI 模块:在 Nginx 配置文件中,添加如下代码:

    location ~ .php$ {     fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;     fastcgi_index index.php;     include fastcgi_params; }

    注意,将路径 /var/run/php/php7.4-fpm.sock 替换为 PHP-FPM 套接字文件的位置。

PHP-FPM

  1. 安装 PHP-FPM:sudo apt-get install php-fpm
  2. 配置 PHP-FPM:编辑 /etc/php/7.4/fpm/pool.d/www.conf 文件,并设置以下选项:

    立即学习PHP免费学习笔记(深入)”;

    listen = /run/php/php7.4-fpm.sock
  3. 创建套接字文件:sudo mkdir /run/php/ && sudo chown www-data:www-data /run/php
  4. 启动 PHP-FPM:sudo systemctl start php7.4-fpm
  5. 配置 Nginx:在 Nginx 配置文件中,添加如下代码:

    location ~ .php$ {     proxy_pass http://127.0.0.1:9000; }

启动 Nginx

在配置完 FastCGI 或 PHP-FPM 后,启动 Nginx:sudo systemctl start nginx。

测试

访问一个 PHP 文件(例如 /var/www/html/index.php),以测试 PHP 服务器是否已启动。如果 PHP 脚本被正确执行,则会显示其输出。

以上就是

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享