Keep getting redis error on Amazon EC2 - magento

I just moved my Magento site to Amazon EC2, but keep getting "Connection to Redis failed after 2 failures" error. I've tried to remove the redis configuration from app/etc/local.xml but still get that error.
I also tried to disable all the cache options directly from core_cache_option table. I have no idea how to clean the already cached files. No cache files under var/cache folder as expected and I've tried to flushall from redis-cli command prompt, but still keep getting this error.
Any idea what else should I try?
<cache>
<backend_options>
<server><![CDATA[/var/tmp/_cache.sock]]></server>
<port><![CDATA[0]]></port>
<persistent><![CDATA[]]></persistent>
<database><![CDATA[0]]></database>
<password><![CDATA[]]></password>
<connect_retries><![CDATA[1]]></connect_retries>
<read_timeout><![CDATA[10]]></read_timeout>
<automatic_cleaning_factor><![CDATA[0]]></automatic_cleaning_factor>
<compress_data><![CDATA[1]]></compress_data>
<compress_tags><![CDATA[1]]></compress_tags>
<compress_threshold><![CDATA[20480]]></compress_threshold>
<compression_lib><![CDATA[gzip]]></compression_lib>
<use_lua><![CDATA[0]]></use_lua>
</backend_options>
<backend><![CDATA[Cm_Cache_Backend_Redis]]></backend>
</cache>

Given EC2 instances are ephemeral, you should be able to regenerate the instance, right? If that's not an option —
First, Check app/etc/ for other XML files. Magento will parse any XML files it finds in this folder. I've seen something like the following trip people up
$ ls app/etc/*.xml
local.xml
local.backup.xml
Magento parses both local.xml and local.backup.xml, and the backup values override the new values in local.xml. Also, make sure you're working with the local.xml you think you are. Magento loads the local configuration in the following location. Add some temporary debugging to make sure it's doing what you think it's doing.
#File: app/code/core/Mage/Core/Model/Config.php
public function loadBase()
{
$etcDir = $this->getOptions()->getEtcDir();
$files = glob($etcDir.DS.'*.xml');
$this->loadFile(current($files));
while ($file = next($files)) {
var_dump($file);
$merge = clone $this->_prototype;
$merge->loadFile($file);
$this->extend($merge);
}
if (in_array($etcDir.DS.'local.xml', $files)) {
$this->_isLocalConfigLoaded = true;
}
return $this;
}
Second, after you clear your cache, make sure Magento's reloading the configuration. Add some temporary debugging to
#File: app/code/core/Mage/Core/Model/Config.php
public function init($options=array())
{
$this->setCacheChecksum(null);
$this->_cacheLoadedSections = array();
$this->setOptions($options);
$this->loadBase();
$cacheLoad = $this->loadModulesCache();
if ($cacheLoad) {
var_dump("Loaded Config from Cache");
return $this;
}
else
{
var_dump("Reloading configuration");
}
$this->loadModules();
$this->loadDb();
$this->saveCache();
return $this;
}
Finally, if you suspect the problem is a file based cache not clearing, drop some debugging code in
#File: app/code/core/Mage/Core/Model/Config/Options.php
public function getCacheDir()
{
//$dir = $this->getDataSetDefault('cache_dir', $this->getVarDir().DS.'cache');
$dir = $this->_data['cache_dir'];
$this->createDirIfNotExists($dir);
var_dump($dir);
return $dir;
}
This will let you know the cache directory Magento's reading from — if Magento can't read the local var, it'll pop up to the root level /var/ folder.

Related

Craft 3.7 permission denied error on install & migration

On a new Rackspace server, I am getting the following error whenever I try to install and/or migrate a Craft 3.7.0 site from local environment:
PHP Warning – yii\base\ErrorException session_start():open(/var/lib/php/session/sess_6d4r4eip8iotcfif9hlbi701ap, O_RDWR) failed: Permission denied (13)
1. in /my/path at line 152
{
if ($this->getIsActive()) {
return;
}
$this->registerSessionHandler();
$this->setCookieParamsInternal();
YII_DEBUG ? session_start() : #session_start();
if ($this->getUseStrictMode() && $this->_forceRegenerateId) {
$this->regenerateID();
$this->_forceRegenerateId = null;
}
if ($this->getIsActive()) {
Yii::info('Session started', __METHOD__);
$this->updateFlashCounters();
2. in /my/path/vendor/craftcms/cms/src/web/ErrorHandler.php at line 76– yii\base\ErrorHandler::handleError() 70717273747576777879808182 {
// Because: https://bugs.php.net/bug.php?id=74980
if (PHP_VERSION_ID >= 70100 && strpos($message, 'Narrowing occurred during type inference. Please file a bug report') !== false) {
return null;
}
return parent::handleError($code, $message, $file, $line);
}
/**
* #inheritdoc
*/
public function getExceptionName($exception)
3. craft\web\ErrorHandler::handleError()
4. in /my/path/vendor/yiisoft/yii2/web/Session.php at line 152– session_start() 146147148149150151152153154155156157158 }
$this->registerSessionHandler();
$this->setCookieParamsInternal();
YII_DEBUG ? session_start() : #session_start();
if ($this->getUseStrictMode() && $this->_forceRegenerateId) {
$this->regenerateID();
$this->_forceRegenerateId = null;
}
5. in /my/path/vendor/yiisoft/yii2/web/Session.php at line 751– yii\web\Session::open() 745746747748749750751752753754755756757 /**
* #param mixed $key session variable name
* #return bool whether there is the named session variable
*/
public function has($key)
{
$this->open();
return isset($_SESSION[$key]);
}
/**
* Updates the counters for flash messages and removes outdated flash messages.
* This method should only be called once in [[init()]]
etc.
I've tried checking the owner/group permissions, setting the chmod to 774 and 777, to no avail. Also cleared the storage/runtime folder and public/cpresources folder on each attempt.
What could be going on? Running PHP 7.4.2 and the Craft requirements are all met via checkit.php file.
Much appreciate the help in advance!
You can see that PHP is trying to write temp files to store the session in, which is failing because the PHP process doesn't have the correct permissions for that folder:
session_start():open(/var/lib/php/session/sess_6d4r4eip8iotcfif9hlbi701ap, O_RDWR) failed: Permission denied
You can solve this in a number of ways:
Change your PHP configuration to save session in a different folder that is writable by the process – see session_save_path. You would need to do this in your index.php and your craft file BEFORE craft is initiated.
Change the permissions of the folder in the error message above so the PHP process has write access to it.
Configure Craft to store sessions in the database instead. See How can I store Craft sessions in the database?

Zipping and downloading Amazon S3 bucket files and folders in Laravel

Is there a way to zip and download files and folders which are in Amazon S3 bucket, together in Laravel? I Want to zip the three folders and one file in the picture together and download it
Here's a half baked solution in a route file. Hope it helps.
https://flysystem.thephpleague.com/docs/adapter/zip-archive/
composer require league/flysystem-ziparchive
I put this in routes/web.php just to play with.
<?php
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
Route::get('zip', function(){
// see laravel's config/filesystem.php for the source disk
$source_disk = 's3';
$source_path = '';
$file_names = Storage::disk($source_disk)->files($source_path);
$zip = new Filesystem(new ZipArchiveAdapter(public_path('archive.zip')));
foreach($file_names as $file_name){
$file_content = Storage::disk($source_disk)->get($file_name);
$zip->put($file_name, $file_content);
}
$zip->getAdapter()->getArchive()->close();
return redirect('archive.zip');
});
You'll definitely want to do something different than just plopping it in the public dir. Maybe stream it out straight out as a download or save it somewhere better. Feel free to post comment/questions and we can discuss.
I did it the following way after looking at some solutions by streaming the zip directly to the client by using https://github.com/maennchen/ZipStream-PHP :
if ($uploads) {
return response()->streamDownload(function() use ($uploads) {
$opt = new ArchiveOptions();
$opt->setContentType('application/octet-stream');
$zip = new ZipStream("uploads.zip", $opt);
foreach ($uploads as $upload) {
try {
$file = Storage::readStream($upload->path);
$zip->addFileFromStream($upload->filename, $file);
}
catch (Exception $e) {
\Log::error("unable to read the file at storage path: $upload->path and output to zip stream. Exception is " . $e->getMessage());
}
}
$zip->finish();
}, 'uploads.zip');
}

Logic hook displaying some information from parent record raises error

I've got an hosted instance of SugarCRM 6.5 CE, and one of the requirements I have to fulfil is to display some information--contact phone number, contact email address--of the parent record in an associated task/activity record.
All I found so far was pointing towards the creation of a logic hook for pulling the contact information from the parent record (Contacts) and display these in custom fields in the child record (Tasks).
Following some instructions and examples found I came up with the following as outlined below.
Under "custom/modules/Tasks" I've create a file called "logic_hooks.php"
<?php// $Id$
$hook_version = 1;
$hook_array = Array();
// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Task: logic hook invoked");
// position, file, function
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array('1', 'contact_info', 'custom/modules/Tasks/hooks/contact_info.php','contact_info_class', 'contact_info_method');
?>
and under "custom/modules/Tasks/hooks" I've create a file called "contact_info.phplogic_hooks.php"
<?php
class contact_info_class {
// retrieve contact information from parent record
function contact_info_method($bean, $event, $arguments) {
// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Tasks: contact_info_method called for event ".$event . "(BeanID: " . $bean->id . ")");
// fetch data
if ($bean->fetched_row['id'] != $bean->id) {
// load Task
//$bean = BeanFactory::getBean('Tasks', $id);
// check if relationship is loaded
//if ($bean->load_relationship('contact_tasks_parent'))
if ($bean->load_relationship('contact_tasks')) {
// fetch related beans
//$relatedBeans = $bean->contact_tasks_parent->getBeans();
$relatedBeans = $bean->contact_tasks->getBeans();
$parentBean = false;
if (!empty($relatedBeans)) {
// order the results
reset($relatedBeans);
// first record in the list is the parent
$parentBean = current($relatedBeans);
// retrieve data from parent bean
$bean->contact_phone_c = $parentBean->phone_work
$bean->contact_primary_email_c = $parentBean->email1
}
}
}
} // contact_info_method
} // contact_info_class
?>
With this hook in place I can create new tasks without any problem at all, but when opening up an existing one, I'm receiving a message, reading
There was an error processing your request, please try again at a later time.
Being completely new to SugarCRM (btw. 6.5.20 CE it is I'm dealing with), I've got not the faintest idea as what is going wrong here.
I also cannot find any of the debug messages which are supposed to be written somewhere to.
--Sil68
The "contact_info.phplogic_hooks.php" file should be in the same folder as logic_hooks.php (custom/modules/< module-name>). And there's no need to name it that way (in fact I think it might cause problems). Try naming it just contact_info.php and changing the path given in the logic_hooks.php file to custom/modules/Tasks/contact_info.php.
As for where you can find the error log, assuming you're using apache for your web server (since you didn't specify) for linux/OS X, the error log is located at
/var/log/apache2/error.log
or
/var/log/apache2/error_log
In windows it'll be in
'C:\Program Files\Apache Software Foundation\Apache2.2\logs'.
Now that you know where the error log is, you can put
error_log('some helpful message');
inside your contact_info.php file and see which messages (if any) get sent to the error log. This can tell you if it even starts the logic hook and if so, how far it gets through the logic hook

laravel "invalid host" on loadbalancer redirects

Background: I'm working on an api which I host on ec2 servers. I just finish the login and set up an nginx loadbalancer which redirect to the said server's internal ip's. The domain name points to the load balancer.
This used to work well with code igniter, but now I keep getting an "invalid host" problem.
I tried googling it and it found some things about trusted proxies so I installed what fideloper made and tried his post as well (I've followed a guide by fideloper on laravel-4-trusted-proxies and used and tried his trusted sample on github: fideloper/TrustedProxy) but I still get the same error:
UnexpectedValueException
Invalid Host "api.myserver.im, api.myserver.im"
// as the host can come from the user (HTTP_HOST and depending on the configuration, SERVER_NAME too can come from the user)
// check that it does not contain forbidden characters (see RFC 952 and RFC 2181)
if ($host && !preg_match('/^\[?(?:[a-zA-Z0-9-:\]_]+\.?)+$/', $host)) {
throw new \UnexpectedValueException(sprintf('Invalid Host "%s"', $host));
}
Can someone help me?
I had the same issue as well. I had to resort to modifying the UrlGenerator.php file, which is part of the framework (bad I know...) just to get this to work.
So here's my "temporary" solution.
Create an array value to your app.php config file. e.g:
return array(
'rooturl' => 'https://www.youractualdomainname.com',
...
Next add the below modification in your UrlGenerator.php file <-- (trunk/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php)
<?php namespace Illuminate\Routing;
use Config;
...
protected function getRootUrl($scheme, $root = null)
{
$approoturl = Config::get('app.rooturl');
$root = isset($approoturl) ? $approoturl : $this->request->root();
return $root;
// if (is_null($root))
// {
// $root = $this->forcedRoot ?: $this->request->root();
// }
// $start = starts_with($root, 'http://') ? 'http://' : 'https://';
// return preg_replace('~'.$start.'~', $scheme, $root, 1);
}
Do note that composer update will revert your modification.

"Could not determine temp directory, please specify a cache_dir manually"

Magento admin throws an exception:
Could not determine temp directory, please specify a cache_dir manually
It is fresh instalation on new hosting package.
Usually it will happen in shared web hosting, but also some times on individual server, if the permission of tmp folder is set wrong.
Many people suggest to modify the file:
/lib/Zend/Cache/Backend/File.php to fix this problem. However, it may be a trap when you upgrade your Magento, as this file resides as core file of Magento. I recommend to use Magento's override feature.
Firstly, copy /lib/Zend/Cache/Backend/File.php to /app/code/local/Zend/Cache/Backend/File.php.
Then on line 91 or near this line, you will find:
'cache_dir' => null,
Change to:
'cache_dir' => "var/tmp/",
You can change the cache folder wherever you want.
Now create a directory named tmp(or whatever name you have given above) under var folder and change the permission to 777 if necessary.
This is only the permission issue. Just set the 777 permission to the cache directory and you are all done. try it.
For more details you can follow the link.
When ever you set the permission be sure it is recurrsively set..
chmod 777 -R /var/cache
this is the function
public function getTmpDir()
{
$tmpdir = array();
foreach (array($_ENV, $_SERVER) as $tab) {
foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
if (isset($tab[$key])) {
if (($key == 'windir') or ($key == 'SystemRoot')) {
$dir = realpath($tab[$key] . '\\temp');
} else {
$dir = realpath($tab[$key]);
}
if ($this->_isGoodTmpDir($dir)) {
return $dir;
}
}
}
}
$upload = ini_get('upload_tmp_dir');
if ($upload) {
$dir = realpath($upload);
if ($this->_isGoodTmpDir($dir)) {
return $dir;
}
}
if (function_exists('sys_get_temp_dir')) {
$dir = sys_get_temp_dir();
if ($this->_isGoodTmpDir($dir)) {
return $dir;
}
}
// Attemp to detect by creating a temporary file
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
if ($tempFile) {
$dir = realpath(dirname($tempFile));
unlink($tempFile);
if ($this->_isGoodTmpDir($dir)) {
return $dir;
}
}
if ($this->_isGoodTmpDir('/tmp')) {
return '/tmp';
}
if ($this->_isGoodTmpDir('\\temp')) {
return '\\temp';
}
Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
}
defined in file lib/Zend/Cache/Backend.php
http://www.webtechnologycodes.com/magento-error-could-not-determine-temp-directory-please-specify-a-cache_dir-manually/
Create tmp folder in root of your magento installation with 777 permissions.
Open lib/Zend/Cache/Backend/File.php
Find $_options property and change line: 'cache_dir' => null, to 'cache_dir' => 'tmp',
Refresh page.
Create an info.php and check for the path beneath upload_tmp_dir to be writable for the webserver.
<?php phpinfo();
Otherwise set the path in your hosting environment.
Beware that this setting can not be placed within .htaccess files but some hosters allow individual php.ini files to be placed in your docroot:
upload_tmp_dir = /path/to/docroot/var/tmp/

Resources