Using Symfony with Homestead/Vagrant

In order to develop a Symfony application, you might want to use a virtual development environment instead of the built-in server or WAMP/LAMP. Homestead is an easy-to-use Vagrant box to get a virtual environment up and running quickly.

Symfony アプリケーションを開発するために、組み込みサーバーや WAMP/LAMP の代わりに仮想開発環境を使用したい場合があります。 Homestead は、仮想環境をすばやく起動して実行するための使いやすい Vagrant ボックスです。

Tip

ヒント

Due to the amount of filesystem operations in Symfony (e.g. updating cache files and writing to log files), Symfony can slow down significantly. To improve the speed, consider overriding the cache and log directories to a location outside the NFS share (for instance, by using sys_get_temp_dir). You can read this blog post for more tips to speed up Symfony on Vagrant.

Symfony のファイルシステム操作 (キャッシュファイルの更新やログファイルへの書き込みなど) の量が原因で、Symfony は大幅に遅くなる可能性があります。速度を向上させるには、キャッシュおよびログ ディレクトリを NFS 共有外の場所に上書きすることを検討してください (たとえば、sys_get_temp_dir を使用して)。 Vagrant で Symfony を高速化するためのその他のヒントについては、このブログ投稿を参照してください。

Install Vagrant and Homestead

Before you can use Homestead, you need to install and configure Vagrant and Homestead as explained in the Homestead documentation.

Homestead を使用する前に、Homestead のドキュメントで説明されているように、Vagrant と Homestead をインストールして構成する必要があります。

Setting Up a Symfony Application

Imagine you've installed your Symfony application in ~/projects/symfony_demo on your local system. You first need Homestead to sync your files in this project. Run homestead edit to edit the Homestead configuration and configure the ~/projects directory:

Symfony アプリケーションをローカル システムの ~/projects/symfony_demo にインストールしたと想像してください。このプロジェクトでファイルを同期するには、最初に Homestead が必要です。 homestead edit を実行して、Homestead 構成を編集し、~/projects ディレクトリを構成します。
1
2
3
4
# ...
folders:
    - map: ~/projects
      to: /home/vagrant/projects

The projects/ directory on your PC is now accessible at /home/vagrant/projects in the Homestead environment.

PC の projects/ ディレクトリは、Homestead 環境の /home/vagrant/projects でアクセスできるようになりました。

After you've done this, configure the Symfony application in the Homestead configuration:

これを行った後、Homestead 構成で Symfony アプリケーションを構成します。
1
2
3
4
5
# ...
sites:
    - map: symfony-demo.test
      to: /home/vagrant/projects/symfony_demo/public
      type: symfony4

The type option tells Homestead to use the Symfony nginx configuration. Homestead now supports a Symfony 2 and 3 web layout with app.php and app_dev.php when using type symfony2 and an index.php layout when using type symfony4.

type オプションは、Homestead に Symfony nginx 構成を使用するように指示します。Homestead は、symfony2 型を使用する場合は app.php および app_dev.php を使用する Symfony 2 および 3 の Web レイアウトをサポートし、symfony4 型を使用する場合は index.php レイアウトをサポートするようになりました。

At last, edit the hosts file on your local machine to map symfony-demo.test to 192.168.10.10 (which is the IP used by Homestead):

最後に、ローカル マシンのホスト ファイルを編集して、symfony-demo.test を 192.168.10.10 (Homestead が使用する IP) にマップします。
1
2
# /etc/hosts (unix) or C:\Windows\System32\drivers\etc\hosts (Windows)
192.168.10.10 symfony-demo.test

Now, navigate to http://symfony-demo.test in your web browser and enjoy developing your Symfony application!

それでは、Web ブラウザで http://symfony-demo.test に移動して、Symfony アプリケーションの開発を楽しんでください!

See also

こちらもご覧ください

To learn more features of Homestead, including Blackfire Profiler integration, automatic creation of MySQL databases and more, read the Daily Usage section of the Homestead documentation.

Blackfire Profiler の統合、MySQL データベースの自動作成など、Homestead の機能の詳細については、Homestead ドキュメントの「Daily Usage」セクションを参照してください。