Configuring the project (config.neon)

Notice: This thread is very old.
ivanscm
Member | 16
+
0
-

Tell us about the configuration of “config.neon”, in particular about the tuning of the database. What would be some parameters were taken locally, but on the other production. And what to do with the sections of “common”, “development”, “production”. The symbol “<” is the inheritance? And then be rewritten as parameters?

Patrik Votoček
Member | 2221
+
0
-

So… Yep < is inheritance.

common is “base” section of config. development is section for your localhost or development server (inherit / overide common params, services etc). production is secion for any other servers.

Nette is detect if your request comming from localhost (127.0.0.1 or ::1) and switch your app to development mode.

For more info please see documentation

juzna.cz
Member | 248
+
0
-

I've take another approach to separating development/production configuration. The main reason was that I don't want my database password to be available for all developers, and also to give all the developers freedom to configure anything on their machines and not bother others with that. Saying that, having one config.neon file with more sections was not possible.

Therefore I decided to have two configuration files (without sections like common/production/dev):

  • config.neon which is common for all machines, it is versioned in git and it doesn't contain any password.
  • config.local.neon which is per-machine, i.e. contains only variables for that one particular machine (like passwords, database name, …); it it NOT versioned in git (since every instance has a different content).

With this approach I don't have to rely on Nette's ability to detect dev/production mode and to choose proper section from config file. Also, passwords for production DB are only on production server, nowhere else. Third thing is, that each developer can have his own config and password and doesn't have to share it with others in one common config file.

I consider this approach much better in all ways ;)

Implementation

in bootstrap.php:

$configurator->addConfig(__DIR__ . '/config/config.neon', FALSE);
$configurator->addConfig(__DIR__ . '/config/config.local.neon', FALSE);

FALSE as second parameter means NOT to load sections from the file.

ivanscm
Member | 16
+
0
-

please show how to properly write

#
# SECURITY WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
#
# If you don't protect this directory from direct web access, anybody will be able to see your passwords.
# https://nette.org/en/security-warning
#
common:
	parameters:
		database:
			driver: mysql
			host: localhost
			dbname: my_local_db
			user: root
			password:

	php:
		date.timezone: Europe/Prague
		# session.save_path: "%tempDir%/sessions"
		# zlib.output_compression: yes


	nette:
		session:
			expiration: '+ 14 days'

		database:
			default:
				dsn: '%database.driver%:host=%database.host%;dbname=%database.dbname%'
				user: %database.user%
				password: %database.password%


	services:
		database: @\NConnection

		authenticator: Authenticator( @database::table(users) )


	factories:


production < common:
	parameters:
		database:
			driver: mysql
			host: my_prod_host_name.domain
			dbname: my_prod_db
			user: my_prod_user
			password: my_prod_pass

development < common:
	parameters:
		database:
			driver: mysql
			host: localhost
			dbname: my_local_db
			user: root
			password:
juzna.cz
Member | 248
+
0
-

That looks correct. Is there something what doesn't work?

ivanscm
Member | 16
+
0
-

Sorry, I forgot to clear the cache. Everything works fine!