I used to write my configs for Symfony project like this in config.yml file:
my_bundle:
internal_identifier: %test%
key: %someparam%
endpoint: %nobil_endpoint%
and used parameters.yml (which was ignored by git) for allowing other developers to have different values.
Bu I think using this:
my_bundle:
internal_identifier: my-identifier
key: 12345
endpoint: www.endpoint.com
still allows developers to have different values because they can use config_dev.yml which is also ignored by Git.
So my question is this: what's the purpose of parameters.yml file if config_dev.yml can be used for the same thing?
I think two things are being asked here:
Why is parameters.yml ignored be the default Symfony .gitignore file?
Why use parameters.yml instead of config_dev.yml?
Per the first question, parameters.yml is ignored by default because this file is meant to hold settings which are per-installation. For instance different developers might need different database settings. If parameters.yml wasn't ignored, your "personal" settings would be copied to every developer.
As of Symfony 2.3 you should put the needed parameters, along with default values, in a file called parameters.yml.dist. Then, when you run composer install a composer script will check for this file and create/update your local parameters.yml file, prompting you for each setting which gives you the opportunity to change the settings to be relevant to the given install.
Per the second issue, parameters are considered different than config settings. Parameters are settings which will change install to install, whereas config settings will stay the same for all installs of a particular app (although they may be different from dev to production environments.)
first, what is ignored by git is up to you, there is a .gitignore file in your repo-root
my advice to use different parameters would be:
you have different parameter.yml´s like :
parameters.yml.dev.one
parameters.yml.dev.two
parameters.yml.dev.three
and for example you are developer one then you make a symbolic link to "your" parameters.yml.dev.one like :
cd app/config; ln -s parameters.yml.dev.one parameters.yml
so now there is a parameters.yml on your machine that points on your parameters
developer two would make a symbolic link to his parameters and so on
if you are not clear about the difference between parameters and config, please check symfony book
you can do the same with your stages when you need for example another database-connection on prelive or live or whatever by using symbolic links
the advantage of this is that every developer has the parameters of every stage and developer on his machine
cheers
Being ignored by Git is the most useful, but it also prompts you for missing values when doing composer install.
If you want to have common parameters that are not ignored, you can create a parameters_common.yml and source it in config.yml (or add them directly in config.yml).
For an advanced use of config/parameters files, I suggest you check https://github.com/wemakecustom/DirectoryLoaderBundle
Because where you are in production environment, symfony needs to work in PRODuction environment and not in DEV.
Why you removed config_dev.yml from repository?
Related
I am still learning about env. I'm not sure why it's not working. I have two files in my root project folder. '.env.local' and '.env'. And, the values for .env aren't being processed. However, .env.local is working fine. I believe I followed the same format.
For the .env file, if I just write them on the page and expose them, then they work just fine.
What am I missing here, this is on a NEXTJS app. In vercel I just added Environmental variable to their built in mechanism.
In my code I wrote this to get the value.
env local file
NEXT_PUBLIC_GOOGLE=xxxxxxxxxx
_app.js
my env file
MAILCHIMP_PUBLIC_USERNAME=xxxxx
MAILCHIMP_PUBLIC_DOMAIN=xxxx
MAILCHIMP_PUBLIC_POST=xxxxxxxxxxxxxxxxxxxx&
MAILCHIMP_PUBLIC_ID=xxxxxxxx
I think .env.local is overriding the other files. Also remember to add NEXT_PUBLIC_ to the variables. After editing the .env file you should stop and restart the development server. In your case you should do the following
NEXT_PUBLIC_MAILCHIMP_PUBLIC_USERNAME=xxxxx
NEXT_PUBLIC_MAILCHIMP_PUBLIC_DOMAIN=xxxx
NEXT_PUBLIC_MAILCHIMP_PUBLIC_POST=xxxxxxxxxxxxxxxxxxxx
NEXT_PUBLIC_MAILCHIMP_PUBLIC_ID=xxxxxxxx
Did You read exactly the next.js docs about Environment Variables ? ;-)
It happens because as we can read in next.js docs:
In general only one .env.local file is needed. However, sometimes you
might want to add some defaults for the development (next dev) or
production (next start) environment.
Next.js allows you to set defaults in .env (all environments),
.env.development (development environment), and .env.production
(production environment).
.env.local always overrides the defaults set.
Here You have much more examples how to use .env properly in next.js. source, source
Good Luck and enjoy your study ;-)!
On the server I need to deploy my symfony 5.2.4 application, the database configuration is defined in an ini file for which the path is set as an environment variable.
The way I have done it right now is to run composer dump-env dev then in .env.local.php, add some code to load the inifile, parse it, then construct my database url and set DATABASE_URL to that value like that:
$inifile = parse_ini_file($_SERVER["DB_INI_PATH"]);
$databaseurl = 'mysql://'.$inifile["user"].':'.$inifile["password"].'#'.$inifile["host"].':'.$inifile["port"].'/'.$inifile["db"];
But this means that I have some code in this file that can't be versioned (because it also contains my APP_SECRET value), and anytime I need to redump my env, I will need to readd that custom code.
I have not found a proper place to add this ini file decoding process in my symfony app, so I am looking for any advice on the proper way to do that, in a way that would be versionable.
You can write your doctrine config in php and you will have access to environment variables. You can add your logic in "config/packages/prod/doctrine.php". The example in the docs shows how to set doctrine.dbal.url go here and click on the php tab for the example code: https://symfony.com/doc/current/configuration.html#configuration-based-on-environment-variables
I am using the Symfony profiler. But I actually only want to make it visible in the Dev mode. But when I push the data via git on my server and open the website, I see the profiler. That does not make sense of cause, but I do not know how to remove it.
I was looking for the file called config/config_dev.yml and config/config.yml because I would think that in config/config.yml I should just set to:
web_profiler:
toolbar: false
intercept_redirects: false
But I do not have any config.yml files. Do I have to create them?
On your server, copy your .env.dist (if you have one) to .env, and set APP_ENV=prod
If you don't yet have a .env file, create one at the root of you project, and put APP_ENV=prod in it.
That being said, note that best practice is to use server level configuration in production env. Reference link : https://symfony.com/doc/current/configuration/external_parameters.html#configuring-environment-variables-in-production
EDIT (based on the comments) for your information :
.env is a file where you will mainly put your global configuration. The .dist variant is meant to be added to git, it won't be used by symfony but is useful for the developpers (including you) to have a default config file to rely on.
Basically, when they'll pull the project for the first time, they'll copy this file to .env then adjust the lines/config to their liking.
The .env must not be added to git for it will be the file that will be used by symfony. If you add it to git, each time you will push your local work then pull from your server, it will replace your server configuration with your local one.
in my project, I want to refer to an other xcconfig file, located in InDesign SDK. As this SDK may be installed at different locations, depending upon the machine, I prefer to declare an environment variable for locating it.
Nest step is obviously to use variable (aptly named ID_CS5_SDK_DIR) in my xcconfig include directive.
Unfortunatly, when I try the simple
// InDesign sdk project build settings (based on common build settings)
#include "$(ID_CS5_SDK_ROOT)/build/mac/prj/_shared_build_settings/common.xcconfig"
XCode throws me a
[WARN]AutocatPlugin.xcconfig line 7: Unable to find included file "$(ID_CS5_SDK_ROOT)/build/mac/prj/_shared_build_settings/common.xcconfig"
How can I make it work ?
I've been trying to do this too and also came to the conclusion that it is not possible.
I once tried to achieve that and came to the conclusion that you can't. I would be happy if someone proves us it's possible though then delete my answer
It seems like .xcconfig files can only DEFINE and set value to environment variables (which prevail only throughout the build session) but not USE or evaluate environment variables.
Maybe it is because .xcconfig files serve as a base layer of build-settings, and are not parsed.
Unfortunately this is not possible, but instead of making one include the other, you can use two different xcconfig files per target. Just select one for the Project and one for the Target.
If you put the environment variable in /etc/config/launchd.conf and then reboot it will be accessible to the .xcconfig file.
Short Instructions for experienced users:
Edit the read-only file /etc/launchd.conf and add 'setenv VARIABLENAME /FOLDER/PATH' to the file, then reboot.
Steps For Inexperienced Users
Open Application/Utilities/Terminal, and entersudo nano /etc/launchd.conf
Create the Environment Variable by adding a line like setenv VARIABLENAME FOLDER/PATH and then pressing ENTER.
Save the file using Ctrl-O, Ctrl-M, (Possibly Ctrl-Y to overwrite), then Ctrl-X to exit the editor.
(Optional) type cat /etc/launchd.conf to see that your changes are present
Restart your computer. (Logoff doesn't work)
You can now access the variable in your .xcconfig file as$(VARIABLENAME)
Notes:
This creates a GLOBAL environment variable, accessible to all users. It probably doesn't make sense to set this to something in your home directory (e.g ~/MyFolder). If you do this, however, you need to use the full pathname, such as /Users/MyUserName/MyFolder).
References:
Stack Overflow - Setting Environment Variables in OSX
Stack Overflow - Are there any differences between /etc and /private /etc
I am fighting with Xcode 4 workspaces. Currently Xcode 4 wins. Thus, my situation:
I have the workspace with the iOS app project. There is also static library project iOS app depends on in the this workspace.
Solution #1
I try to configure like this:
the app project:
add to target's Build Phases > Link Binary With Library a product (libmystaticlib.a);
set USER_HEADER_SEARCH_PATHS to $(TARGET_BUILD_DIR)/usr/local/include $(DSTROOT)/usr/local/include;
the static library project:
add some header files to target's Build Phases > Copy Headers > Public;
set SKIP_INSTALL to YES.
And important thing: both projects must have configurations named the same. Otherwise, if I have, e.g., configuration named Distribution (Ad Hoc) for the app and Release for the static library, Xcode can't link the app with the library.
With this configuration archiving results to an archive with the application and public headers from static library projects. Of course, I am not able to share *.ipa in this case. :(
Solution #2
I have also tried another configuration:
Xcode preferences:
set source tree for the static library, e.g, ADDITIONS_PROJECT;
the app project:
add to target's Build Phases > Link Binary With Library a product (libmystaticlib.a);
set USER_HEADER_SEARCH_PATHS to $(ADDITIONS_PROJECT)/**;
the static library project:
don't add any header files to Public!;
set SKIP_INSTALL to YES.
I still need to care about configuration names for both projects. But in result I can build and archive successfully. In the result I get archive and I can share *.ipa.
I don't like the second solutions, because in this case I don't get any real advantage of the Xcode 4 workspace. The same effect I can add get, if I add the static lib project inside the app project. Therefore, I think something is wrong with my solution.
Any suggestion how better to link a static libraries?
I also found a solution that works with build and with archive.
In your static library set the Public Headers Folder Path to ../../Headers/YourLib
In your app config set the Header Search Paths to $(BUILT_PRODUCTS_DIR)/../../Headers
In your app you will be able to code #import <YourLib/YourFile.h>
Don't forget the Skip Install = YES option in your static lib.
We've found an answer, finally. Well, kind of. The problem occurred because Xcode 4 places public headers into InstallationBuildProductsLocation folder during build for archive. Apparently, when archiving it sees the headers and tries to put them into archive as well. Changing Public Headers Folder Path of the lib to somewhere outside of InstallationBuildProductsLocation, for example, to $(DSTROOT)/../public_folders and adding this path to Header Search Path solve the problem.
This solution doesn't look very elegant, but for us it seems to be the only option. May be you'll find this useful.
Here is a solution a get from Apple DTS. I don't like it, because it is suggests to use absolute path. But I still publish it here, maybe someone feels it is right for him.
How to set up the static library:
Add a build configuration named "Archive" by copying the Release Configuration.
Move your headers to the Project group of the Copy Headers build phase.
Set the Per-configuration Build Products Path of the "Archive" configuration to $(BUILD_DIR)/MyLibBuildDir. Xcode will create the MyLibBuildDir folder inside the BuildProductsPath, then add your static library into that folder. You can use "MyLibBuildDir" or provide another name for the above folder.
Set Skip Install to YES for all configurations.
Set Installation Directory of "Archive" to $(TARGET_TEMP_DIR)/UninstalledProducts.
Edit its scheme, set the Build Configuration of its Archive action to "Archive."
How to set up the project linking against the library:
Add a build configuration named "Archive" by copying the Release Configuration.
Set the Library Search Paths of "Archive" to $(BUILD_DIR)/MyLibBuildDir.
Set the User Header Search Paths to the recursive absolute path of your root of your workspace directory for all configurations.
Set Always Search User Paths of "Archive" to YES.
Set Skip_Install to NO for all configurations.
Edit its scheme, set the Build Configuration of its Archive action to "Archive."
I was not real happy with any of the other solutions that were provided, so I found another solution that I prefer. Rather than having to use relevant paths to put the /usr/local/include folder outside of the installation directory, I added a pre-action to the Archive step in my scheme. In the pre-action I provided a script that removed the usr directory prior to archiving.
rm -r "$OBJROOT/ArchiveIntermediates/MyAppName/InstallationBuildProductsLocation/usr"
This removes the usr directory before archiving so that it does not end up in the bundle and cause Xcode to think it has multiple modules.
so far I also struggled with the same problem, but did come to a solution with a minimal tradeoff:
This requires Dervied Data to be your Build Location.
I set the Public Headers Folder path to ../usr/local/include
This will ensure, that the headers will not be placed into the archive.
For the app, I set the Header Search Path to:
$(OBJROOT)/usr/local/include
$(SYMROOT)/usr/local/include
There are 2 entries necessary since the paths slightly change when building an archive and I haven't figured out how to describe it with only one variable.
The nice thing here is, that it doesn't break code sense. So except for having 2 entries rather than one, this works perfectly fine.
I'm struggling with the same problem at the moment. I didn't progress much farther than you. I can only add that in the second solution you can drag headers you need to use from the library to the app project, instead of setting ADDITIONS_PROJECT and USER_HEADER_SEARCH_PATH. This will make them visible in app project. Value of SKIP_INSTALL flag doesn't matter in this case.
Still, this solution isn't going to work for me, because I'm moving rather big project, with dozens of libraries, from Xcode 3 to Xcode 4, and it means really a lot of drag and drop to make my project build and archive correctly. Please let us know if you find any better way out of this situation.
I could use Core Plot as a static library and workspace sibling, with two build configurations:
Release:
in project, Header Search Path: "$(BUILT_PRODUCTS_DIR)"
in CorePlot-CocoaTouch, Public Headers Folder Path: /usr/local/include
AdHoc (build configuration for "Archive" step in Scheme, produces a shareable .ipa):
in project, Header Search Path: "$(BUILT_PRODUCTS_DIR)"/../../public_folders/**
in CorePlot-CocoaTouch, Public Headers Folder Path: ../../public_folders
Hope it will help someone to not waste a day on this.