This wouldn’t be much of a tutorial if we didn’t at least help show you how
to share your project with the world! There are a lot of neat deployment
tools out there and I’m sorry, we’re not going to show you any of them. At
least not in this screencast. Instead, we’ll go through the exact steps you’ll
need for deployment. If you want to automate them, awesome!

To keep things simple, I’m going to “deploy” to a different directory right
on my local machine. So, just pretend this is our server and I’ve already
ssh’ed into it.

First, we’ve gotta get the files up to the server! The easiest way is just
to clone your git repository right on the server. To do this, you’ll need
to push your code somewhere accessible, like GitHub. The finished code for
this tutorial already lives on GitHub, under a branch called episode4-finish.

Let’s clone this repository:

git clone

Move into the directory. If your code lives anywhere other than the master
branch, you’ll need to switch to that branch:

git checkout -b episode4-finish origin/episode4-finish

GitHub might ask you to authenticate yourself or give you some public key
error. If that happens, you’ll need to register the public key of your server
as a deploy key for your repository. This is what gives your server permission
to access the code.

Code, check! Next, let’s configure the web server. I’m using Apache, but
Symfony has a cookbook article about using Nginx. Find your Apache configuration
and add a new VirtualHost that points to the web/ directory of our project.
In our case, /var/www/knpevents.com/web:

<VirtualHost*:80>ServerName knpevents.com
DocumentRoot/var/www/knpevents.com/web<Directory/var/www/knpevents.com/web>Options Indexes FollowSymlinks
AllowOverrideAll# Use these 2 lines for Apache 2.3 and belowOrder allow,deny
allow from all# Use this line for Apache 2.4 and aboveRequireall granted
</Directory>ErrorLog/var/log/apache2/events_error.logCustomLog/var/log/apache2/events_access.log combined
</VirtualHost>

The VirtualHost is pretty simple and needs ServerName, DocumentRoot
and Directory keys.

Restart your webserver. For many servers, this is done by calling service
restart apache:

It’s alive! And with a big error, which might just show up as the white
screen of death on your server. Symfony can’t write to the cache directory.
We need to do a one-time chmod on it and the logs dir:

sudo chmod -R 777 app/cache/ app/logs/

Let’s try again. Ok, we have a site, and we can even login as Wayne.
But it’s missing all the styles. Ah, right, dump the assetic assets:

php app/console assetic:dump --env=prod

Crap! Scroll up. This failed when trying to run uglifycss. I don’t
have Uglifycss installed on this machine yet. To get ugly Just run
npminstall to fix this.

One more thing. There are a few really easy wins to maximize
Symfony’s performance.

First, when you deploy, dump Composer’s optimized autoloader:

php composer.phar dump-autoload --optimize

This helps Composer’s autoloader find classes faster, sometimes much faster.
And hey, there’s no downside at all to this!

Tip

If you add the –optimize-autoloader flag, Composer will generate a
class map, which will give your whole application a performance boost.
Using the APC ClassLoader may give you an even bigger boost.

Next, make sure you have a byte code cache installed on your server. For PHP 5.4
and earlier, this was called APC. For 5.5 and later, it’s called OPcache.
In the background, these cache the compiled PHP files, making your site
much faster. Again, there’s no downside here - make sure you have one of
these on your server.

And on that note, PHP typically gets faster from version to version. So staying
on the latest version is good for more than just security and features. Thanks
PHPeeps!

Ok, that’s it! Now google around for some deployment tools to automate this!

Leave a comment!

2018-09-24Diego Aguiar

You're welcome :)

2018-09-21Christophe Lablancherie

Oh god ok ! I thought it was obvious to put "true" on the kernel when we go to prod.

Thanks !

2018-09-21Diego Aguiar

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!

2018-09-21Christophe Lablancherie

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 :/

// 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);

2018-09-21Diego Aguiar

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');

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/404 where "404" is the code of the error

Cheers!

2018-09-21Christophe Lablancherie

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....

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!

2017-09-06Mohamed

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

2017-08-09Victor Bocharsky

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.

Hi Guys,Thank you for your help,just i'm trying to upload small project i'm working on right nowI 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 workedi believe maybe there is some thing i should have done before uploading .please if possible help with the deployment steps

many thanks

Mohamed

2015-06-15Theravadan

Thank you very much. it all makes sense.

2015-06-12weaverryan

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!

2015-06-10Theravadan

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?