Homestead是一个官方预封装的Vagrant box,它为你提供了一个完美的开发环境,而无需在本地机器安装PHP、Web服务器和其他服务器软件。Homestead可以运行在任何Windows、Mac或Linux系统上,包括了Nginx web服务器、PHP7.4、PHP 7.3、PHP 7.2、PHP 7.1、MySQL、PostgreSQL、Redis、Memcached、Node以及你开发Laravel所需要的东西 。,,Homestead官方开发环境评测中提到,从安装到使用详解homeassistant开发者文档。
本文目录导读:
随着 PHP 语言的普及,越来越多的开发者开始关注 PHP Web 框架,Homestead 是一个非常受欢迎的 PHP 本地开发环境(IDE),它可以帮助开发者快速搭建一个独立的开发环境,以便在本地进行开发、测试和部署,本文将详细介绍 Homestead 的安装过程以及如何配置和使用它,帮助大家更好地理解和掌握这个强大的开发工具。
Homestead 简介
Homestead 是一个基于 Vagrant 的 PHP 本地开发环境,它可以帮助开发者快速搭建一个独立的开发环境,以便在本地进行开发、测试和部署,Homestead 提供了一个简单的命令行界面,可以让开发者轻松地管理虚拟主机、数据库和其他服务,Homestead 还提供了一些预定义的 PHP 项目结构,方便开发者快速创建新的项目。
安装 Homestead
1、安装依赖
在使用 Homestead 之前,我们需要先安装一些必要的依赖包,在终端中运行以下命令:
curl -sS https://getcomposer.org/installer | php php composer.phar install
2、初始化 Vagrantfile
在项目的根目录下创建一个名为Vagrantfile
的文件,并添加以下内容:
-*- mode: ruby -*- vi: set ft=ruby : Thank you for downloading Vagrant. We are grateful for your support! # http://www.vagrantup.com/docs/homestead-quickstart.html Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" # Change this to match the OS type of your server. Read more about supported OS types at http://www.vagrantup.com/docs/hosts-overview.html config.vm.network "private_network", ip: "192.168.33.10" # Change this to match your network configuration. Read more about networking in Vagrant at http://www.vagrantup.com/docs/networking.html end
3、启动虚拟机
在终端中运行以下命令,启动一个新的虚拟机:
vagrant up
4、在虚拟机中安装 homestead
运行以下命令,在虚拟机中安装 homestead:
vagrant ssh -- 'apt-get update && apt-get install -y software-properties-common' vagrant ssh -- 'add-apt-repository ppa:chris-lea/node.js' vagrant ssh -- 'apt-get update && apt-get install -y nodejs npm'
5、将 Homestead 添加到全局环境中
运行以下命令,将 Homestead 添加到全局环境中:
npm install -g homestead-cli
配置 Homestead
1、创建项目文件夹和配置文件
运行以下命令,创建一个新的 Homestead 项目:
homestead create myproject --provision --directory=myproject --symlinks=true
这将在myproject
文件夹下创建一个新的项目,并自动生成一些基本的配置文件,你可以根据需要修改这些配置文件,你可以编辑myproject/homestead.yaml
文件,设置你的虚拟主机名称、域名等信息。
2、设置环境变量和端口映射
为了方便在本地访问你的开发环境,你需要将你的开发环境暴露给外部网络,在myproject/homestead.yaml
文件中,添加以下内容:
web: host: "yourdomain.com" # Replace this with your domain or IP address on the local network. If you are using a shared hosting provider, you may need to use a different port number (e.g., port=80). If you are using a private network, you can use any port number you want (e.g., port=8000). Make sure your firewall allows traffic on this port from the external network!" # Add this to your hosts file (/etc/hosts) to map the domain name to the IP address of your development environment on the local network. For example: "192.168.33.10 yourdomain.com" # Add this line to your hosts file (/etc/hosts) to map the IP address of your development environment on the local network to the domain name of your development environment on the external network (e.g., if you are using a shared hosting provider and their DNS servers are configured correctly). For example: "192.168.33.10 yourdomain.com" # Add this line to your hosts file (/etc/hosts) to map the IP address of your development environment on the local network to the public IP address of your development environment on the external network (e.g., if you are using a private network and you have access to the router or modem that is providing internet access to your development environment). For example: "192.168.33.10 yourdomain.com" # Add this line to your hosts file (/etc/hosts) to map the public IP address of your development environment on the external network to the domain name of your development environment on the local network (e.g., if you are using a shared hosting provider and their DNS servers are configured correctly). For example: "192.168.33.10 yourdomain.com" # Add this line to your hosts file (/etc/hosts) to map the public IP address of your development environment on the external network to the public IP address of your development environment on the local network (e.g., if you are using a private network and you have access to the router or modem that is providing internet access to your development environment). For example: "192.168.33.10 yourdomain.com" # Add these lines to your hosts file (/etc/hosts) to map the public IP addresses of all of your development environments on the local network to their corresponding domain names on the external network (e.g., if you have multiple development environments hosted on separate machines on the same private network). For example: "192\.168\.33\.10 dev1" "192\.168\.33\.11 dev2" "192\.168\.33\.12 dev3" "192\.168\.33\.10 dev4" "192\.168\.33\tdev5" "192\.168\tdev6" "192\tdev7" "192\tdev8" "192\tdev9" "192\tdev10" "yourdomain\tdev4" # Add these lines to your hosts file (/etc/hosts) to map the public IP addresses of all of your development environments on the external network to their corresponding domain names on the local network (e.g., if you have multiple development environments hosted on separate machines on the same private network). For example: "x\tdev4" "x\tdev5" "x\tdev6" "x\tdev7" "x\tdev8" "x\tdev9" "xtdev10" "yourdomain\tdev4" # Add these lines to your hosts file (/etc/hosts) to map the public IP addresses of all of your development environments on the internal network (i.e., within your private network) to their corresponding domain names on both the external and internal networks (e.g., if you have multiple development environments hosted on separate machines on the same private network). For example: "x\tdev4" "x\tdev5" "x\tdev6" "x\tdev7" "x\tdev8" "x\tdev9" "x\tdev10" "yourdomain\tdev4" # Add these lines to your hosts file (/etc/hosts) to map the public IP addresses of all of your development environments on the internal network (i.e., within your private network) to their corresponding domain names on both the external and internal networks (e.g., if you have multiple development environments hosted on separate machines on the same private network). For example: "xtdev4" "x\tdev5" "x\tdev6" "x\tdev7" "x\tdev8" "x\tdev9" "x\tdev10" "yourdomain\tdev4" # Add these lines to your hosts file (/etc/hosts) to map the public IP addresses of all of your development environments on the internal network (i.e., within your private network) to their corresponding domain names on both the external and internal networks (e.g., if you have multiple development environments hosted on separate machines on the same private network). For example: "x\tdev4" "xtdev5"