In this video we will use Ansible to build ourselves a Symfony development server running on nginx.
The nice thing about using Ansible for this process is that it allows you to spin up a brand new, fully working Symfony development environment in a matter of minutes, which in turn allows you to get immediately focussed on the important part - development, instead of the usual time consuming part - operations.
You may be wondering why bother with a tool like Ansible for this process, when you are already more than capable of setting up an nginx server, uploading your Symfony site, and so on.
It's a good question - and having that knowledge is certainly very valuable.
For me, it is really all about saving time. Once you have built and deployed an nginx server, uploaded your Symfony files, set up the relevant directory permissions, and of course, debugged the whole set up because things never work perfectly the first time... well if you can bypass that every subsequent time in the future, then in my opinion, you would be crazy not too.
The other big point for me is that before this, I would work in quite a similar fashion. I would build a server manually, install nginx and MySQL, then power down the machine, and clone it for future projects.
Whenever I needed a new Symfony box, I would clone that base image, boot it up, customise it and crack on. But that was still more effort than I would have liked. And it still meant images diverged over time. There was no standardisation, or living documentation.
Ansible has changed all that.
Whilst Apache is great for a development environment, I can say from bitter experience that as your web site grows, should you be lucky enough to gather a sizeable volume of traffic then you are inevitably going to hit problems.
To mitigate that, it is better to switch to nginx early, even if you are far more comfortable currently with Apache.
And the good news with using nginx through Ansible is that you can read through the exact process ahead of time, and / or refer back to the exact task list used to build your nginx environment.
As mentioned in the video, the nginx role I use is a customisation on the nginx role from Chris Fidao's Servers for Hackers ansible-nginx role, and also from the book of the same name (highly recommended reading for any developer who is also interested in servers).
You can find all the code for the Ansible Nginx and Symfony roles on the CodeReview GitHub account.
Update: this bug is now fixed. I had forgotten to also remove the
default site from
sites-available. I also added in a call to the
Restart Nginx handler at the last step in the
One issue I keep running in to with this set up is that the Default site (
/etc/nginx/sites-enabled/default) won't properly remove. This, in turn, will cause your Symfony site not to load.
The solution here is to log in to your built Symfony development server and manually remove this file (
rm /etc/nginx/sites-enable/default) and that problem should go away.
You will also need to restart the nginx server:
sudo service nginx restart
If you have found this video helpful, please consider sharing. I really appreciate it.
|1||How To Install Ubuntu Server in Oracle VirtualBox||10:21|
|2||How to Rename our Ubuntu Server||02:00|
|3||Installing Ansible on Ubuntu Server||00:33|
|4||Safety First, Safety Second - Snapshots are like Ctrl+Z||00:11|
|5||Managing the Ansible Inventory Hosts File||02:16|
|6||Ansible Ad Hoc Commands||04:27|
|7||Introduction to Ansible Playbooks||02:14|
|10||Git Your Deploy Just Right||05:34|
|12||Looping in Ansible with_items||04:34|
|13||Ansible Files For Beginners||06:14|
|14||Variable Precedence - Where To Put Your Role Vars?||04:13|
|16||Ansible Inventory With Our Own Hosts Files||06:57|
|17||How to Manage Users with Ansible||08:32|
|18||Ansible Vault Tutorial||03:48|
|19||Ansible Galaxy Tutorial||10:03|
|20||Real World Ansible - Common Role Walkthrough||06:19|
|21||Ansible MySQL Tutorial||13:44|
|22||Ansible Symfony and nginx||09:37|