How to Setup Docker for Your Symfony Project

As you probably know, I am a big Symfony fan :) In the last few years I used Vagrant to set up my Symfony development environment more or less as described here. But we now have Docker and it’s time to move forward with a new setup. Docker containers are generally more lightweight than Vagrant virtual machines, so starting and stopping them is extremely fast. They also take a lot less disk……


How to Get Nearby Locations from MySQL Database

If you have a MySQL table with locations (latitude and longitude columns) you can get a list of locations near a specific point using the following query: [crayon-5f2a1a63de51b633165942/] In this query we have noted the latitude of the reference point with <latitude>, its longitude with <longitude> and the maximum distance to search for with <distance> (in kilometers). To make…


Symfony OAuth Authentication for Your Mobile Application

Let’s say you built an API using Symfony and you need to access it from a mobile application using authenticated requests on behalf of your users. Here’s how to make this work using Symfony 2.8 and Doctrine. Install FOSOAuthServerBundle We will use the FOSOAuthServerBundle to implement this feature. Install it using the following command: [crayon-5f2a1a63ded95105487569/] Next, enable the bundle…


tinyint, symfony, doctrine

How to add TINYINT MySQL type to Doctrine in Symfony 2.8

Hello! A few days ago I needed to define an entity with a TINYINT type column to hold a rating value between 1 and 5. I was doing this in a Symfony 2.8 project and to my surprise, Doctrine was unable to handle this type of data out of the box (it uses it for booleans but it has no TINYINT standalone type). So I searched the internet for a solution and I found some but nothing complete. The…


Setup Docker Machine for Symfony Development

If you need a development environment for Symfony, hosted by Docker, you can use the fazy/apache-symfony docker image to start with, then extend it to your need. In your Symfony project's folder add the Dockerfile and docker-compose.yml files. In the first one, we added mysql and composer, then we used the docker-compose.yml file to mount a local volume to the docker container with file sync.…


testing and fixtures

Setup Testing and Fixtures in Symfony2: The Easy Way

Setting up testing and fixtures in Symfony2 is vital if you plan on starting Test Driven Development or you simply want to start covering your code with properly written tests that can access mock data.   1. Install PHPUnit and php 5.6 The first thing you need to do is to install PHPUnit on your machine: [crayon-5f2a1a63e0d7a132334071/] and then, if needed, also upgrade your PHP version to…


How to monitor Symfony and Apache logs with M/Monit

So you have developed and deployed a fresh new project and you want to be alerted in case an error happens. Here's how you do it using the M/Monit tool. It can be installed on an Ubuntu machine using the following command: [crayon-5f2a1a63e1724390180597/] Now edit the /etc/monit/monitrc configuration file and add the following: [crayon-5f2a1a63e172d492754507/] First we need to tell M/Monit what…


send emails in symfony2

Send Emails in Symfony2: The Right Way

No matter what your app is about, at one you point you will have to send emails in Symfony2. Even though this process might seem straightforward and easy to apply, it can actually get pretty tricky. Here's how you can send emails in Symfony2 by properly splitting your functionality and templates.   1. Mailer parameters First off, you're going to need to add some email data into your…


APIs in Symfony2

Getting Started with Building APIs in Symfony2

Hello all you Interwebs friends! While we're passing through the shallow mists of time, REST is becoming more and more of a universal standard when building web applications. That said, here's a very brief tutorial on how to get started with building APIs in Symfony2. Spoiler alert: the bits of code written below use FosUserBundle + Doctrine. 1. Generate a New Bundle It's nice to keep your code…