|
| 1 | +.. index:: Vagrant, Homestead |
| 2 | + |
| 3 | +Using Symfony with Homestead/Vagrant |
| 4 | +==================================== |
| 5 | + |
| 6 | +In order to develop a Symfony application, you might want to use a virtual |
| 7 | +development environment instead of the built-in server or WAMP/LAMP. Homestead_ |
| 8 | +is an easy-to-use Vagrant_ box to get a virtual environment up and running |
| 9 | +quickly. |
| 10 | + |
| 11 | +.. tip:: |
| 12 | + |
| 13 | + Due to the amount of filesystem operations in Symfony (e.g. updating cache |
| 14 | + files and writing to log files), Symfony can slow down signifcantly. To |
| 15 | + improve the speed, consider :ref:`overriding the cache and log directories <override-cache-dir>` |
| 16 | + to a location outside the NFS share (for instance, by using |
| 17 | + :phpfunction:`sys_get_temp_dir`). You can read `this blog post`_ for more |
| 18 | + tips to speed up Symfony on Vagrant. |
| 19 | + |
| 20 | +Install Vagrant and Homestead |
| 21 | +----------------------------- |
| 22 | + |
| 23 | +Before you can use Homestead, you need to install and configure Vagrant and |
| 24 | +Homestead as explained in `the Homestead documentation`_. |
| 25 | + |
| 26 | +Setting Up a Symfony Application |
| 27 | +-------------------------------- |
| 28 | + |
| 29 | +Imagine you've installed your Symfony application in |
| 30 | +``~/projects/symfony_demo`` on your local system. You first need Homestead to |
| 31 | +sync your files in this project. Execute ``homestead edit`` to edit the |
| 32 | +Homestead configuration and configure the ``~/projects`` directory: |
| 33 | + |
| 34 | +.. code-block:: yaml |
| 35 | +
|
| 36 | + # ... |
| 37 | + folders: |
| 38 | + - map: ~/projects |
| 39 | + to: /home/vagrant/projects |
| 40 | +
|
| 41 | +The ``projects/`` directory on your PC is now accessible at |
| 42 | +``/home/vagrant/projects`` in the Homestead environment. |
| 43 | + |
| 44 | +After you've done this, configure the Symfony application in the Homestead |
| 45 | +configuration: |
| 46 | + |
| 47 | +.. code-block:: yaml |
| 48 | +
|
| 49 | + # ... |
| 50 | + sites: |
| 51 | + - map: symfony-demo.dev |
| 52 | + to: /home/vagrant/projects/symfony_demo/web |
| 53 | + type: symfony |
| 54 | +
|
| 55 | +The ``type`` option tells Homestead to use the Symfony nginx configuration. |
| 56 | + |
| 57 | +At last, edit the hosts file on your local machine to map ``symfony-demo.dev`` |
| 58 | +to ``192.168.10.10`` (which is the IP used by Homestead):: |
| 59 | + |
| 60 | + # /etc/hosts (unix) or C:\Windows\System32\drivers\etc\hosts (Windows) |
| 61 | + 192.168.10.10 symfony-demo.dev |
| 62 | + |
| 63 | +Now, navigate to ``http://symfony-demo.dev`` in your web browser and enjoy |
| 64 | +developing your Symfony application! |
| 65 | + |
| 66 | +.. seealso:: |
| 67 | + |
| 68 | + To learn more features of Homestead, including Blackfire Profiler |
| 69 | + integration, automatic creation of MySQL databases and more, read the |
| 70 | + `Daily Usage`_ section of the Homestead documentation. |
| 71 | + |
| 72 | +.. _Homestead: http://laravel.com/docs/homestead |
| 73 | +.. _Vagrant: https://www.vagrantup.com/ |
| 74 | +.. _the Homestead documentation: http://laravel.com/docs/homestead#installation-and-setup |
| 75 | +.. _Daily Usage: http://laravel.com/docs/5.1/homestead#daily-usage |
| 76 | +.. _this blog post: http://www.whitewashing.de/2013/08/19/speedup_symfony2_on_vagrant_boxes.html |
0 commit comments