Nginx 通过 FastCGI 或 PHP-FPM 来启动 PHP 服务器,具体步骤如下:
FastCGI 安装 FastCGI 模块:sudo apt-get install libnginx-mod-fastcgi配置 FastCGI 模块:在 Nginx 配置文件中,添加如下代码:
location ~ \.php$ { fastcgi_pass unix:/var/run/php/<a style="color:#f60; text-decoration:underline;" href="https://www.php.cn/zt/15965.html" target="_blank">php7</a>.4-fpm.sock; fastcgi_index index.php; include fastcgi_params; }注意,将路径 /var/run/php/php7.4-fpm.sock 替换为 PHP-FPM 套接字文件的位置。
PHP-FPM 安装 PHP-FPM:sudo apt-get install php-fpm配置 PHP-FPM:编辑 /etc/php/7.4/fpm/pool.d/www.conf 文件,并设置以下选项:
listen = /run/php/php7.4-fpm.sock 创建套接字文件:sudo mkdir /run/php/ && sudo chown www-data:www-data /run/php 启动 PHP-FPM:sudo systemctl start php7.4-fpm配置 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 脚本被正确执行,则会显示其输出。
以上就是nginx怎么启动php服务器的详细内容,更多请关注知识资源分享宝库其它相关文章!
版权声明
本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com
发表评论