12.
Deployment
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
24 Comments
Hello SymfonyCasts,
I am looking for deployment instruction like this but with Symfony 4 do you have a tutorial for it?
Thank you!
Hey Dung L.
We don't have chapters like this one specific to Symfony4 but deploying a Symfony4 app shouldn't be too different than a Symfony2. You just need to tweak some commands, like for example,
php bin/console cache:clear(and cache warmup). What we have is a tutorial to learn how to deploy automatically applications using Ansible. Ansible is a great tool for automation, if you are interested in that topic I really recommend you to check it out: https://symfonycasts.com/screencast/ansibleCheers!
Hi MolloKhan I am running into issue like this post https://stackoverflow.com/q...
the routing does not seem to work, the only route that works is path '/' I think i am missing something basic like rewrite rules .htaccess. I read and followed this link but still that does not help https://symfony.com/doc/4.1.... can you give your suggestion? Thanks!
ok this tutorial helps me get it working https://www.youtube.com/wat...
Thanks!
Any plan to make couple of videos for Symfony4 project? I would like to see Manual deployment, Github deployment & automated tool deployment. Another topic that I dont understand is where uploaded documents are suppose to be stored? I dont want to make them public therefor I need somehow to move it 1 level up and how this would work with manual deployment I have no idea.
Yo Peter K.!
Yes, I think we're going to cover a lot of this... sort of in several different tutorials. Let's take a look:
1) Our main deployment tutorial is this: https://symfonycasts.com/sc... - it uses Ansistrano (basically Ansible). But even if you don't want to use Ansible, we *really* went into deep detail about all the pieces of deploying a Symfony app. It's built in Symfony 3, but the only real difference between Symfony 4 are the environment variables. Which... unless you're deploying to an environment that really makes using real env vars easy, I still recommend just creating a .env.local file on production for your production variables. So this is ultimately no different than parameters.yml (which is what we cover in that tutorial).
> 2) Another topic that I dont understand is where uploaded documents are suppose to be stored
Well... you're in luck! This tutorial starts next week: https://symfonycasts.com/sc...
But, to answer your question a little bit... it depends :). First, you can decide to store them in the cloud - like S3. When you do that, you can make each file public or private. If it's public... you can just link to it. If it's private, you can create a signed URL when you want to allow someone temporary access. We'll cover that in the tutorial. If you just want to keep it simple and upload to your server, then if you want the files to be public - put them in something like public/uploads. Done! This directory will be ignored by git and when you deploy, this directory simply won't be touched (e.g. you could do a simple "git pull" on the directory, and because that directory is ignored, nothing happens to it). If you need your files to be private (e.g. require login, or something), then I recommend putting them into var/uploads (this directory would be ignored, just like public/uploads). Then, you'll need to create a route/controller that a user can go to to download that file. You'll check the credentials then use the BinaryFileResponse to stream that file to the user.
If I've missed anything else on the upload topic - let me know. The tutorial is not fully written yet and I don't want to miss any great topics!
Cheers!
Hi everyone :)
I have one problem with my SF 3.4 deployment. Well the app works BUT the errors page override doesn't.
I have put my pages in app/Resources/views/TwigBundle/views/exceptions but nothing changes.
I have delete the app_dev.php and set an environnement variable with SYMFONY_ENV=prod but nothing change too....
Did i forget something ? :/
Regarde,
Christophe
Hey Christophe Lablancherie
Are you hitting the dev or prod environment? If it's prod environment, then everytime you make a change you have to clear the cache.
If it is dev's, then you can access to your error pages by going to
localhost:8000/app_dev.php/_error/404where "404" is the code of the errorCheers!
Hi MolloKhan , i hit the prod environnement, and yes i clear the cache everytime i do a change, but look i receive a 404 exception but the page look like dev template :/ https://www.domilia.ca/fr/p...
Oh, I think it's because of the name of your folder, it should be called "Exception" and the templates should be pre-fixed with "error", then the number
Docs: https://symfony.com/doc/3.4...
Hum my Exception page are there :
app > Resources > TwigBundle > views > Exception > error404.html.twig
app > Resources > TwigBundle > views > Exception > error500.html.twig
Wait, I think you are not hitting prod's environment, you should not see the error details, just an ugly page with a white background. Could you double check that? Review your "web/app.php" and at any controller's action just dump this
$this->getParameter('kernel.environment');https://www.domilia.ca/fr/
I've done it, and it seems that we are in prod :/
By the way i'm totally agree with you, i have to see "an ugly" page :/
Here the app.php page
use Symfony\Component\HttpFoundation\Request;
require __DIR__.'/../vendor/autoload.php';
if (PHP_VERSION_ID < 70000) {
include_once __DIR__.'/../var/bootstrap.php.cache';
}
$kernel = new AppKernel('prod', true);
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Aha! can you see the error?
...
...
This line
$kernel = new AppKernel('prod', true);You must set to "false" the debugging flag on prod environment
Cheers!
Oh god ok ! I thought it was obvious to put "true" on the kernel when we go to prod.
Thanks !
You're welcome :)
Hi Guys,
you mention about doctrine migrations being a safer way for renaming the table columns, but how would you make sure that update schema does not break your database?
In other words how do you tell update schema not to drop this table because there is a fix in doctrine migrations for example?
Also another question is how do you deal with having multiple bundles having their own migrations, since there is only one migration_versions table?
Thanks a million!
Hey!!
If you use migrations (http://symfony.com/doc/curr... then you'll be able to review the SQL in your new migration file to make sure it works. For example, if you renamed a column and the generated migration did a "drop and add" instead of a rename, you could modify that SQL until you're happy with it.
Then, when you deploy, you *never* run doctrine:schema:update - you only ever run doctrine:migrations:migrate. If you need to rename a table, then you will have already made sure that your new migration file performs this rename. If you've done everything correct, then after your migrations run, you production database will be perfectly in-sync. In other words, if you *did* run doctrine:schema:update --dump-sql after migrations, it should come back with no changes to be made. Does that make sense? Getting the workflow correct is really important :).
About multiple bundles and only one migration_versions table, that is by design and a good thing! Sure, you may have multiple bundles, but you only have one database, and so it makes sense to only have one set of migration files. Now, imagine that I install a third-party bundle that gives me 2 new tables. This bundle will *not* ship with its own migration file to add these 2 tables. And, that's ok! As soon as you've installed the bundle, you can run doctrine:migrations:diff, and this will cause a new migration file to be generated with the CREATE TABLE for those 2 new tables.
Does it all make sense? Let me know!
Thank you very much. it all makes sense.
Hi Guys,
Thank you for your help,
just i'm trying to upload small project i'm working on right now
I did the deployment configration on Phpstorm i uploaded the project folder on the server, i can see the files on the server, also before uploading i changed parameters settings to the server details. but no thing worked
i believe maybe there is some thing i should have done before uploading .
please if possible help with the deployment steps
many thanks
Mohamed
Hey Mohamed,
That's a bit tricky to deploy Symfony with this PhpStorm feature. I just worry about your local cache folder, does it move to the prod server too? Because it could cause problems, most likely you have different paths on the server and your local machine. Anyway, after you upload the project to the prod server - you need to clear the cache. You can do it with Symfony console command or just "rm -rf var/cache/*" should work fine, but in this case your won't be warmed up, some users could feel a delay before seeing your website. Also, you can have permissions problems. But don't forget about logs! Use "tail -f var/logs/prod.log" to watch the logs, if there's an error - you'll see it there. So there're plenty of possible problems, but without seeing more specific errors it's difficult to help you. Try to find an error first and we'll help you to handle it.
P.S. We'll release a screencast which explains how to deploy Symfony apps properly: https://knpuniversity.com/s... . This way is much much more robust than one you have right now. Also, take a look at this checklist when deploy Symfony application: https://symfony.com/doc/cur...
Cheers!
Hi Victor,
Thank you for your help,
its really unclear steps for me, still can get how to deploy symfony applications which makes all the work i have done is useless so far.
I just wont to know when will you going to release a screencast about how to deploy Symfony apps.
I really like the way how you explain things in details.
Thank you
Mohamed
Hey Mohamed,
I'm working on this Ansistrano deploy tutorial right now, we're going to start releasing it after Webpack JS course which is releasing right now. I think it could be in the next month, maybe the end of this month. But we do not have more precise release date.
If you have some questions in particular during your deploy, i.e. if you have stuck on some step and can't move forward - you can ask your questions here and we'll try to help you in order you can move forward.
Cheers!
We also have a short screencast about deployment, check it out, I think it could be helpful for you:
https://knpuniversity.com/s...
Cheers!
"Houston: no signs of life"
Start the conversation!