未加星标

Using Laravel Homestead with Zend Framework Projects

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

2017-02-07 | By: Enrico Zimuel

Laravel Homestead is an interesting project by the Laravel community that provides a Vagrant box forphp developers. It includes a full set of services for PHP developers, such as the Nginx web server, PHP 7.1, mysql, Postgres, Redis, Memcached, Node, and more.

One the most interesting features of this project is the ability to enable it per project. This means you can run a vagrant box for your specific PHP project.

In this post, we'll examine using it for Zend Framework MVC, Expressive, and Apigility projects. In each case, installation and usage is exactly the same.

Install the Vagrant box

The first step is to install the laravel/homestead vagrant box. This box works with a variety of providers: VirtualBox 5.1 , VMWare , or Parallels .

We used VirtualBox and the following command to install the laravel/homestead box:

$ vagrant box add laravel/homestead

The box is 981 MB, so it will take some minutes to download.

Homestead, by default, uses the host name homestead.app , and requires that you update your system hosts file to point that domain to the virtual machine IP address. To faciliate that, Homestead provides integration with the vagrant-hostsupdater Vagrant plugin. We recommend installing that before your initial run of the virtual machine:

$ vagrant plugin install vagrant-hostsupdater Use Homestead in ZF projects

Once you have installed the laravel/homestead vagrant box, you can use it globally or per project.

If we install Homestead per-project, we will have a full development server configured directly in the local folder, without sharing services with other projects. This is a big plus!

To use Homestead per-project, we need to install the laravel/homestead package within our Zend Framework, Apigility, or Expressive project. This can be done using Composer with the following command:

$ composer require --dev laravel/homestead

After installation, execute the homestead command to build the Vagrantfile :

$ vendor/bin/homestead make

This command creates both the VagrantFile and a Homestead.yaml configuration file.

Configuring Homestead By default, the vagrant box is set up at address 192.168.10.10 with the hostname homestead.app . You can change the IP address in Homestead.yaml if you want, as well as the hostname (via the sites[].map key).

The Homestead.yaml configuration file contains all details about the vagrant box configuration. The following is an example:

--- ip: "192.168.10.10" memory: 2048 cpus: 1 hostname: expressive-homestead name: expressive-homestead provider: virtualbox authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa folders: - map: "/home/enrico/expressive-homestead" to: "/home/vagrant/expressive-homestead" sites: - map: homestead.app to: "/home/vagrant/expressive-homestead/public" databases: - homestead

This configuration file is very simple and intuitive; for instance, the folders to be used are reported in the folders section; the map value is the local folder of the project, the to value is the folder on the virtual machine.

If you want to add or change more features in the virtual machine you can used the Homestead.yaml configuration file. For instance, if you prefer to add MariaDB instead of MySQL, you need to add the mariadb option:

ip: "192.168.10.10" memory: 2048 cpus: 1 hostname: expressive-homestead name: expressive-homestead provider: virtualbox mariadb: true

This option will remove MySQL and install MariaDB.

SSH keys managed by GPG

One of our team uses the gpg-agent as an ssh-agent, which caused some configuration problems initially, as the ~/.ssh/id_rsa and its .pub sibling were not present.

When using gpg-agent for serving SSH keys, you can export the key using ssh-add -L . This may list several keys, but you should be able to find the correct one. Copy it to the file ~/.ssh/gpg_key.pub , and then copy that file to ~/.ssh/gpg_key.pub.pub . Update the Homestead.yaml file to reflect these new files:

authorize: ~/.ssh/gpg_key.pub.pub keys: - ~/.ssh/gpg_key.pub

The gpg-agent will take care of sending the appropriate key from there.

Running Homestead

To run the vagrant box, execute the following within your project root:

$ vagrant up

If you open a browser to http://homestead.app you should now see your application running.

Manually managing your hosts file

If you chose not to use vagrant-hostsupdater, you will need to update your system hosts file.

On linux and Mac, update the /etc/hosts file to add the following line:

192.168.10.10 homestead.app

On windows, the host file is located in C:\Windows\System32\drivers\etc\hosts .

More information

We've tested this setup with each of the Zend Framework zend-mvc skeleton application, Apigility, and Expressive, and found the setup "just worked"! We feel it provides excellent flexibility in setting up development environments, giving developers a wide range of tools and technologies to work with as they develop applications.

For more information about Laravel Homestead, visit the official documentation of the project.

SHARE:

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

主题: LaravelPHPSQLMySQLWindowsLinuxMemcachedNginxRedis
分页:12
转载请注明
本文标题:Using Laravel Homestead with Zend Framework Projects
本站链接:http://www.codesec.net/view/531639.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(39)