I'm starting with Git and Github for versioning my Symfony3 project and I was wondering why parameters.yml is in the .gitignore file by default? I'm changing that file so that my app connects to a PostgreSQL database.
My concern is that when others clone my project from GitHub and start contributing will it affect them to have the parameters.yml file missing?
Do I need to remove it from .gitignore?
If not when do I have to make it trackable?
Thanks for your answers
From the docs:
The default parameters.yml file... defines the options related to the database and mail server infrastructure.
Each of your servers will have its own infrastructure configuration. No one who clones your project will be sharing your exact server configurations. You also don't want to publish your system credentials to the internet. So this file should be ignored by git.
Instead you want to share a similar file for each user to set up their own parameters:
Symfony includes a configuration file called parameters.yml.dist, which stores the canonical list of configuration parameters for the application.
Whenever a new configuration parameter is defined for the application, you should also add it to this file and submit the changes to your version control system. Then, whenever a developer updates the project or deploys it to a server, Symfony will check if there is any difference between the canonical parameters.yml.dist file and your local parameters.yml file. If there is a difference, Symfony will ask you to provide a value for the new parameter and it will add it to your local parameters.yml file.
Because this file it's going to be generated from parameters.yml.dist when you run composer Update
Related
I am new to Laravel and want a simple explanation of the .env and .env.example files, why we need them and the difference between them.
I know that .env is used to specify the app's database connection, for example but I would like to understand it deeper.
.env file, as its name suggest, is a local where you put all your environment setup, such as database credentials, cache drivers and etc. Everything that is about the server that the project is running, and may have different values for different servers, are setup here.
Per example, your local dev environment has different database credentials than production environment. Also your colleague dev environment has different than yours. So each one has a .env with different informations.
And because of these, this file can't be versioned, so .env.example is the file that has every constants setups that .env has but with no values, and only this one is versioned. .env.example works as a guide for creating a .env file with the needed informations that is needs to have the application running.
As you are working with Laravel, you can find more informations here: environment-configuration
The .env file stores configuration variables for your application and .env.example is simply an example of what might be in the .env file! You can easily rename .env.example to .env to get started.
What are configuration variables? From The Twelve-Factor App
An app’s config is everything that is likely to vary between deploys (staging, production, developer environments, etc). This includes:
Resource handles to the database, Memcached, and other backing services
Credentials to external services such as Amazon S3 or Twitter
Per-deploy values such as the canonical hostname for the deploy
In Laravel the .env file also contains your app key which is used for encryption in your app. Because of this, and because you will likely store other private keys in this file, ensure you do not commit .env to your source control or share it publicly!
I recommend you read the link above for an explanation of why you should separate configuration from your application and for Laravel-specific information you can look here
.env file contains various settings, one row – one KEY=VALUE pair. And then, within your Laravel project code you can get those environment variables with function env(‘KEY’).
The rule is that .env file is not committed to the repository, so it is really convenient, cause then people on your team can change their variables locally without committing them to the repository.
Now, .env.example file, on the contrary, is included in the repository – it is used as an example file for you to know what KEY=VALUE pairs you need for your project. Most often it is used to copy it to .env file and then change the values.
You can also read about it in the official Laravel documentation.
.env is simply used to store all sensitive files like password API key, database,and so on as environment variables to be used in your code later this sensitive files are not included in the code base and will not be there when been pushed to git.
.env.example
This is a file that tells other programmer what is meant to be in there code when your code is cloned or been used by another user.
Example
.env
API_KEY="hwhhwhshs6585gahwhgwuwjwusuhs"
.env.example
API_KEY="YOUR API KEY GOES HERE"
The .env.example file is just an example of the .env file. It is not used by the app. It's used to serve as a base for you to edit and rename.
The .env file contains constants that are specific to that application to those environments. What this means is for example if I want to deploy my app in multiple places with the same code, I'll just have to change some settings on this file to run on each environment and we are all set, no code changes needed.
These settings can be database connection settings but they can be used for other things too like the APP_KEY that should be different for each application and used my many functions.
Be careful, this .env file should not be shared anywhere as it contains private information about that specific deploy.
You can read more here: https://laravel.com/docs/5.6/configuration#environment-configuration
From the version Laravel 5.0 in your main folder you should have .env file which contains various settings, one row – one KEY=VALUE pair. And then, within your Laravel project code you can get those environment variables with function env(‘KEY’).
The rule is that .env file is not committed to the repository, so it is really convenient, cause then people on your team can change their variables locally without committing them to the repository.
Now, .env.example file, on the contrary, is included in the repository – it is used as an example file for you to know what KEY=VALUE pairs you need for your project. Most often it is used to copy it to .env file and then change the values.
Your .env file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed.
If you are developing with a team, you may wish to continue including a .env.example file with your application. By putting place-holder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application. You may also create a .env.testing file. This file will override the .env file when running PHPUnit tests or executing Artisan commands with the --env=testing option.
.env or environment variables are files that store some sensitive information like your API key. They are only visible to you on your PC/local system. Not to anyone else, if you push your project to GitHub or some other platform.
.env is a file that store information about your website such as API or database password.
these information are visible for you in local host. when you publish website on a host this file not visible for other people.actually env's file improve security website on the net.
I'm developing some web application (php, codeigniter). Today a time to push it to github has come, but I've encountered an issue I can't manage.
I've got 2 branches:
master - this branch should be used for github pushing, does not contain credentials or any other sensitive data (just public code)
dev - this is master's child, used for development, does contain credentials (of my private app instantion)
By credentials I mean: database login, password, host, user; oauth services id / secrets; encryption_key. Credentials are stored in 2 separated files within /application/config folder.
The idea is that I'll make all changes on dev, than merge dev into master, and pull master content to github (but master can't contain my private credentials).
This is what I've done till now:
Removed all credentials from /application/config/config.php and /applications/config/database.php (as I don't want them to be public on github) they've become an empty strings like:
$db['default']['hostname'] = '';
Started git repository and made an initial commit - the default branch that was created is named 'master'
Pulled master into github
And it's pretty cool till now - I've got my project code on github with no credentials within. Next I need to make some changes in my project, so I:
Created new branch 'dev'
Stored my credentials into dev, and make a commit - I need dev instantion to have credentials as I'm uploading this to ftp server every time I change something in the code (I don't use local LAMP or anything like this in this project)
So now I need to make some change in dev, upload it and pull to github so I:
Make an change on dev (let's say add new feature)
Checkout to master
Merge dev into master.
What I expected to happen:
Git will ask me which version of configs should be used in 'master' as it is different in both branches. I will use diff to chose a 'master' verion of files (which does not contain credentials). Git will remember my choice, and in the future I will not have to chose again when I'll merge dev into master.
Git works like this on one of my other projects, where dev is a master branch and instantions are it's children (In this case dev is a child and I merge child into parent).
What happened:
Git just copied credentials from dev to master, did not ask me about that. So now my master branch is 'tainted' by credentials and I can't push it to github anymore.
My questions are:
Why is that happening, how can I avoid this?
Is there any other (better?) way to handle that kind of issue.
Please let me know if anything is unclear, any help will be appreciated.
Git will only flag a conflict if files in your master branch were changed after your original branch to dev, then the same files were changed in dev.
I suggest you add a .gitignore entry for your credentials, or separate them using an ENVIRONMENT variable, in codeigniter this is very easy, all you have to do is on your apache config (vhost if your using them) is add SetEnv APPLICATION_ENV development then you can add a folder inside application/configs called development, now when you are running in development environment, these configs will take precedence over the ones in the base config directory.
This isn't so much about gitignoring files, or removing commits, but a good file structure, and environment setup to differentiate between the separate environments, you an use development, staging, and production (which is the default)
otherwise add a .gitignore row to tell git to ignore those certain files.
Git ingore will help.
Read this blog post for solution.
http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/
You can include the credentials from a configuration file and add that file to .gitignore.
The config file can consist of settings for the dev, preproduction and production environments.
I am about to start a CodeIgniter based project and plan on using Git as our DVCS. I will be working with a few other developers, and the central (origin) server is privately hosted. But I also want to open source it and publish the code to Github later.
My question is, is there a way to separate the config file(s) in Git, so that the private information in the config file is not sent to the Github remote but is to origin and other peers.
Another question is could we use a similar solution for having local development config files and a server one for production?
Create the files config.php.sample and database.php.sample that each of your developers will use that has a placeholder for the passwords and other sensitive information. Add config.php and database.php to your .gitignore
The first time you deploy to the production site, you'll create the config.php and database.php files. Subsequent pushes won't overwrite config.php and database.php since they're not included in the git repository.
Codeigniter has some support for environments (Development, Production, etc).
Refer to official documentation , CodeIgniter Environments.
Regarding config files, you can use .gitignore
http://progit.org/book/ch2-2.html
Edit:
Since you have used github tag in the question; Github now has an option to add .gitignore file (they have a codeigniter template too )
You should use a deployment tool to set the config file when deploying your application to the destination system.
capistrano with railsless-deploy is a good option
I have a developed a small web-app in Symfony 2 and Doctrine 2.
Can i deploy it to a web-host that doesn't give SSH access?
I ask this because i see there are a lot of task that must be done from the terminal, like updating the database schema, creating symlinks for the assets, clearing cache, etc...
Should not be a problem:
Create a copy of the system somewhere, ideally with identical DB connection params like the production system.
Run all the necessary tasks with the --env=prod parameter, if your DB settings allow it.
Clone the created production database to the production system (with phpMyAdmin). You can clone the schema from the production database, run app/console doctrine:schema:update --dump-sql locally and then run the generated SQL on the production server.
Copy all the files, excluding the dirs in app/cache and app/log
I have done this many times with SF 1.4, and it should be just as easy with SF 2.
Some low end hosts have restrictions that will cause issues for symfony, so its important to run the symfony compatibility checker script (you can upload it and then enter its URL in your browser to get the output). Once thats done, follow these simple steps:
copy over all the files for the project. I usually zip/tar the project folder, upload it, and unpack.
Export the database from your development environment and upload it to your new server.
Edit the config and update your database settings. If you have hardcoded paths somewhere in your code, now is the time to fix those as well.
Make sure that the user for apache (or whatever server software your host uses) has full access to the cache and log directories. This can be tricky on some hosts, I have had to contact support in the past to have someone log in and change permissions.
In your web hosts configuration tool, set the webroot for your site to the web folder in your project.
Maybe there is a way (with sftp for example), but it would be like trying to ride a bike with square wheels ;)
Between me and a Network Architect we manage a bunch of Web Servers (FreeBSD). He's responsible for all server/network related stuff (IPs, Firewalls, users/groups, etc.) and I'm responsible for all web-related stuff (Apache, PHP, MySQL). Sometimes the responsibilities overlap.
It happend few times that some changes were made to the config files which more or less affected the server and we were not able to figure out which of us made the changes and why.
I - being a Web Developer - think it'd be a good practice to put the files under version control (we currently use Subversion), so that whenever we change anything we have to commit an comment the changes. It'll solve all the problems with wondering who did what and why.
The particular config files I was thinking of were:
firewall config
apache config (with extras)
php config (php.ini)
MySQL config (my.conf)
I already know, that the idea version control of server config files is sound based on other question asked here. My only worry is how to do it properly on the Web Server side since the files are in different locations. Putting the whole /usr/local/etc under version control seems pointless as it contains not just the config files.
I was wondering whether not to create a new folder, say /config which would be under version control and would contain all the config files we need and then replace the original ones with symlinks to ones in the /config folder. E.g.:
/usr/local/etc/apache22/httpd.conf -> /config/apache22/httpd.conf
So the question is: Is this a good idea and if not, what is a better solution?
If you use GIT then puitting the whole /usr/local/etc under version control is not pointless at all.
you can only track a handfull of files if you so chose
the working directory with all config files tracked is hardly bigger in size
Just install git, then go to /usr/local/etc and write git init. This will create the .git folder in your current location (basically making this folder a repository).
Then add the config files you want to track:
git add firewall/firewall_config.conf apache2/httpd.conf etc
and commit: git commit -m "Initial Configuration"
Your config files are now being tracked.
Since you are versioning sensitive configuration files, I would recommend setting up an internal git server like gitlab. Create a git repository for each server, or server template/image/etc. Go to the / directory and 'git init'.
You can be selective about what you put under version control by only using 'git add /path/to/file for the files that you will be customizing.
Then, 'git -m 'commit comment' and 'git push -u origin master'.
Have you looked at any of the management tools made to do just this sort of thing? I recommend Puppet or Chef, having used them in previous jobs to do this sort of thing.