- First install Composer and PHP for the jailed user. This article has the steps
- composer require aws/aws-sdk-php — as the jailed user
- There might be an error –
fopen(/usr/share/php/Composer/Autoload/../../../doc/composer/copyright): failed to open stream: No such file or directory - You can copy the file using the root login
- mkdir -p /var/www/clients/client1/web1/usr/share/doc/composer
- cp /usr/share/doc/composer/copyright /var/www/clients/client1/web1/usr/share/doc/composer/
- chown web1:client1 /var/www/clients/client1/web1/usr/share/doc/composer/copyright
Tag Archives: php
Web 3D experiments with ThreeJS
Here is an experiment where a fixed background (or texture) has been used behind an interact-able 3D model. The model was created using Blender. From Blender (or any other 3D software) export the model as FBX file.
The code formatting is getting horribly misaligned when pasted here. So here is the whole folder. Run the webgl_loader_fbx2.php. Though I have included files.js, but it not needed for this experiment.
three.js-experiments — Download sample app from here.
Here is a sample 3D box created using Blender (fbx format).
PHP code for Amazon SNS Auto Subscription Confirmation (HTTPS)
Amazon Simple Notification Service or SNS is a messaging service which be used to send notifications by SMS, Email, Push notification or to a URL endpoint.
For a quick on setting up Amazon SNS see this article Amazon SNS setup for HTTPS and Email
Code for auto confirmation of subscriptions
<?php $json_write_to_text = file_get_contents("php://input"); //read the raw data $json_write_to_text = json_decode($json_write_to_text, TRUE, 512, JSON_OBJECT_AS_ARRAY); if($json_write_to_text['Type'] == SubscriptionConfirmation) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $json_write_to_text['SubscribeURL'], CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => $header, )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); } file_put_contents("response.txt",print_r($json_write_to_text,true)); // this is just for dumping the raw data and can be omitted ?>
Amazon SNS setup for HTTPS and Email
Login to AWS Console
Goto Simple Notification Service
Create a Topic
Add a Subscription – the easy and safe way to do this is by clicking the ARN of the Topic (in the topic listing page ) and going to the Topic details page.
Choose your subscription protocol (in simpler words in which way you want the notifications to be delivered)
Amazon SNS will do a verification. The method depends on the protocol chosen. For example for emails it will send an email with a verification link, for HTTP or HTTPS it will call the endpoint with some data like below. On opening or hitting the SubscribeURL the verification will be complete.
Array ( [Type] => SubscriptionConfirmation [MessageId] => eeexxxea-xxxx-xxxx-xxxx-c15xxxx81361 [Token] => 2336412f3xxxxxxxxxxxxxxxxxxxxxxxxee34aadbb4eb9c926c288f8ca1xxxxxxxxxxxxcbe27c6835edd47bd28d0cf1d0cb9b4xxxxxxxx1003b95c6bc1231db657b1bb465a7d98c73a8d79faddb473a1a109c45654a1db1f11xxxxxxxxxxxxxxxxxxxf74dae61acfbe2f508901390b2cd6 [TopicArn] => arn:aws:sns:us-east-x:0xxxxxxxxxx9:xxx-bounce [Message] => You have chosen to subscribe to the topic arn:aws:sns:us-east-x:0xxxxxxxxxx9:xxx-bounce. To confirm the subscription, visit the SubscribeURL included in this message. [SubscribeURL] => https://sns.us-east-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-x:0xxxxxxxxxx9:xxx-bounce&Token=2336412f3xxxxxxxxxxxxxxxxxxxxxxxxee34aadbb4eb9c926c288f8ca1xxxxxxxxxxxxcbe27c6835edd47bd28d0cf1d0cb9b4xxxxxxxx1003b95c6bc1231db657b1bb465a7d98c73a8d79faddb473a1a109c45654a1db1f11xxxxxxxxxxxxxxxxxxxf74dae61acfbe2f508901390b2cd6 [Timestamp] => 2019-01-09T14:53:31.247Z [SignatureVersion] => 1 [Signature] => euyT80G1NujWgQMWfltxxxxxxxxxxxxxxxiDqeicbE1FH5dwdBnAA7UY84zHf0fsJCd/xxxxxxxxxxxxxxxxxxxxxxxxx/rxx/t/wKxxxxxx/LKg2QwcjGPdnIh4xp6rNA4PKihOjMiPfTZYH4kQV+h+4zqFsQT1UL+ixlM+xBZqZY3zUV1lrHKz+SfIkPJxxxxxxxxxxIB2FN0O2leokHJYRlUqxxxxxxkMzlbsMg4ChDW8+hcJ14hNEz5kpM5T0Fqljt2CmqkF1BQ68ViTgFV7yYpcSTbejo0DuZAUxxxxxxxxxx5y340TcfTWWq+3hKSTtB9aTclgDchvLDYKNqg== [SigningCertURL] => https://sns.us-east-x.amazonaws.com/SimpleNotificationService-ac56xxxxxxxxxxxxxxxxxxxx8aa1d9b.pem )
Once the verification is complete the Subscription ID will show an ARN. See The Topic Details picture.
Sample PHP code for auto-verification of SNS Subscriptions for HTTP/HTTPS protocols PHP code for Amazon SNS Auto Subscription Confirmation (HTTPS)
ISPConfig PHP-FPM Session Problem
The problem I was facing – session variables not getting passed from page to page. On page1.php I set some session variables and then on going to page2.php all I was getting was Array() ! The problem drove me crazy as everything settings and permissions were fine.
I have ISPConfig 3 on Ubuntu 18.04 and PHP 7.2.
Session path, folder ownership, folder permission, cookie path everything was fine. On checking the Session folder found that the session file is getting created properly and the session variables also got saved in files properly. Also had session_start() at the beginning of every page. And there was no error or warnings. But when going to next page – nothing in session!
Then on further analysis found the issue is all about the PHPSESSID cookie being set by ISPConfig control panel. After logging out of ISPConfig panel when I opened my pages the SESSION variables got passed fine.
I spent a whole day trying to find issues with the setup or server configuration. Hope this saves someone else’s time.