Posts

Showing posts with the label php

PHP 5.6 way to send AWS SNS topic message

This is an example PHP 5.6 script to send AWS SNS topic message. The architecture and assumption are as follow: Architecture: SNS (FIFO) -> SQS(FIFO) -> Lambda Only FIFO SNS can connect to FIFO SQS. Standard SNS cannot publish to FIFO SQS. Assumption: This script is executed in an EC2 instance. Assigned an AWS role to send SNS message. Because of above, supposed that there is no need to use Credential when creating SnsClient object. As the OS and PHP in this EC2 is old, the curl is already outdated. So it set http to false to bypass SSL verification.  Reference here . The $message part is designed for sending email for different vendor. In other words, it would vary in different case. Since SNS and SQS are FIFO, MessageGroupId must be set. It can be any random string, which is used to group message together for sending purpose. Here is the code <?php  require_once 'vendor/autoload.php'; use Aws\Sns\SnsClient; try{     $snsClient = new SnsClient([ ...

Cannot connect to MySQL from PHP(Permission Denied), even if commandline or other programs works

If your PHP code (e.g. adminer) cannot connect to your MySQL database (Error: Permission Denied), yet you can connect successfully via other program, like HeidiSQL or even command line, this is for you. Reference:  https://serverfault.com/a/667930/253676 It said even if you have SELinux disabled, Apache server still cannot connect to MySQL Noted what I wrote: Apache cannot connect to MySQL So you need to run (either one, not both): Permanent: `setsebool -P httpd_can_network_connect_db on` Temporary: `setsebool httpd_can_network_connect_db=1` Then you tried again, you should be fine.