如何在AWS EC2上安装php-pear

3
我是Amazon EC2的新手。 我正在尝试在我的Amazon服务器上安装php-pear。 但是我遇到了以下错误: 点击此处查看图片 有人能帮帮我吗?

请查看此链接 http://jafty.com/blog/installing-pear-on-amazon-ec2-or-ubuntu-linux-server/。 - istaro
谢谢,它对我有效。 - Lin
2个回答

1

我今天早些时候在运行PHP7的EC2 Linux实例上安装了它,方法如下:

sudo yum install php7-pear

一旦安装:

pear install Mail
pear install Net_SMTP

然而,接下来并不是一件轻松的事情。我遇到了与PHP7和Postfix相关的SMTP设置方面的其他挑战,这对于我的特定情况造成了一些困难,因为我想要发送内联的base64编码图像,这显然是一个非常不寻常的情况,因为我找不到任何有用的帮助。然而,对于简单的电子邮件发送,您只需要以下代码:
require_once "Mail.php";
$from = "My Name <no-reply@example.com>";
$host = "smtp.example.com";
$port = "587";
$username = "user@example.com";
$password = "password";
$subject = "Some subject";
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
$body = "\r\n\r\n--" . $boundary . "\r\n";
$body .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= "This is the message body.";
$body .= "\r\n\r\n--" . $boundary . "\r\n";

$smtp = Mail::factory('smtp', array(
            'debug' => true,
            'host' => $host,
            'port' => $port,
            'auth' => true,
            'username' => $username,
            'password' => $password));

$mail = $smtp->send($to, $headers, $body);

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

0

假设您已经安装了PHP,您可以按照以下步骤进行操作

  1. 提升权限:此步骤对于pear被安装在标准目录中非常重要。如果您跳过此步骤,pear将安装在ec2-user目录中,并且由于拥有和权限问题,它几乎无法使用。

    sudo -i

  2. 下载并安装Pear
    wget http://pear.php.net/go-pear.phar php go-pear.phar

  3. 安装Mail和Net_SMTP Packages
    pear install Mail pear install Net_SMTP

安装程序会要求更新php.ini文件。请完成这一步骤。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接