Setting up environment in Yii Framework - php

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

Related

CakePHP - cake bake all error (says missing $default in database.php, but it is present)

I am trying to bake all with cake bake all, but it returns all sorts of errors. It says that default in database.php cannot be found, but in reality it is present in the file, also, few days ago I baked few models etc and it worked fine. Here is the output:
C:\wamp64\www\WarehouseManagementApp\app\Console>cake bake all
Warning Error: Use of undefined constant TESTS - assumed ‘TESTS’ (this will throw an Error in a future version of PHP) in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\TaskCollection.php, line 94]
Welcome to CakePHP v2.10.19 Console
App : Console
Path: C:\wamp64\www\WarehouseManagementApp\app\Console\
Bake All
Warning Error: include_once(C:\wamp64\www\WarehouseManagementApp\app\Console\Config\database.php): failed to open stream: No such file or directory in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php, line 67]
Warning Error: include_once(): Failed opening ‘C:\wamp64\www\WarehouseManagementApp\app\Console\Config\database.php’ for inclusion (include_path=‘C:\wamp64\www\WarehouseManagementApp\lib;.;C:\php\pear’) in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php, line 67]
Error: The datasource configuration “default” was not found in database.php
#0 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php(91): ConnectionManager::_getConnectionObject(‘default’)
#1 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(956): ConnectionManager::getDataSource(‘default’)
#2 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(893): ModelTask->getAllTables(‘default’)
#3 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(983): ModelTask->listAll(‘default’)
#4 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\BakeShell.php(150): ModelTask->getName(‘default’)
#5 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Shell.php(459): BakeShell->all()
#6 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\ShellDispatcher.php(222): Shell->runCommand(‘all’, Array)
#7 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\ShellDispatcher.php(66): ShellDispatcher->dispatch()
#8 C:\wamp64\www\WarehouseManagementApp\app\Console\cake.php(47): ShellDispatcher::run(Array)
#9 {main}
Also, here is my database.php file:
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'modules',
'prefix' => '',
// ‘encoding’ => ‘utf8’,
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'test_database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
}
Look at the include errors, they tell you that your database.php file cannot be found, and if you look at the path, you see that it looks in the Console/Config folder, which is of course the wrong location.
That is because the shell will use the current working directory as the application path, so either run the console from within your app folder, ie Console\cake bake all, or use the -app parameter to pass the path to your app folder:
cake bake all -app "C:\wamp64\www\WarehouseManagementApp\app"
The cake shell tells you about that too (cake --help), and shows you the relevant paths.
See also
Cookbook > Shells, Tasks & Console Tools

Uncaught exception 'RuntimeException' PHP and cPanel

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/.

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 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.

PHP Fatal error: Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/tmp" must be a directory'

I have problem regarding zend cache_dir.
I try to tranfer my site from one server to another, and it work.
But, when i try to access the site, it shows this error:
PHP Fatal error: Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/tmp" must be a directory' in /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php:209
Stack trace:
- #0 /home/aiesorgm/public_html/gcpi/library/Zend/Cache/Backend/File.php(178): Zend_Cache::throwException('cache_dir "/tmp...')
- #1 /home/aiesorgm/public_html/gcpi/library/Zend/Cache/Backend/File.php(129): Zend_Cache_Backend_File->setCacheDir('/tmp')
- #2 /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
- #3 /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
- #4 /home/aiesorgm/public_html/gcpi/application/Bootstrap.php(55): Zend_Cache::factory('Page', 'File', Array, Array)
- #5 /home/aiesorgm/public_html/gcpi/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initCache()
- #6 /home/aiesorgm/public_html/gcpi/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract-> in /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php on line 209
I already try all solutions that i can get from stackoverflow, but it's still doesn't work.
I also have create tmp directory inside public folder and change the permission to 777.
application/Bootstrap.php
protected function _initCache() {
$info = Zend_Registry::get('info');
$backendOptions = array(
'cache_dir' => sys_get_temp_dir(),
'hashed_directory_level' => 1,
'file_name_prefix' => 'style',
'automatic_cleaning_factor' => 1
);
$frontendOptions = array(
'lifetime' => $info['cache']['lifetime'],
'automatic_serialization' => true,
'caching' => ($info['cache']['enabled'] == '1') ? true : false,
);
$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
Zend_Registry::set('cache', $cache);
}
/library/Zend/Cache/Backend/File.php
protected $_options = array(
'cache_dir' => null,
'file_locking' => true,
'read_control' => true,
'read_control_type' => 'crc32',
'hashed_directory_level' => 0,
'hashed_directory_perm' => 0700,
'file_name_prefix' => 'zend_cache',
'cache_file_perm' => 0600,
'metadatas_array_max_size' => 100
);
Folder Structure
application
config
controller
form
layouts
models
view
docs
library
public
css
js
images
tmp
.htaccess
index.php
10Q for your time for reading this.
/tmp is the full path, so ZF isn't trying to write to a folder called tmp in your public folder, it's trying to write to the system temp folder at the root of the file system.
I'd recommend setting a project-specific cache folder instead:
$backendOptions = array(
'cache_dir' => APPLICATION_PATH.'/../data/cache',
'hashed_directory_level' => 1,
'file_name_prefix' => 'style',
'automatic_cleaning_factor' => 1
);
then create a folder called data within your project, and a cache folder within that, and make it writeable.

Categories