简体   繁体   中英

How to install php-pear to AWS EC2

I'm new to Amazon EC2. I'm trying to install php-pear in my Amazon server. But i got some error below like enter image description here

Can someone help me?

Assuming you already have php installed, you can follow below steps

  1. Elevate Privileges : This step is important for pear to be installed standard directory. If you skip this, pear will be installed in ec2-user directory and will be pretty much unusable due to a ton of ownership and permission issues.

    sudo -i

  2. Download and Install Pear
    wget http://pear.php.net/go-pear.phar php go-pear.phar

  3. Install Mail and Net_SMTP Packages
    pear install Mail pear install Net_SMTP

The installation will ask for updating the php.ini file. Please do that.

I just installed it earlier today on my EC2 Linux instance running PHP7 as follows:

sudo yum install php7-pear

Once installed:

pear install Mail
pear install Net_SMTP

However it was not piece of cake after that. I ran into other challenges related to SMTP settings related to PHP7 and Postfix, which gave some hard time for my specific case, since I wanted to send out base64 encoded image inline, which apparently is a very unusual case since I couldn't find any help at all for it. However, for a simple email sending out, all you need is the following code:

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>");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM