Creating a bootstrap Symfony project

By bootstrapping a Symfony project I am referring to creating a ready-to-go basic software package from which to build any projects from.  This also does include Twitter’s awesome Bootstrap libraries as well.

New project requires a well-designed database first

The first thing I usually do with a new Symfony project is design the database.  I use Oracle’s free tool called MySQL Workbench.  Here is a screenshot of a basic database design.  Once I go through the database and document how it will work, I then migrate the table model to the database where it creates the actual tables.

While it may take days to design the database first, this is by far the most critical step because your Symfony project, like most websites, depends on the database to perform properly.

Copying an existing Symfony project or phase of project or start from scratch?

So while this is going on I then would set up a new instance of Symfony on the website.  For first-timers, you need to do it a few times and get used to being able to have the framework’s tools write a bunch of code already for you!  Simply follow the instructions in the Cookbook on Sensio Lab’s Symfony website — a newest feature now is the Symfony installer which you will now need to install first before executing the few other command line prompts.

It’s fast and easy and all the Symfony files will be loaded on your website in the standard folder structure ready to go.  You can move folders around later and if you already did this on a local dev, you can just copy the entire folder to another site.  As an alternative, before you dev’d that project, you could use the .git repository and use the first commit as your bootstrap as well and simply check out those files from the repository.

There are many ways to deploy Symfony and since Symfony’s meant to be modular, Sensio claims it’s flexible and easy to deploy and I find it is most the time.

Essentially any already deployed Symfony project can serve as your next bootstrapped project.  Just don’t copy over anything dealing with “cache” folders or “cache” in the file names.

During initial Symfony set ups, depending on your host and server machine on occasion I would run into some file permission issues or directives in the php.ini or .htaccess files that are prohibited with certain hosts, but this is the exception and not the rule.

Composer – get to know your new friend

You’re not going to get very far if you don’t learn Composer.  It’s pretty easy how it works but it helps you keep all your software dependencies in line so things don’t break later.  Composer is your friend so take 10 minutes and learn up on what it is and does!

In case you were wondering, you can install it on your server through the command line, it’s usually better if you are logged in as the root user:

Bootstrapping your Bootstrap Symfony Project

Besides the FOSUserBundle, which now looks like it comes with the newest Symfony package, I usually install Braincrafted’s Bootstrap Bundle automatically since I use it for so many projects.  You can always not use a bundle from a vendor, but it’s usually a foregone conclusion I will be needing it.  So follow the instructions how to install the Bootstrap Bundle or simply go to your Symfony folder and add these three requirements to your composer.json file:

By the way, jQuery’s pretty common and works well with Bootstrap themes, so you need to throw this into the composer.json file after your “requires” list:

Then on the command line update all your Composer dependencies by typing in:

It also just updated my Symfony from 2.6.3 to 2.6.9, so I’m curious if I’ll run into any issues.  You’ll know if you do usually right away you will see 500 errors blowing up or blank pages (yikes) and what you need to do is Google frantically or roll back version in your composer.json file until the errors go away.  Lesson here?

Never ever ever run Composer updates on a live site, always do it on a staging server and test it, then test it again, then ask end users to test your staging again before going live!

Everytime you update your Composer dependencies, you must CLEAR YOUR SYMFONY CACHE!

Do save yourself the frustration and navigate to your Symfony install on your site, usually inside “public_html” and automatically type in  “app/console  ca:cl”  then “app/console ca:cl –env” in that order on your server.  This will clear the cache, sometimes it doesn’t make sense, but do it.  This is just the abbreviated commands for “cache:clear”.

Commit your Barebones Symfony so you have a snapshot

Now, since you’re using a local computer as a dev server and hopefully not the one you’re coding on because running VM on the same machine is asking for performance frustration later — you can just grab the entire site, pull it down, it’ll take 3 minutes.  I use PHP Storm for my IDE and already have it connected to my BitBucket account so after grabbing it all, I commit it and push the code to BitBucket and mark it with “INITIAL COMMIT” and I usually leave a note like “Bootstrap template” so I know it’s a quick way I can have Symfony-ready site to dev later.

Need help?  Feel free to contact me!

 

– Aaron Belchamber

www.AaronBelchamber.com

 

Aaron Belchamber has written 243 articles

Leave a Reply

Your email address will not be published. Required fields are marked *