I developed a website using Yii2 Framework, and while I didn't explicitly use the Cache features, I guess it does do some things using APC as default.
The client where I published the website had uninstalled APC, since it is deprecated since v5.5 and refuse to install the extension.
My client now keeps receiving an 'unable to load dynamic library - apc.so' every time they try to save or delete a record to the database, not read.
I tried to clear the cache sub folder under the runtime folder in hopes that the website will use whatever system is available, but the error still creeps up.
They are using opcache. How can I reconfigure yii to use opcache and prevent the inability to find apc.so error?
EDIT:
This is what I have under components.
'cache' => [
'class' => 'yii\caching\FileCache',
],
If your cache is properly configured you should find something like this in the configuration file:
'components' => [
'cache' => [
'class' => 'yii\caching\ApcCache',
],
],
Now, AFAIK OpCache does not require configuration on the code level so you don't have to replace this config with something OpCache specific but there are direct cache calls in your code (hence the error) so you may want to use some available cache component anyway. In case you don't want to use any new cache component and at the same time you don't want to remove cache calls in your code use DummyCache:
'cache' => [
'class' => 'yii\caching\DummyCache',
],
EDIT:
It looks like it is not a case of Yii 2 configuration, more like a PHP configuration. Look for "unable to load dynamic library - apc.so". Probably APC is still in the PHP configuration but the library has been removed.
Related questions:
https://serverfault.com/questions/623520/php-startup-unable-to-load-dynamic-library-usr-lib-php5-20100525-apc-so
PHP APC Error Loading apc.so
APC - Unable to load dynamic library
Related
my problem is in tinker i tried to set value with \Redis::set("name","john")
in redis and got this error:
PHP Error: Non-static method Redis::set() cannot be called statically in Psy Shell code on line 1
but when using for example \Illuminate\Support\Facades\Redis::set("name","john") it works and everything is ok.
with this registeration in app.php by default:
'aliases' => [
'Redis' => Illuminate\Support\Facades\Redis::class,
],
so
\Illuminate\Support\Facades\Redis::set("name","MOHSEN") = \Redis::set("name","john")
what is the problem?
Laravel uses the predis extension, and php also installs and uses the phpredis extension. Since both of the above redis extensions use Redis as the namespace, namespace conflicts are caused. Therefore in your Laravel project, you used predis before, but now switch to phpredis. Then the static method in the previous code will report an error.
Solutions to solve the cause
method one: In Laravel, since predis is an extension made based on PHP, it can be added through composer to facilitate integration with Laravel. Therefore, you can avoid conflicts by annotating the extension of phpredis in php.ini.
;extension = redis.so
Disadvantages:
predis maintenance has been cancelled, Laravel has started from version 6, it is recommended to use phpredis.
Method 2: In the code, clearly indicate Redis
use Illuminate\Support\Facades\Redis;
Method 3: change aliases Also stable
in config\app.php
'Redis' => Illuminate\Support\Facades\Redis::class
Replace with
'The desired name' => Illuminate\Support\Facades\Redis::class
And finally, use the desired name;
The second method is a more appropriate option. You can replace it with a small amount of code.
When i update data from ckeditor and it didn't save to database properly it saves only text but table div and inline style didn't save after I apply sneek/laravel-xss-middleware.
What xss middleware that not affect to text editor?
I tried others but it can't prevent xss.
Can anyone recommend ?
I use nessus to scan web for security after i use htmlpurifier it still show:
CGI Generic HTML Injections (quick test)
Synopsis
The remote web server may be prone to HTML injections.
Description
The remote web server hosts CGI scripts that fail to adequately sanitize request strings with malicious JavaScript. By leveraging this issue, an attacker may be able to cause arbitrary HTML to be executed in a user's browser within the security context of the affected site.
The remote web server may be vulnerable to IFRAME injections or cross-site scripting attacks :
IFRAME injections allow 'virtual defacement' that might scare or anger gullible users. Such injections are sometimes implemented for 'phishing' attacks.
XSS are extensively tested by four other scripts.
Some applications (e.g. web forums) authorize a subset of HTML without any ill effect. In this case, ignore this warning.
I often use HTMLPurifier
Complete the following steps
1.install
composer require "mews/purifier:~2.0"
2.setting
php artisan vendor:publish --provider="Mews\Purifier\PurifierServiceProvider"
config/purifier.php
<?php
return [
'encoding' => 'UTF-8',
'finalize' => true,
'cachePath' => storage_path('app/purifier'),
'cacheFileMode' => 0755,
'settings' => [
'body' => [
'HTML.Doctype' => 'XHTML 1.0 Transitional',
'HTML.Allowed' => 'div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,h2,h3,h4,h5,h6,blockquote,del,table,thead,tbody,tr,th,td',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,margin,width,height,font-family,text-decoration,padding-left,color,background-color,text-align',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
],
],
];
use
$article->body = clean($article->body, 'body');
Hope useful to you!
I have a problem with the sessions on the shared hosting.
I developed an app on a local server (XAMPP) and it works great (sessions, auth etc). The problems have appeared when I moved the app on a shared hosting.
I realized that the sessions are not persisting from a page to another or from AJAX files to another page and the Authentication does not work either .
The only session that persists is the _token which has a different value after every refresh of the page.
I have the following configuration in the session.php file:
'driver' => 'database',
'lifetime' => 120,
'expire_on_close' => false,
'lottery' => array(2, 100),
'path' => '/',
'domain' => null
First, I used file driver and I had the same problem, and now I used the database.
Both file and database work on the local server but on the shared hosting they do not.
I tried all the solutions found on the forum but still I have the same problem.
I think the problem is at the session domain setting because when I change the value from null to other string on my local server, I have the same problem that I have encountered online.
Can you help me, please!
Thanks, Mirel
I fixed the problem. In my case the error because I have added a php closed tag ?> in the end of the included files. So removing this tag will bring the application back to normal behavior.
Case scenario:
$dbResult = myEloquentClass::remember(60)->all();
My results are being cached, which works great for a production environment.
However, i am finding myself removing the remember method in my development environment since i don't want to cache my database results.
This results in a lot of unnecessary removal/additions of code.
Is there a way to bypass the cache globally for eloquent's remember when in development environment?
In laravel - 4 edit the app/config/local/cache.php file and set the driver to array.
<?php
return array(
'driver' => 'array',
);
For laravel 5 - edit the .env file and set the CACHE_DRIVER to array
CACHE_DRIVER=array
As posted by #bogdan,
I switch my development cache.php config file's driver to array, and works as advertised.
I have a CakePHP 2.x site I'm working on which performs as intended locally. Login works, session flash messages work, etc. When I push the code to my staging/prod server it's breaking.
Logins no longer work, no session flash messages appear, some controller actions that should be redirecting to /user/login are displaying nothing (empty document), etc.
I'm at a loss as to what the problem would be. Based on the issues I'm experiencing and some searching I've done I believe I've ruled out problems like whitespace after the closing ?> in a code-only PHP file (controllers). I'm using DB sessions, and I see session records being created in the DB on my local instance, but not on the remote staging/prod instance.
Any assistance would be much appreciated. Thanks.
In you app/Config/core.php check out these thing.
If you are using SSL and non-SSL based protocols, make sure you have cookie_secure set as false.
Configure::write('Session', array(
'defaults' => 'php',
'ini' => array(
'session.cookie_secure' => false
)
));
Try changing Session's configuration from php defaults to cake or db as
Configure::write('Session', array(
'defaults' => 'php', // change 'php' to 'cake' or 'database'
'cookie' => 'my_app',
'timeout' => 4320 //3 days
));
Also try setting Session.checkAgent to false, just for once to ensure if it is a browser issue.
Try changing Session.name of your session, it defaults to 'CAKEPHP'
Configure::write('Session', array(
'name' => 'New-Session-name'
'defaults' => 'php', // change 'php' to 'cake' or 'database'
'cookie' => 'my_app',
'timeout' => 4320 //3 days
));
Remove all cache files from all sub-directories of /app/tmp
Set debug level higher to 1, to do cache refresh. If you still don't see an error, try setting error_reporting to true in php.ini. (Although, this one is very obvious I am still pointing it out in case you might have missed it out)
Hope this helps
One of the recommendations I came across frequently was to ensure that there was no whitespace after the closing PHP tag in a code-only file (or preferably to not actually have a closing PHP tag). Checking all my files showed that to be the case. Somehow, however, I managed to put a single line break before the opening PHP tag in AppController.php and that was the issue. My apologies to anyone who wasted time on this. I just hope this helps someone in the future who clumsily makes the same mistake.