Fatal error on Amazon AWS SDK StreamWrapper PHP - php

I am trying to install Amazon AWS SDK StreamWrapper on cPanel.
I have this code in my s3_Upload.php file:
<?php
require 'aws/aws.phar';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$s3Client= S3Client::factory(array(
'key' => "<key>",
'secret' => "<secret_key>"
));
$s3Client->registerStreamWrapper();
$s3Bucket = '<bucket_name>';
$s3Path = 's3://'.$s3Bucket;
if (file_exists($s3Path.'/<folder>/clip.mp4')) {
echo 'Clip exists!';
} else {
echo 'Clip doesnt exists!';
}
?>
and I have both the aws.phar file and extracted version of aws-sdk-php-master.zip.
Issue:
Whenever I try to go to www.example.com/s3_Upload.php it writes this error:
Fatal error: Class 'Phar' not found in /home/<user>/public_html/aws/aws.phar on line 17

It seems your PHP environment is missing PHP/PECL's Phar class. This is odd, because, according to the Phar Installation page, "The Phar extension is built into PHP as of PHP version 5.3.0.".
So either you need to make sure the Phar extension is installed, or you need to use the aws.zip.
Note: The aws.zip is not the same as the aws-sdk-php-master.zip you've mentioned. I assume what you have is just a download of the SDK source from GitHub. That zip file would not contain any of the SDKs dependencies like aws.phar and aws.zip do. To use the official aws.zip, please see Installing from the Zip from the AWS SDK for PHP User Guide.

Related

Error GRPC Spanner Google Cloud With PHP

I'm using PHP to try using the Google Cloud Spanner. I already did the gCloud settings and everything, and that's right. Now I need to make the connection via PHP to do a CRUD with the database that is in Spanner, but the code below always returns the error:
PHP Fatal error: Undefined constant 'Grpc\STATUS_UNKNOWN' in
/xxx/xxxx/www/vendor/google/cloud-spanner/Connection/Grpc.php on line
129
The code I have is:
<?php
require 'vendor/autoload.php';
use Google\Cloud\Spanner\SpannerClient;
/* Error start here */
$spanner = new SpannerClient([
'projectId' => 'my-project-id'
]);
$db = $spanner->connect('instance', 'database');
$userQuery = $db->execute('SELECT * FROM usuario WHERE login = #login', [
'parameters' => [
'login' => 'devteam'
]
]);
$user = $userQuery->rows()->current();
echo 'Hello ' . $user['login'];
The requirements I use in the composer are:
"require": {
"google/cloud": "^0.32.1",
"google/cloud-spanner": "^0.2.2"
}
I noticed that if I enter through the browser, the error presented above continues to appear. If I run the command php teste.php on the terminal, it runs the script correctly, ie, the terminal works and the browser does not.
Google Cloud PHP's spanner client is gRPC only. This means to use it you will need to install the gRPC PHP extension:
pecl install grpc
Once you have done that, add google/proto-client-php and google/gax to your composer.json and run composer update. After this is done, the error will be resolved.
For those wanting more detailed instructions, see this page for installing and enabling gRPC for PHP!
Since you mentioned that it works on CLI but not on browser, I can say that you need to enable the grpc extension on your php web server config.
E.g. Add
extension=grpc.so to your /etc/php/5.6/apache2/php.ini

Installing Composer with autoload.php and use Aws\* says Class not found

I'm running my php in cli under my user.
I have installed composer and autoloader.php does exist. Under vendor folders and file have been downloaded (autoload.php aws, bin, composer, guzzlehttp, mtdowling and psr)
Now in my php code I do:
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
$credentials = new Credentials('KEY', 'SECRETKEY');
$client = Route53Client::factory(array(
'credentials' => $credentials
));
When I run the script I get: PHP Fatal error: Class 'Credentials' not found in /home/user/updatedns.php on line 15
I tried running it a sudo also (in case it needs to write to the directory) and still get this error.
Just found out that use Aws\Common\Credentials\Credentials; is now under use Aws\Credentials\Credentials;

Elastic search configuration issue with client call php

I am using elasticsearch API php to build search results. I have configured everything in my xampp server. All the libraries downloaded from composer.json. In my composer.json file contains below code
{
"require": {
"elasticsearch/elasticsearch": "~2.0"
}
}
Libraries are successfully downloaded. After that i initialize the elastic search with below code
<?php
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
It shows fatal error like as follows
Fatal error: Class 'ClientBuilder' not found in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 4
So i change the config code as,
require_once 'vendor/autoload.php';
$es = new Elasticsearch\Client([
'hosts' => ['127.0.0.1:9200']]
]);
This also shows error like
Parse error: syntax error, unexpected ']' in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 10
I am following the below youtube tutorial to build the search
https://www.youtube.com/watch?v=3xb1dHLg-Lk
Please suggest what i went wrong in Elasticsearch - PHP.
My PHP Version is 5.5.9
i have initialize the clientbuilder class, now it works fine
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
you need install it with composer
composer require elasticsearch/elasticsearch

Fatal error: Class 'OpenCloud\Rackspace' not found

For a custom application, I am trying to integrate Rackspace cloud files using php-opencloud library.
This is the link I followed for setup -https://github.com/srijanaravali/php-opencloud/blob/master/docs/getting-started.md
# Install Composer
curl -sS https://getcomposer.org/installer | php
# Require php-opencloud as a dependency
php composer.phar require rackspace/php-opencloud:dev-master
However, when I try to instantiate a client object, it throws an error:
Fatal error: Class 'OpenCloud\Rackspace' not found in /var/www/example/Project/sites/all/libraries/php-opencloud/test.php on line 7
Here is the code snippet:
<?php
require 'vendor/autoload.php';
use OpenCloud\Rackspace;
// 1. Instantiate a Rackspace client.
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => getenv('Axxxxxxx'),
'apiKey' => getenv('abcxxxxxxxxxxxxxxxxxxxx')
));
print_r($client); die('!!');
Any pointers about whats missing?
Got it working. For some strange reason, php-opencloud library was empty under vendors/rackspace/php-opencloud.
Cloned one from github and created a symlink to it from above directory. It is working fine now.

S3Client creation fails on linux server

I have this code:
<?php
require('aws/aws-autoloader.php');
echo "1";
use Aws\S3\S3Client;
echo "2";
$s3Client = S3Client::factory(array(
'key' => 'mykey',
'secret' => 'mysecret',
));
echo "3";
echo "OK!";
?>
While on my machine the output is "123OK!" (as expected) after uploading it to the server I get only "12" (meaning the creation of the object fails?)
My local machine is running PHP 5.3.27 while the server is running 5.5.5-1chl1~precise1
Update:
The error I'm getting:
Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'The PHP cURL extension must be installed to use Guzzle.' in /var/www/api/1.0/aws/Guzzle/Http/Client.php:70 Stack trace: #0 /var/www/api/1.0/aws/Aws/Common/Client/AbstractClient.php(78): Guzzle\Http\Client->__construct('https://s3.amaz...', Object(Guzzle\Common\Collection)) #1
How do I install what is needed on a linux on C2?
sudo apt-get install php5-curl
sudo service apache2 restart
The error message says:
The PHP cURL extension must be installed to use Guzzle.
So… you need to install the PHP cURL extension.
how do I install it on a linux hosted on amazon?
It depends on the OS. Installing in Ubuntu is different from installing in Amazon Linux.
How about trying this :
<?php
require('aws/aws-autoloader.php');
use Aws\Common\Aws;
$aws_access_key = ''; // AWS Access key
$aws_access_security = ''; // AWS Security Key
$aws_default_region = 'ap-southeast-1'; // Your Default Region
$aws_default_scema = 'http'; // Default Protocol Schema
// Instantiate the AWS client with your AWS credentials
$aws = Aws::factory(array(
'key' => $aws_access_key,
'secret' => $aws_access_security,
'region' => $aws_default_region,
'scheme' => $aws_default_scema,
));
// Define S3client Object
$s3Client = $aws->get('s3');
// Test
var_dump($s3Client);
?>
That should work. But i think you should use composer method of AWS sdk use.
if you need a guide line or a script to work with s3, you can use my code on github : https://github.com/arizawan/aiss3clientphp

Categories