Uncaught exception 'RuntimeException' PHP and cPanel - php

I am trying to dynamically create Subdomains from my website CMS.
I have created the following script:
require_once "/usr/local/cpanel/php/cpanel.php";
$cpanel = new CPANEL();
$get_userdata = $cpanel->uapi(
'DomainInfo', 'domains_data',
array(
'format' => 'hash',
)
);
$addsubdomain = $cpanel->api2(
'SubDomain', 'addsubdomain',
array(
'domain' => ''. $subdomain .'',
'rootdomain' => 'REMOVED',
'dir' => '/public_html/',
'disallowdot' => '1',
)
);
I am getting the following error:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'There was a problem fetching the env variablecontaining the path to the socket' in /usr/local/cpanel/php/cpanel.php:146
Why is this and what am I doing wrong?

You get this error when you're trying to use LiveAPI in PHP Script outside the cPanel's document root.
According to cPanel, LiveAPI can be used only from withing cPanel's document root: /usr/local/cpanel/base/frontend/, /usr/local/cpanel/base/3rdparty/.

Related

Why this $_SERVER['SERVER_NAME'] code in PHP is giving me error?

I am new to programming, and I decided to try PHP.
I am trying to set the variable $_SERVER["SERVER_NAME"].
Unfortunately, I'm getting some errors.
The code is copied from this Youtube tutorial, so it is supposed to be correct.
$server = [
'Host Server Name' => $_SERVER['SERVER_NAME'],
'Host Header' => $_SERVER['HTTP_HOST'],
'Server Software' => $_SERVER['SERVER_SOFTWARE'],
'Document Root' => $_SERVER['DOCUMENT_ROOT'],
'Current Page' => $_SERVER['PHP_SELF'],
'Script Name' => $_SERVER['SCRIPT_NAME'],
'Absolute Path' => $_SERVER['SCRIPT_FILENAME']
];
//print_r($server);
// Create Client Array
$client = [
'Client System info' => $_SERVER['HTTP_USER_AGENT'],
'Client IP' => $_SERVER['REMOTE_ADDR'],
'Remote Port' => $_SERVER['REMOTE_PORT']
];
The error:
Notice: Undefined variable:** server in C:\xampp\htdocs\phpsandbox\website2\server-info.php on line 7
Fatal error: Uncaught Error: Unsupported operand types in C:\xampp\htdocs\phpsandbox\website2\server-info.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\phpsandbox\website2\server-info.php on line 7
Thanks to anyone for the support!

Setting up environment in Yii Framework

I'm having trouble setting an Environment for Yii Framework. Probably is an easy task for someone who knows it, but the documentation of this ir rather poor and I couldn't solve it by myself. Any help would be apprecitated, I don't get to SO until I waste all my resources.
The error I get is:
Fatal error: Uncaught exception 'Exception' with message '"SetEnv YII_ENVIRONMENT <mode>" not defined in Apache config.' in /home/(ommited)/app/extensions/Environment.php:235
Stack trace: #0 /home/(ommited)/app/extensions/Environment.php(209): Environment->getMode(NULL, false) #1 /home/marcelo/myprojects/bocaweb/boca-sitioweb/html/index.php(10):
Environment->__construct() #2 {main} thrown in /home/(ommited)/app/extensions/Environment.php on line 235
My mode_development.php
<?php
return array(
'yiiDebug' => false,
'yiiTraceLevel' => 3,
'configWeb' => array(
'components' => array(// Database
'mongodb' => array(
'class' => 'EMongoClient',
'server' => 'mongodb://(ommited)',
'db' => '(ommited)',
'RP' => array('RP_PRIMARY', array())
),
),
),
'configConsole' => array(),
);
index.php
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
//Envirment and global
require_once(dirname(dirname(__FILE__)) . '/app/components/ArtfosEnvironment.php');
require_once(dirname(dirname(__FILE__)) . '/app/globals.php');
$env = new ArtfosEnvironment();
defined('YII_DEBUG') or define('YII_DEBUG', $env->yiiDebug);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', $env->yiiTraceLevel);
require_once($env->yiiPath);
$env->runYiiStatics(); // like Yii::setPathOfAlias()
$yiiApp = Yii::createWebApplication($env->configWeb);
$yiiApp->run();
Is the Yii framework folder in the directory beside your local? Make sure that your site knows the location of the framework as that's where it will get all it's resources.
Try I would like to move yii framework folder outside of www access

Mailgun : Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open

I have used the following code and I have placed these files in the same directory as of the script I am running to send the mail. The exception continues to be thrown even when I try to give an online link.
I am trying this piece of PHP code in my local host which you can figure out from the error below
# Include the Autoloader (see "Libraries" for install instructions)
require 'mail/vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-secret');
$domain = "mydomain";
$result = $mgClient->sendMessage($domain, array(
'from' => 'email',
'to' => 'email',
'bcc' => 'email',
'subject' => "Sending Attachment 2",
'text' => "Sending Attachment",
'html' => "Sending Attachment",
'attachment-1'=> 'test.xml'
), array("attachment" => array(
array('filePath' => '#/file.txt',
'remoteName' => 'file.txt'),
array('filePath' => '#/test.txt',
'remoteName' => 'test.txt'))));
Fatal error: Uncaught exception
'Guzzle\Common\Exception\InvalidArgumentException' with message
'Unable to open /file.txt for reading' in
C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php:53
Stack trace: #0
C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php(28):
Guzzle\Http\Message\PostFile->setFilename('#/file.txt') #1
C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\EntityEnclosingRequest.php(199):
Guzzle\Http\Message\PostFile->__construct('attachment', '#/file.txt',
NULL, 'file.txt') #2
C:\xampp\htdocs\zendeskapis\mail\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php(52):
Guzzle\Http\Message\EntityEnclosingRequest->addPostFile('attachment',
'#/file.txt', NULL, 'file.txt') #3
C:\xampp\htdocs\zendeskapis\mail\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(80):
Mailgun\Connection\RestClient->post('hotelpalmshore....', Array,
Array) #4 C:\xampp\htdocs\zendeskapis\mail\vendor\mailgun\mailgun-php\
in
C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php
on line 53
As the exception state it, your file path doesn't seem to be correct.
Assuming you're on a nix system, your file.txt should be right under / which seems quite unlikely to me.
If you're on a windows system the path /file.txt does not have any meaning.
Try to hardcode first your path, once it will work set it dynamically

AWS Lambda PHP Create Function with Zip

I'm trying to create a PHP script that creates a function from some code that i zip up on our server. I uploaded the file manually to lambda, and it works fine. But when i try to use the aws sdk to create the function, it fails with an error message. Anyone got any clue?
Code:
private function createLambdaFunction() {
$result = $this->lambdaConn->createFunction(array(
'FunctionName' => $this->lambdaFunctionName,
'Runtime' => $this->runtime,
'Role' => $this->role,
'Handler' => $this->lambdaFunctionName.".".$this->handler,
'Description' => $this->description,
'Timeout' => $this->timeout,
'MemorySize' => $this->memorySize,
'Code' => array(
'ZipFile' => 'fileb://test.zip'
)
));
Error:
PHP Fatal error: Uncaught Aws\Lambda\Exception\LambdaException: AWS
Error Code: InvalidParameterValueException,
Status Code: 400, AWS Request ID: asdf, AWS Error Type: user,
AWS Error Message: Could not unzip uploaded file. Please check
your file, then try to upload again., User-Agent:
aws-sdk-php2/2.8.10 Guzzle/3.9.3 curl/7.35.0 PHP/5.5.9-1ubuntu4.9
I can't seem to find a good example on google, and the documentation is...less than ideal. I created the zip file with php, so I've tried passing that var, the full path to the file, relative path to file, etc. Finally learned you have to use fileb:// preface, but that didn't end up fixing anything.
Okay, I'm not sure why this is the case, but you need to base64 encode your zip file like:
$result = $this->lambdaConn->createFunction(array(
'FunctionName' => $this->lambdaFunctionName,
'Runtime' => $this->runtime,
'Role' => $this->role,
'Handler' => $this->lambdaFunctionName . "." . $this->handler,
'Description' => $this->description,
'Timeout' => $this->timeout,
'MemorySize' => $this->memorySize,
'Code' => array(
'ZipFile' => 'fileb://'.base64_encode(file_get_contents('test.zip'))
)
));
I'm not sure why this is required, as accourding to the doumentation and a post by an AWS employee, you dont have to have base64 encoding for create function. They must have mixed up something or another.

aws s3 uploading a directory to a bucket with php sdk

This is the php file named upload.php in ec2 server
require 'vendor/autoload.php';
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'key' => 'aws-secret-key',
'secret' => 'aws-very-secret-pass',
));
$dir = '/home/user/movies/history';
$bucket = 'my-unique-bucket';
$keyPrefix = '';
$options = array(
'params' => array('ACL' => 'public-read'),
'concurrency' => 20,
'debug' => true
);
$client->uploadDirectory($dir, $bucket, $keyPrefix, $options);
When I execute the upload.php file in terminal returns fatal error like this,
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/home/kaya/Resimler/transferet/): failed to open dir: No such file or directory' in /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/Sync/UploadSyncBuilder.php:47
Stack trace:
#0 /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/Sync/UploadSyncBuilder.php(47): RecursiveDirectoryIterator->__construct('/home/user/movie...', 12800)
#1 /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/S3Client.php(557): Aws\S3\Sync\UploadSyncBuilder->uploadFromDirectory('/home/user/movie...')
#2 /var/www/html/upload_dir.php(21): Aws\S3\S3Client->uploadDirectory('/home/user/movie...', 'my-unique-bucket', '', Array)
#3 {main}
thrown in /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/Sync/UploadSyncBuilder.php on line 47
Normally I can upload files clearly with php sdk except uploadfolder function. I couldnt find where is false. My php sdk version is 2.7.
I figured it out. It works on local server like xampp or something, doesnt work on remote server.

Categories