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.
Related
In a page on my site I receive this error about debug toolbar, as suggested in other answera at similar question:
The directory /runtime and all sub-dir have right chmod permissions, after some test I've tried with 777 mode but the error remains (is bad I know, but is only for test);
The index.data have not the tag wich generate the error;
After run composer update command the error wasn't solved;
No error logs was generated in runtime/logs folder;
In a first time the xdebug module was not installed, after I've installed the extension error was not solved;
[Edit 1] The /runtime dir was be cleaned after every test
The debug module configurations:
`$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['127.0.0.1'],
];`
The site is made by advanced template, someone have an idea about how I can solve this problem?
The Yii2 advance template has two runtime folders, the backend runtime and the frontend runtime
You need to clear one you are debugging.
I know there are some questions almost identical but none of them seems to be my case.
I have a symfony 2.8.3 project that reads and imports data from an excel file into mysql database. Its all working nice on localhost but in the last 48 hours I've been trying to get it working on my server. Its a shared hosting, with no SSH access to the linux.
When I am trying to load it from the server I get this error: "You have requested a non-existent service "phpexcel"."
Looks like you want to use service from ExcelBundle. But that bundle is not loaded. Check if you have it added for production env.
$bundles = array(
// ...
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
);
Don't forget to clear cache on production environment after any config (AppKernel.php also) change.
To clear cache run php app/console cache:clear. You can also add env parameter: --env=dev or --env=prod - depending on your env. If it don't help then just remove all content of app/cache/ directory (or var/cache/ in case of Symfony3 app)
Pawel answered correctly, but something is missing: after you add this line: new Liuggio\ExcelBundle\LiuggioExcelBundle(), to the AppKernel.php file, inside the $bundles array, don't forget to clear the cache: delete the file from app/cache/dev in case you're in developer mode or app/cache/prod in case on production mode.
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!
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.
I am trying to migrate my PHP application to an Ubuntu server, but without succes. Any help would be appreciated.
First I installed Doctrine successfully into /jorrit/myapp, following the first part of Doctrine's Getting Started manual (till "Generating the Database Schema"). Secondly I placed my PHP scripts (which use Doctrine) in folder /jorrit/myapp.
When I try to run my PHP script in the CLI, I get this error messages:
PHP Warning: require(/tmp/__CG__Source.php): failed to open stream: No such file or directory in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200
PHP Fatal error: require(): Failed opening required '/tmp/__CG__Source.php' (include_path='.:/usr/share/php:/usr/share/pear') in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200
Bootstrap.php looks like this:
<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = false;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'xx',
'user' => 'xx',
'password' => 'xx',
'dbname' => 'xx',
'profiler' => 'false'
);
// obtaining the entity manager
$entityManager = EntityManager::create($dbParams, $config);
?>
The first lines of my PHP script:
<?php
require_once "bootstrap.php";
require_once 'classes.php';
$connection = $entityManager->getConnection();
The application works fine in my development environment (Windows). The /tmp folder exists and is accessible. The database is migrated succesfully and exists. I did not change anything in the vendor folder.
Any ideas? Thanks in advance for your help.
TL;DR You'll just need to generate your proxy classes manually
vendor/bin/doctrine orm:generate-proxies
Doctrine uses Proxies to connect the to database. Proxies are generated from the the Entity classes.
In development mode, it generates a Proxies on every request because you could make changes to Entity classes.
In production mode, it does not generate Proxies every time. For performance reason, it assumes the Proxies exist and include them directly.
There are a few mode for Proxies generation:
ALWAYS - It alwayes generates Proxies, this is the default setting for development mode
NEVER - It never generates Proxies, this is the default setting for production mode
ON_DEMAND - It only generates the Proxies if the Proxy files do not exist. The drawback of this option is that it has to call file_exists() every time which could potentially cause a performance issue.
Now the command
vendor/bin/doctrine orm:generate-proxies
generates Proxy classes to /tmp. I would say this might still cause trouble because other applications
on your server might delete these files unexpectedlly. One option is you can change your /tmp directory access permission to 1777
sudo chmod 1777 /tmp
The stricky bit '1' in front of 777 means that, although everyone can read/write to the /tmp directory, but you can only operate on your own files. i.e. You can't remove files created by other users.
For further reading, please have a look at
http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#auto-generating-proxy-classes-optional
You can also set the Proxies directory to somewhere else so no other applications can modify them. http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#autoloading-proxies
In code after $config line you could try
$config->setAutoGenerateProxyClasses(true);
But the CLI version is much better, because it avoids on refresh regen as in code might not avoid.
To change cache dir you could try:
$cacheDir = dirname(__FILE__).'/cache';
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $cacheDir);
Looks like a permission problem, first should chek on permissions for the entire application folder.
Also try to hard-cleanup cache by deleting app/cache/* files, and try again.
Good luck!