# Symfony Fundamentals: Bundles, Configuration & Environments

After the first course - Joyful Development with Symfony, you've got Symfony up and running. CELEBRATION!

In this episode, it's time to get down to work by learning the fundamental concepts of bundles, configuration and environments! We'll discover what all the files in a Symfony project do and why, the purpose of bundles and the power behind environments. So let's get to work: what we're about to learn will pay dividends for us in the future:

• Where do services come from?
• Installing an external bundle
• Configuring bundles
• Controller outside services
• Using config:dump-reference
• Understanding Symfony environments
• The prod environment and cache:clear
• The famous parameters.yml
• Where do routes come from?
• src/ versus app

0%

### Questions? Conversation?

• 2017-06-26 weaverryan

Thanks Yan Yong!

That's a cool idea! We'll be updating the courses next year for Symfony 4 - I'll consider doing something like that then - it would be neat!

Cheers!

• 2017-06-25 Yan Yong

Thanks Ryan. Your tutorial makes learning symphony quit enjoyable. My suggestion: if you could include a cheatsheet pdf for this course with simple topic that will be very nice.

• 2017-05-29 Victor Bocharsky

Great! We're going to add more coding challenges in the future, actually, we want to have coding challenges for all our course, but it need some time to be done.

Cheers!

• 2017-05-29 Robert Went

Ah ok, thanks for the clarification!
Really enjoying it so far.

• 2017-05-29 Victor Bocharsky

Hey Robert,

Unfortunately, not every course has coding challenges - this course doesn't have them yet. Coding challenges are displayed in course's table of contents, for example, check this one which has coding challenges: https://knpuniversity.com/s... .

But every course has start and finish code, which you can download and open in your IDE if your don't want to code along with the author during the course. On each course chapter page you can find "Download" / "Course code" buttons, however this option available for those users who has paid subscription or own the course.

Cheers!

• 2017-05-28 Robert Went

Where do I find the 'coding challenges - practice with real code in an IDE' for each course?

• 2017-05-22 weaverryan

Yo Mert Simsek!

Hmm, I am far from an expert on this. However, I believe that you need to create some sort of connection between Redis and HTTP so that you can create a socket connection in JavaScript. For example: http://haishibai.blogspot.c... or https://www.compose.com/art.... The solution likely won't have anything to do with Symfony or Twig: you'll just render a page in Symfony/Twig, then create some JavaScript that will create be the subscriber. You don't need a subscriber in Symfony: if you want your frontend to be able to update based on published messages, then your frontend (JS) needs to be the subscriber.

Cheers!

• 2017-05-20 Shairyar Baig

That's exactly what I am doing now :) features are ready just few tweaks here and there. Cache is good idea I will implement that thanks for the tips.

• 2017-05-19 Mert Simsek

Hi,

I want to get real-time data. Can I do this with redis pub / sub? I own the node.js publisher. I have a symfony subcriber. Can I get the data from node.js and change the twig interface? But i would render twig. How will i send data to twig files?

• 2017-05-18 Diego Aguiar

I would suggest you to first focus on functionality, and then, when you detect a bottleneck, optimize your code / cache a few queries

Have a nice day!

• 2017-05-18 Shairyar Baig

Hi weaverryan many thanks for getting back with your suggestions. I ended up using rendering controller inside twig https://knpuniversity.com/s... which worked out fine, its not a heavy traffic site so an addition ping to db wont hurt the performance. Thanks.

• 2017-05-17 weaverryan

Hey Shairyar Baig!

Caching! There are 2 ways to cache in Symfony: (A) via the fairly new Symfony cache component or (B) via HTTP caching. Honestly, we need a tutorial on both of these. I would use Symfony's new cache component. Let me give you a few details:

A) I don't know what your database setup looks like, but somewhere in your template, you'll need to fetch the image. Create a new Twig function to do this - so something like:

<img src="{{ get_company_logo() }}"/>

B) In your Twig extension, you'll be able to make a query to find this path. Symfony 3.1 also comes with a new service whose id is cache.app, which you can use to cache the path to the logo. Here are some quick docs about it: http://symfony.com/blog/new...

C) This should be not too hard - just use dependency injection to pass that service to your Twig extension - I know you, so I know you can dig into it ;). But, now what happens when your admin uploads a new logo!? We need to invalidate the cache. Basically, when the user uploads a new image (e.g. you could do this in the controller), you'll need to invalidate the cache you just stored. Details here: http://symfony.com/doc/curr...

And of course, I also need to say "Don't prematurely optimize". Having an extra database query is not ideal... but probably doesn't hurt performance much. So, balance that with the added complexity of caching!

Cheers!

• 2017-05-16 Shairyar Baig

I was looking for a way to allow the admin of a symfony based app to upload a logo via admin panel and then use that logo on every page, I certainly do not want to ping the database on every route just to get the logo. I cannot seem to find any example on how to achieve this. Any tips :)

• 2016-12-05 weaverryan

Ah, thank you!!

• 2016-12-04 Hoàn Vũ Trần

Your courses is amazing, thank you it all !

• 2016-07-09 Paul De Zwaan

Authors!, symfony is not disappointing me sofar , before have been doing a lot of stuff in Yii, as i have been wanting to try out symfony for a long time, this was really the help that i needed to switch from framework. So big Thanks! Keep up the good work!

• 2016-05-24 Shairyar Baig

I am running one of the client's project on shared hosting and its no fun :( i miss having access to CLI to run commands specially when i need to clear cache. It will run without problem but you need to setup .htaccess file in root to point to web folder other wise your every URL will have the word web in it like http://example.com/web

• 2016-05-16 Thierno Diop

thx a lot

• 2016-05-07 weaverryan

For this, you would dump your local database to an SQL file and import it into your host's database manually (through whatever process they allow you - like phpmyadmin). For database changes in the future, you wouldn't be able to use migrations (like we do in this tutorial) - you would need to make those changes manually (though you could copy the SQL statements from the migration files and execute those manually).

It's not *ideal* to run Symfony without CLI access. It's definitely possible - but as you can see, parts get more complex :)

• 2016-05-05 dominik

how about the initial setup, like doctrine:database:create and such.. is there some way to do it by a script instead of cli?

• 2016-05-04 weaverryan

Ah, I understand! Ok:

1) I'm using the normal "terminal" app in OSX. There are other terminal apps you can download - but this is the normal one that comes with OSX.

2) For the file and directory coloring, I added the following 2 lines to my ~/.bash_profile file

export CLICOLOR=1export LSCOLORS=GxFxCxDxBxegedabagaced

Here is the reference I originally used for this: http://osxdaily.com/2012/02.... After you make the change, open a new terminal tab to see it.

3) If you want to change the text that appears at the beginning of each line in your terminal to look like mine, then you can add the following line to your ~/.bash_profile

export PS1="\w$" After you make this, open a new terminal tab to see it. This changes the text at the beginning of each terminal line from: Ryans-MacBook-Pro-4:oo weaverryan$to~/path/to/current/directory$ Cheers! • 2016-05-04 Thierno Diop thx for the reply i mean the cloring of file and folder and can you be more clear about the export ps1 and how to do it and what you mean by stock"terminal" THX you did well with these formations • 2016-05-03 weaverryan Hi Dominik! I don't know of any such tutorial. However, the most important thing is that you: A) Upload all of your files (somehow) to the server B) Empty the contents of the var/cache directory (app/cache for Symfony 2.x) C) Make sure the var/cache and var/logs are writeable by the web server (usually done by 777'ing those directories, but this has - in theory - some security implications). This is a non-standard way to use Symfony, but there's no reason that it shouldn't work. Good luck! • 2016-05-03 dominik Hi Ryan, do you know some tutorial for deploying a Symfony app to a shared hosting, where you are not able to run any console commands? Thanks! • 2016-05-02 weaverryan Hi Theirno! Which part - the coloring - or something else? To have a short "prompt" (just the directory at the beginning of each line), I have this code in my ~/.bash_profile file: export PS1="\w$ "

I also - obviously - have made my font size really big - Manaco 22pt. And I *am* using the stock "Terminal" application.

Does that help? Glad you like it :)

Cheers!

• 2016-05-01 Thierno Diop

please can u telle me how did you do to have a terminal like yours in your macbook

• 2016-03-29 weaverryan

I haven't used it personally - so sorry, I can't help!

• 2016-03-29 weaverryan

Dude, awesome! Welcome :)

• 2016-03-27 Infete Shine

Hi

Anyone using IvoryCKEditorBundle?

I just want to know how can I add mathjax plugin to it?

Thanks

• 2016-03-23 Constantin

Hey authors! Thanks for this great learning resource. I am migrating from Laravel to Symfony and the way you structured the course makes it a piece of cake. Thanks!

• 2016-03-01 Felipe Martins

WOW! Thanks Ryan & Leanna!

• 2016-02-29 Michal Jarnot

yay :)