Ok, here's a new one to me.
Here's the situation... I have a Cake app running under multiple environments (dev, qa, staging, live), managed using GIT.
I'm developing away on my development branch, and access that branch from dev.BLAH.com.
DEV is served out of /var/www/dev.BLAH.com/app
Occasionally, when working on DEV I start getting errors like this:
Warning (512): Model "Exercise" is not associated with model "ExerciseOutcome" [/var/www/QA.BLAH.com/lib/Cake/Model/Behavior/ContainableBehavior.php, line 344]
NOTE: That error is caused because it is trying to find an association
that is not built yet under the QA environment, so it's not about the missing association, it's about the WRONG PATH.
Clearly, for some unknown reason, the DEV domain is trying to serve files from the QA domain! Now, I don't think this is related to some kind of human coding error, because the simple FIX for it is to restart Apache!
Now, I thought it might be some kind of session issue, because I'm storing sessions in the DB, but even if I clear all the sessions in the DB (without restarting apache), it doesn't fix it.
But if I restart Apache, leaving the sessions table untouched, it suddenly starts working again!
It all seems so strange to me, that I just don't know where else to look.
I tried changing the various levels of caching, but that didn't change anything.
I don't think I'm an idiot, but I hope someone can prove me wrong! ;)
As noted in the comments, the issue is most likely to do with APC and prefixes.
What happens is that Cake caches the paths of various models using APC. This is all fine until you have multiple applications that use the same cache data on the one server. This is why Cake allows you to set the prefix of the cache.
So one solution is to set the prefix in a per-deployoment basis, like this:
// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
$prefix = 'myapp_DEV_';
However, this gets messy when you're using source control and you want the various deployments to be as close to each other as possible.
The way I got around it was to modify the cache config in APP/Config/core.php as follows:
/**
* Configure the cache used for general framework caching. Path information,
* object listings, and translation cache files are stored with this configuration.
*/
Cache::config(
'_cake_core_',
array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_' . Inflector::slug(ROOT),
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
)
);
Note the Inflector::slug(ROOT) line. This will give each application a unique prefix, without having to explicitly set it.
Related
I use ZF3 and code in the development mode. I configured it like the tutorial suggests:
composer development-enable
So everything works fine if this mode is enabled. If I disable it I get a database connection error, like this one:
Connect Error: SQLSTATE[HY000] [1044] Access denied for user
''#'localhost' to database 'xyz'
I still work on the same computer.
So what error it might be?
The main topic would be, how is the right way to change between development and production, does the composer statement also make clear to use the production configfiles?
If I have changed the mode via composer, what do I have to do additional? I really blueeyed thought, it would be enough to just disable:
composer development-disable
Do I have to rename the development config files also? Of which files do we talk about? Is it just application-config.php and development-config.php?
Where and how should I place the different database connections? I now use the files you see above.
And last, how to change the mode on the production server? I now just disabled the mode on my developmentsystem and then uploaded the hole project. Afterwards I only upload the changed files.
EDIT1: Here additional a screensot, which configuration files I use in which folders:
In my application.config.php the configuration links to:
'config_glob_paths' => [
realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php',
],
and in my development.config.php the configuration links to
'module_listener_options' => [
'config_glob_paths' => [realpath(__DIR__) . '/autoload/{,*.}{global,local}-development.php'],
'config_cache_enabled' => false,
'module_map_cache_enabled' => false,
],
for me it looks correct. My database connection is in local.php (for the production) and in local-development.php (for the development mode).
Enabling/Disabling the mode is just the same as having/not having the config/development.config.php file.
If you look closely, you'll see that the development mode disables the cache.
Your problem is that the cache files have been created (non dev mode) while the configuration wasn't fine for the environment. Remove data/cache/application.config.cache and application.module.cache as configured in config/application.config.php.
If you use development-mode enable (Development) it mean config_cache_enabled set to false. So your new configuration like module, services, controllers, etc will load by ZF3, because ZF3 will not read the configuration from cache (in data/cache/*).
If development-mode disable (Production) configuration will be cached, so when you deploy your code with new configuration like I mention above, will not read by ZF3. Because ZF3 still read the configuration in cache.
I usually remove the cache when deploying to Production. Here the sample shell script I used for deploying
#/bin/bash
rsync --exclude data --exclude .git -av temp_example.com/. /var/www/example.com/.
echo -e "Removing cache..."
rm -f /var/www/example.com/data/cache/*.php
So, the main key, if you used development-mode disable, just remove the cache after deploying the code.
I've been working quite a while on a Symfony2 project and it looks very nice.
However, to save some time lately I've been programming a lot without actually testing the functionality. Obviously I didn't push it to the live environment either.
Now I'm trying to start the built-in PHP server to run my project locally to see what I broke by coding blindly and ... well, I must've broken something BIG.
app/console server:start
Hangs for a few seconds and finally I get an error:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: Invalid argument supplied for foreach()
That's it. There's literally nothing more in the console. It doesn't say where I made a mistake, whether it's in my code (no class names, no lines) or somewhere else... This is like a needle in a haystack.
I've tried running it with the --force flag because it's just a warning, maybe it could continue and crash again later (and give me a proper reason why then), but I get the same error.
All the other command like trying to clear the cache, trying to validate my doctrine schema's etc. produce the exact same result. Nothing in the logs either. Not even in /var/logs/apache2.
I've manually cleared the cache and try to run the server again to see if maybe it would show me a different error. It does manage to create a folder structure:
.
└── dev
├── annotations
├── classes.map
├── jms_aop
├── jms_security
└── serializer
But doesn't manage to place anything inside these folders. So I think I'm getting the error rather quickly.
I'm looking for a needle in a haystack over here... I've looked through my code, figuring out if I made a stupid mistake in my foreach loops but I don't see anything.
Is there any way I can get more debugging information from Symfony? A simple class name or line would help me figure out what the underlying cause might be but this is just madness. I don't even have a clue where to start.
UPDATE:
#JimL pointed out to me that I could increase the verbosity level of the console command output.
By adding -vvv to the output I managed to get a full stack trace of the exception. Once I saw the last line:
/Users/A Sneaky Ginger/path/to/my/project/vendor/jms/serializer-bundle/JMS/SerializerBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php:48
at first I was confused because this isn't a file which I've edited myself. But after a few head scratches I could figure out that one of my EventListeners had the code:
static public function getSubscribedEvents()
{
//return array(
//array("event" => "serializer.post_serialize", "class" => "Acme\myBundle\Entity\myEntity", "method" => "onPostSerialize")
//);
}
Which was causing the invalid parameter given to the foreach().
I still think a small hint could've been included by default in the warning message because this was really too vague, but luckily JimL saved the day.
When you use the CLI you're not using Apache so no errors should end up there. You could change the verbosity level
http://symfony.com/doc/current/components/console/introduction.html#verbosity-levels
Does anyone know if mysqldump-php can work with shared hosting? I can get it to work on my local computer (I can get mysqldump to work locally also) but I need a method to backup a database that's hosted with a popular webhosting company. The only method that they offer to their customers is to sign onto phpMyAdmin and download your .sql manually. daily. yourself. no automation allowed. I'm a newbie and I'm going nuts trying to find a solution.
mysqldump-php called for
namespace Ifsnop\Mysqldump;
use Exception;
use PDO;
use PDOException;
It didn't mention needing command line access or SUPER privilege(s).
Am I using incorrect settings?
Here's the link to the code that I'm using on Github.
https://github.com/ifsnop/mysqldump-php#dump-settings
Any help would be so appreciated!
I've had a look in the code of ifsnop, and it uses SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ before starting the transaction. Global settings are only allowed with the SUPER-privilege (which you don't have on a shared environment, with a good reason ;) ).
You can either:
If you have only MyISAM-tables, there is no need for a transaction, so it can be turned off in the config.
$dumpConfig = array(
'single-transaction' => false
);
$md = new Mysqldump($db, $user, $pass, $host, 'mysql', $dumpConfig);
or; Change that word GLOBAL into SESSION (thus modifying the downloaded code).
I have a fresh install of Laravel. When running php artisan migrate:refresh I get a message saying Application In Production! Do you really wish to run this command?'
I know this is an update in 4.2, however I can't figure out how to turn it off.
I found in the source that it comes from Illuminate\Console\ConfirmableTrait and runs if this if test passes : if ($this->getLaravel()->environment() == 'production')
I'm not sure why it thinks I'm in production. I never setup any environments. This is the default environment detection, which I'm still currently using.
$env = $app->detectEnvironment(array(
'local' => array('homestead')
));
Also, if I set a production environment to a hostname that isn't my machine, I still have the same problem.
Just specify a machine name for the host that matches a given environment, then laravel will automatically detect the environment (default is production), for example:
$env = $app->detectEnvironment(array(
//'local' => array('homestead'),
'local' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net', 'www.somedomain.com')
));
Read the documentation and this answer as well.
Setting your environment to something other than production is The Right Way. See the accepted answer.
But, if you're looking for A Quick Fix you can use (in UNIXoid environments):
yes | php artisan migrate:refresh
All this does is send a stream of "y" to the program, which acts like you pressed "y" when prompted.
I find this to be a little better than --force, as not all the artisan commands support force.
In case if anyone stumbled upon this question while searching for similar problem in a lumen installation I'd suggest to check the .env file and add APP_ENV=local if its not already there. It solved my problem.
Hopefully this will help someone else. I suddenly had an issue where my dev site I was building stopped connecting to the DB saying:
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
I was also receiving errors such as the OP when trying to run artisan migrate:refresh etc, the error was stating that i was in production etc etc.
After much head scratching (!) I found that my hostname value set inside the /bootstrap/start.php was wrong, because my hostname had changed on my macbook pro!? I have no idea how but it changed from something like RobMacbookPro2.local to RobMacbookPro.local. This meant it fell back to production thus loading the incorrect database.php file with the standard DB=forge (which was wrong)
Check this guide:
http://laravel.com/docs/4.2/configuration
Pay particular attention to the code:
<?php
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
On a mac and probably linux? you can determine your hostname by typing # hostname in terminal.
Hope that saves someone some time!
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.