I am trying to configure cakephp ver 2.6.0 to use redis engine by default. but somehow i am not able to make it work. any help will be highly appreciated.
Things Which i have tried so far..
Configured app/config folder 2 files , core.php and bootstrap.php. , according to the guidelines provided here in this blog configure cake with redis and this blog too Another cake-redis config setup
but i keep on getting errors like.
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine session is not properly configured.' in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181
CacheException: Cache engine session is not properly configured. in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181
Any help will be highly appreciated.
I was having the same exact issue today while trying to setup CakePHP to use Redis as the cache engine.
Coincidentally, I also read the same setup instructions from the two blogs you linked to.
The reason was that I had copied pasted the Configure::write(...) code block from the Another cake-redis config setup blog post as it is and pasted it into the file without first commenting out the Configure::write(...) code block that was already in the core.php file.
I'm assuming that you have already successfully setup Redis on Windows and have installed the PHPRedis extension without any issues.
I am using the instructions from Another cake-redis config setup here.
In your app/Config/core.php file, comment out the following block: (this was starting at line 218 in my core.php)
Configure::write('Session', array(
'defaults' => 'php'
));
Instead, you can put this in: (You can change the values to suit your particular needs)
Configure::write('Session', array(
'defaults' => 'cache',
'timeout' => 100,
'start' => true,
'checkAgent' => false,
'handler' => array(
'config' => 'session'
)
));
After this, change the value of $engine to 'Redis', so it becomes:
$engine = 'Redis';
And then, put this code in, I put this in at the very end of the file: (Again, your values can be different depending on what your setup is)
Cache::config ('session', array (
'Engine' => $engine,
'Prefix' => $prefix . 'cake_session_',
'Duration' => $duration
));
And that's it. You're done! No need to change anything else.
To make sure that Redis is working properly with CakePHP, I ran the RedisEngine Test Suite that comes with CakePHP. You need to have PHPUnit installed for this to work.
It can be accessed via http://your-cakephp-project/test.php
Click on 'Tests' under Core and then click on 'Cache/Engine/RedisEngine'
If everything is working successfully, you should see all the tests pass.
Alternatively, you can use redis-cli at the command prompt to confirm that Redis is storing keys properly.
Once you have logged in by typing redis-cli, type KEYS *
This should give you a list of keys related to your CakePHP setup.
An example would be the "myapp_cake_core_object_map" key.
Hope this helps.
Related
I have a composer package designed for use in other projects that has configurations, or rather default settings I'd like the end user to be able to adjust based on their intended use. The package itself can be configured to build things differently depending on the configurations passed to the package's builder class. I'd like there to be default settings, possibly in a settings.yml file (the medium is not a concern, *.conf, *.json, *.php), may be this should go within the package? But then I imagine if that were the case it would be hard for the end user to maintain as it would be overwritten during composer updates? Anyone know what the norm for storing composer vendor packages configs is?
$parameters = [
'handlers' => [
// various depending on client use
'//widget' => 'LivingMarkup\Component\Widgets\{name}',
'//img' => 'LivingMarkup\Component\Img',
'//a' => 'LivingMarkup\Component\A',
'//var' => 'LivingMarkup\Component\Variable',
'//condition' => 'LivingMarkup\Component\Condition',
'//redact' => 'LivingMarkup\Component\Redact'
],
'hooks' => [
'beforeLoad' => 'Executed before onLoad',
'onLoad' => 'Loads object data',
'afterLoad' => 'Executed after onLoad',
'beforeRender' => 'Executed before onLoad',
'onRender' => 'RETURN_CALL',
'afterRender' => 'Executed after onRender',
]
];
Thank you.
After a bit more searching I found a post that addresses this exact question.
https://www.reddit.com/r/PHP/comments/3qqrmz/how_to_handle_config_files_and_default_settings/
To summarize, in case the above link stops working some day, here are some options:
"Bolt CMS does uses a config.yml.dist, which is included with the source code. And the end user can create a config.yml file if one doesn't exist. The config.yml.dist file is part of the official project and acts as the example config file, and should not be modified."
"Your own config.yml file can be tracked in your version control if you wish. Then you can put confidential or environment-specific information into config_local.yml and place that file's name in .gitignore."
"Symfony I use the parameters.yml and config.yml to pass parameters to the objects in DIC."
"Phpunit uses the phpunit.xml.dist file to setup tests."
"Apigen uses .neon or .yaml config files."
"Flysystem asks for config options to be passed directly in the constructor"
"Cakephp has it's own configuration settings, and plugins come with instructions on the keys to add. This asset compress package uses an ini file"
Opus is an option: https://github.com/imarc/opus
I am developing an API service that another site I've developed will be using. So locally when building and testing, obviously I want both local copies of the site to work. However, it seems to mix up the environment variables.
For example:
Site A has APP_URL=http://a.local
Site B has APP_URL=http://b.local
I send a GET Request (using Guzzle) from Site A code to http://b.local/test
The /test endpoing in Site B simply dumps out dump(env('APP_URL'))
Result retrieved by Site A is "http://a.local"
Expected result: "http://b.local"
So the code in Site B is running with environment variables loaded from Site A. This is an issue as Site B cannot access the correct database, it's trying to use the Site A's database.
Is this an issue with my local setup (Win10 + WAMP), PHP settings, Laravel settings?
I also encountered this issue, and it is mentioned here. The resolution for it is to run php artisan config:cache in both projects to cache configuration from .env files or patch the code from here.
are you using artisan commands to run both projects with different ports ?
php artisan serve --port=8000
php artisan serve --port=8010
You can set Environment variables in either the vhost config OR in an .htaccess file:
SetEnv APP_URL http://b.local
Apart from #Daniel Protopopov answer above there is also another way, that is also works when both Site A and Site B are Lumen.
In short just rename your DB_DATABASE variable on each side to a different name. Then change the respective variable names in the respective config/<configfilename>.php files.
So that on Site A you would have SITE_A_DB_DATABASE in .env and matching 'database' => env('API_A_DB_DATABASE', 'forge'), line in config/database.php.
Then your Site B SITE_B_DB_DATABASE will not be overwritten due to variable names are different.
The same solution applies for any .env variables which names match.
Because the command php artisan config:cache doesn't work here (closure needed in routes file config file)
LogicException : Your configuration files are not serializable.
I add phpdotenv with composer :
composer require vlucas/phpdotenv
And at the begginning of the file "/bootstrap/app.php" (after "new Illuminate\Foundation\Application"), I add :
$app->detectEnvironment(function () {
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/../', '.env');
$dotenv->overload();
});
Maybe an alternative
If you are calling a Lumen 8 API from within a Laravel 6 application using GuzzleHttp and the Laravel env is being inherited to Lumen, creating config file worked for me.
In bootstrap/app.php comment below lines to prevent loading current env values from Laravel
// (new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
// dirname(__DIR__)
// ))->bootstrap();
In bootstrap/app.php add below line after $app has been created.
$app->configure('database');
Create config/database.php in lumen root folder. Return all env values needed for Lumen api in an array in the config file.
<?php
return [
'timezone' => 'UTC',
'default' => 'pdbmysql',
'connections' => [
'pdbmysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'db2',
'username' => 'root',
'password' => 'root',
],
],
];
I follow this tutorial to create my user online list.
In my local MAMP server on Mac OSX it work fine, but if I tried to put in Ubuntu server, I got this error (at the index, without logged in):
Fatal error: Uncaught exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'session' already exists.
I can catch the exception but I would to know because in OSX it works fine but in Ubuntu it's not works.
I think it may be something in Apache or other config: is it possible ?
Is session created before login ? The component need a user_id (not null) in the session table so I think there is anything I don't understand.
In both php.ini I set session.auto_start = 0.
Probably the problem is that in those 2 servers you have slight differences, and among them the table 'session' which is already available in the Ubuntu server, and is probably handled for a total different reason against what you need, while in your MAC env there is no such thing as 'session' table.
The easy and clean way I can think of to solve the collision of names is to rename your table name from 'session' to 'mysession' changing the config setting this way:
'session' => array (
'class' => 'application.components.DbHttpSession',
'connectionID' => 'db',
'sessionTableName' => 'mysession',
'userTableName' => 'user'
),
And update every occurrence of the table name (like in queries) in your code.
This way the collision should be gone and everything should work fine.
I hope it helps.
This is what I did:
I downloaded the yii2 advanced template.
Ran php init.
Configured each of main-local.php files in
environments/dev/common/config
environments/prod/common/config
common/config
I added the following to the 'components'
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'sqlite:/path/to/sqlitedbs/yayr.sq3',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
I configured the apache vhosts as explained in the readme.
Running yii migrate created the sqlite database file in the configured location with no errors.
What breaks is when I go to the frontend app and try to submit the sign up form, it gives me this error:
Exception
Database Exception – yii\db\Exception
SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: NO)
↵
Caused by: PDOException
SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: NO)
in /home/johnsmith/dev/test/yayr/vendor/yiisoft/yii2/db/Connection.php at line 579
The full stack trace can be seen: http://pastebin.com/KEKH1zbM
I have used my IDE to search for every location that a mysql dsn exists. The only place is in /tests/codeception/config/config.php which should not be called by submitting a form. To double check, I commented out the config, and it didn't help.
I also tried setting 'driverName' => 'sqlite', in the config, but that did not make any difference. Neither did commenting out the username, password, or charset parameters.
None of the functions referenced by the stack trace appear to manually call MySQL. They all look for the configured dsn.
So, why does Yii think it can even try to connect to MySQL? Doesn't ActiveRecord abstract out all the SQL so that it won't matter if I'm using MySQL or sqlite?
How do I get past this issue? Using sqlite would make initial development a lot easier.
Thanks!
Basics of the Yii2 advanced template
You have the environments-folder containing you actual config files
The frontend- and backend-folders hold copies of those "local"-files, depending on which environment you selected, they get copied from dev or prod
Now what does that mean? If you perform changes on ANY file within the envirnments folder, you have to re-init your application. You simply do this by opening a console, navigate to the base folder of your application and call the init-command. You will then be asked which envirnment you want and what files to overwrite.
After that you should see your changes beeing reflected in the frontend- and backend-folder. The idea behind this is to prevent if/else-structures within the config files and have a clean application. By the way: the index.php within the web-folders gets copied the same way. That way you could even customize this...and therefore the way the application gets loaded initially.
Back to your problem
For me it looks like you changed the settings within the environments/.../local-...-configfile, which is right...but then didn't re-init the application. That way the config file within the front- and backend still contain your old settings.
Documantation of the advanced template
Everything is very well documented here:
https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md
After init command
Create a new database and add it in common/config/main-local.php
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=your-db',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
Apply yii migrate in console command!
It'll create the tables for the application to work
I am using Wamp server and I'm trying to install CakePHP 2.0.0 but I'm having trouble with it.
I put the CakePHP 2.0.0 files in my wamp server folder "www" and then "cake" folder.
When I enter address http://localhost/cake in my browser then following message is displayed:
CakePHP: the rapid development php framework
Release Notes for CakePHP 2.0.0-dev.
Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE\Cake\Utility\Debugger.php, line 647]
Notice (1024): Please change the value of 'Security.cipherSeed' in app/config/core.php to a numeric (digits only) seed value specific to your application [CORE\Cake\Utility\Debugger.php, line 651]
Your tmp directory is writable.
The FileEngine is being used for caching. To change the config edit APP/config/core.php
Your database configuration file is present.
Cake is NOT able to connect to the database.
Editing this Page
To change the content of this page, create: APP/views/pages/home.ctp.
To change its layout, create: APP/views/layouts/default.ctp.
You can also add some CSS styles for your pages at: APP/webroot/css.
I had the same problem and it took a lot of researching to determine the actual problem.
The new version of CakePHP uses pdo to establish a connection rather than mysql or mysqli as it did previously. As you are using a Windows environment, just enable the following in php.ini file.
extension=php_pdo_mysql.dll
NOTHING to do with using root and I also found it an real annoyance when trying to move from 1.3 to 2.0
As for the arrogant answer from deceze, I found NO mention of this change anywhere on the CakePHP download / install / docs.
I can't upvote due to a lack of reputation, however I'd like to point out that despite the comments under your question (which, in part, are correct), George Wood is exactly correct: you need to enable
extension=php_pdo_mysql.dll (Windows)
or for me it was extension=pdo_mysql.so (Arch Linux)
...and there may be some variants out there too. I've just struggled with this for an hour. Best of luck with your coding efforts.
My problem with cakephp was solved on Ubuntu by doing this:
sudo apt-get install php5-mysql
sudo /etc/init.d/apache2 restart
I'm using Ubuntu 10.04, MySQL, Apache2 and PHP5.
Once I did that I could use the MySQL user I created. So it wasn't a cakephp config error it was not knowing php5-mysql was not installed by default.
They are NOT errors, they are notices. This means you can do some configurations in order to make it work. Read over them and do what they tell you to do. Seems like errors happen in your config/, watch out to provide correct information such as database's name and password.
Edit
Just to answer your question, CakePHP is a PHP framework that assist you with constructing your website in MVC model. Instead writing source code from scratch, by using framework, you can inherit all its functionality that speed up your development time, help you to deal with more-complex structure/procedures more easily.
If you haven't still solved the connection issue with database, try doing a sanity check on these bits..
'driver' (ok in 1.3) has been renamed to 'datasource'
'mysql' (ok in 1.3) has to be specified as 'Database/Mysql'
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'sandbox',
'prefix' => '',
'encoding' => 'utf8');
Let me know if this worked.
(I was trying to reuse my old 1.3 config and got caught in the same loop.)
Please find solution as shown below.
Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE\Cake\Utility\Debugger.php, line 647]
Solution: Go thorough this file app/config/core.php
find Security.salt and change it to any value.
Notice (1024): Please change the value of 'Security.cipherSeed' in app/config/core.php to a numeric (digits only) seed value specific to your application [CORE\Cake\Utility\Debugger.php, line 651]
Solution: Go thorough this file app/config/core.php
find Security.cipherSeed and change it to any value.
Your tmp directory is writable.
Solution: Give proper permission for this path app/tmp
Cake is NOT able to connect to the database.
Solution: Go thorough this file app/config/database.php
set proper parameters for database connection.
Just adding this in here... I came across this (and other similar solutions) but only recently found the problem. I had an issue with my custom Apache build due to other software issues and decided to quickly get a working environment rather than reformat my PC.
I first installed Apache 2.4 and PHP 5.4. These versions were unfortunately incompatible with most of my code, and again, I wanted to quickly get a working environment, so I uninstalled and went back to WAMP with Apache 2.2 and PHP 5.3.
At some point, WAMPServer was looking at C:\Program Files (x86)\PHP\php.ini for my php.ini file. I do not know how or why it was looking there. Unfortunately I was editing C:\wamp\bin\php\php5.3.13\php.ini instead. I didn't realize why MySQL wasn't working until I loaded up a call to phpinfo() and noticed PHP was looking in the "wrong" place for my php.ini.
In case anyone else has a similar issue, I figured I'd add it here to the mix. Good luck!
I had the same problem and I figured it out.
I had the wrong username and password for database connection.
So I opened database and edited the database.php file. Now cake is able to connect to the database.
Recently I had the same problem with xampp installed on a windows machine, for me it was because when entering the details
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
windows could not resolve localhost to being 127.0.0.1, this can be solved by one of either solutions:
Change details in app/Config/database.php to
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '127.0.0.1',
Or edit in windows C:\Windows\System32\drivers\etc\hosts (You may need to run Nopepad.exe as administrator to do this)
add a line at the end with:
127.0.0.1 localhost
I solved this error by downgrading my xampp from version 7.0 to version 5.6. Seems that the updated xampp doesn't support the cakeframework perfectly. I used this trick to also succesfully install orangescrum.
On local host for mysql, it is compulsory to use the user "root" rather than any other user. Hope this helps.
Also check this.