PHP-FPM 在新的 Web 服务器上与 Nginx 的行为异常

PHP-FPM 在新的 Web 服务器上与 Nginx 的行为异常

因此,我正在转向一个新的网络服务器,主要是因为 CentOS 很快将不再存在,所以我要切换到 Debian 10。

我已经按我想要的方式配置了 Nginx 和 PHP,但是遇到了一个非常奇怪的问题。

PHP-FPM 似乎按预期工作,至少在一个域上(即我有一个 info.php 脚本,它按您想象的那样工作)。

但是,我创建了一个脚本,通过 Mailgun 通过 SMTP 发送邮件,该脚本可以直接通过 CLI 运行,但在通过 HTTP 加载页面时不会执行。但是,两个站点的 PHP-FPM 配置相同,另一个站点可以很好地运行它。我可以很好地在脚本上回显 - 它只是因为某种原因停止工作。

以下是我针对此站点的服务器指令:

server {

        # Site information
        server_name             joshuaquinlan.co.uk www.joshuaquinlan.co.uk;
        root                    /var/web-root/joshuaquinlan.co.uk/www;
        index                   index.html;

        # Error page locations
        error_page              404 /404.html;
        error_page              500 502 503 504 /50x.html;

        # Set expires for images, CSS and JS
        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
                expires         365d;
        }

        location / {
            try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/joshuaquinlan.co.uk/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/joshuaquinlan.co.uk/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.joshuaquinlan.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = joshuaquinlan.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        server_name             joshuaquinlan.co.uk www.joshuaquinlan.co.uk;
    listen 80;
    return 404; # managed by Certbot




}

脚本如下:

<?php

error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);

require_once "Mail.php";

$host = "ssl://smtp.eu.mailgun.org";
$username = "XXXXXXXXXXXXXXXXX";
$password = "XXXXXXXXXXXXXXX";
$port = "465";
$to = "XXXXXXXXXXXXXXXXXXXXX";
$email_from = "XXXXXXXXXXXXXXXXXXXXXXX";
$email_subject = "Subject Line Here:" ;
$email_body = "whatever you like" ;
$email_address = "[email protected]";

$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);


if (PEAR::isError($mail)) {
        echo("<p>" . $mail->getMessage() . "</p>");
} else {
        echo("<p>Message successfully sent!</p>");
}
?>

有任何想法吗?

谢谢,乔希

答案1

首先,尝试将端口更改为 587。首先测试一下,并检查 php/nginx 访问和错误日​​志。

你可能没有安装 Pear Mail 模块。尝试sudo pear install Mail

查看https://www.mailgun.com/blog/sending-email-using-the-mailgun-php-api/

另外,删除 ssl:// 以进行测试。

答案2

检查之后/var/log/nginx/error.log,好像是include_path我的文件中的设置php.ini不正确。

确实是这样的,添加 重启后include_path ".:/usr/share/pear"错误/etc/php/8.0/fpm/php.ini解决php-fpm

感谢大家的评论。

相关内容