ZF3 Development Mode VS Production Mode

2019-07-14 06:23发布

问题:

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).

回答1:

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.



回答2:

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.