Homestead是一款官方开发环境,用于从零开始搭建本地开发服务器。它提供了一个简单的方法来设置和管理多个PHP项目,包括Homeassistant。通过Homestead,开发者可以轻松地在同一台机器上运行多个项目,而无需担心配置和依赖项的问题。Homestead还提供了一些额外的功能,如自动重启、数据库迁移和虚拟主机支持等,以帮助开发者更高效地进行开发工作。Homestead是一个非常实用的开发工具,适用于那些需要在本地环境中进行多项目开发的开发者。
本文目录导读:
Homestead是一个用于快速搭建本地开发服务器的工具,它可以帮助开发者在本地环境中运行PHP项目,同时提供了一个熟悉的命令行界面,让开发者能够更方便地进行配置和管理,本文将详细介绍如何从零开始搭建Homestead官方开发环境,包括安装依赖、创建虚拟环境和配置Homestead等步骤。
安装依赖
1、更新系统软件包
我们需要确保系统软件包是最新的,在终端中执行以下命令:
sudo apt-get update sudo apt-get upgrade
2、安装必要的软件包
我们需要安装一些必要的软件包,如Node.js、npm、Ruby、RubyGems等,在终端中执行以下命令:
sudo apt-get install curl build-essential libssl-dev libreadline-dev zlib1g-dev libyaml-dev git nodejs npm ruby-full rubygems bundler build-essential libsqlite3-dev node-gyp libv8-dev libxslt1-dev libcurl4-openssl-dev libxml2-dev libjpeg62-turbo-dev libpng-dev libtiff5-dev libgdbm-dev libncurses5-dev libmagickwand-dev libffi-dev liblzma-dev python-software-properties libpq5 libpq-dev unzip
创建虚拟环境
1、安装VirtualBox(可选)
Homestead需要VirtualBox来模拟虚拟机环境,如果你还没有安装VirtualBox,请先安装它,在终端中执行以下命令:
sudo apt-get install virtualbox
2、创建一个新的虚拟机镜像文件
我们需要创建一个新的虚拟机镜像文件,在终端中执行以下命令:
VBoxManage createvm --name homestead --register VBoxManage createmedium disk --filename "homestead.vda" --size 204800 --format vdi --variant Standard VBoxManage storageattach homestead --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "homestead.vda" --mediumpath "/home/vagrant/homestead.vdi" --writethrough || true VBoxManage storageattach homestead --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium none --cdrom "/home/vagrant/Vagrantfile.vmg" --mediumpath "/tmp/Vagrantfile.iso" || true VBoxManage modifyvm "homestead" --memory 1024 --cpus 2 --acpi on --boot1 dvd --nic1 nat VBoxManage modifyvm "homestead" --nic1 bridged VBoxManage modifyvm "homestead" --boot2 disk --boot2diskmode 'py2exe' VBoxManage modifyvm "homestead" --ostype linux_64 --accelerate3d on --video hvafb --hidpi on --vga 1280x1024x24orth --framebuffers on --usbgadget on --usbohci on --usbvideo on --usbpci on --audio usb audio --rtcclock offset 0x9C400000000 --audiocontroller ac97 VBoxManage modifyvm "homestead" --autostart on VBoxManage startvm "homestead" --type headless || true
3、将虚拟机镜像文件转换为VMDK格式(可选)
为了提高性能,我们可以将虚拟机镜像文件转换为VMDK格式,在终端中执行以下命令:
VBoxManage convertvm "homestead" --format VMDK 100% --output "/path/to/your/homestead.vmdk" || true
配置Homestead
1、下载并安装Vagrant和Homestead CLI工具
在终端中执行以下命令,下载并安装Vagrant和Homestead CLI工具:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - gpg:output:IDKEY=5a367efa7f5a2d9c3c5a3b3a6f7c3e8b3a8b3e9a7f5a2d9c3c5a3b3a6f7c3e8b > /dev/null && sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" && sudo apt-get update && sudo apt-get install vagrant hashicorp-vagrant box2dfs fswatch jq vagrant ui vagrant version || true && sudo gem install hashicorp-vagrant dotenv fswatch jq || true && mkdir ~/.homestead && echo "--- username: \"vagrant\" password: \"vagrant\" email: \"\" hostserver: \"http://localhost:8545\" " > ~/.homestead.yml && chmod +x ~/.homestead.yml && cp ~/.homestead.yml ~vagrant/configs/ && chown vagrant:vagrant configs/ && chmod +x configs/ && cat <<EOF > scripts/bootstrap.sh #!/bin/sh Set up the SSH key for the first time (if not done already) if [[ ! -f id_rsa_vagrant_linux_trusty_64bit ]]; then umask 077 mkdir ~/.ssh chmod go+rwx ~/.ssh cd ~/.ssh wget https://github.com/PowerShellGit/PowerShellGet/releases/download/v0.9.1/psget-0.9.1-win64.zip unzip psget* && cd PowerShellGet/ pwsh setup fi Add the SSH key to the Vagrant user account and set it as the default login method umask 077 nano ~/.ssh/authorized_keys echo \"Host *\ StrictHostKeyChecking no\ IdentitiesOnly yes\ RSAFile \\\"~/.ssh/id_rsa_vagrant_linux_trusty_64bit\\\"\\\" >> ~/.ssh/authorized_keys grep '^AuthorizedKeysFile' ~/.bashrc > /dev/null || echo 'AuthorizedKeysFile \\\\\"$HOME\\\\\\"/.ssh/authorized_keys' >> ~/.bashrc chmod go+rw $HOME/* >> ~/.bashrc source ~/.bashrc ok=$? err=\$? cd ~ || exit rmdir ~vagrant/ rmdir configs/ rm scripts/* exit $? EOF chmod +x scripts/* scp scripts/* ~vagrant:scripts/ EOF ssh vagrant@localhost <<EOF nano bootstrap.sh source configs/profiles/ export HOMEBREW_GITHUB_API_TOKEN=\"$(<$HOME/token)\" cd src/ npm init @babel/* npm install @babel/* npm install typescript react react-dom react-router-dom axios crypto jsdom jwt dotenv moment express socket io socketcluster superagent cors morgan winston bcryptjs body-parser dotenv express-session memory-cache passport passport-local passport-jwt localstrategy express-validator dotenv express helmet path@strict: false dotenv dotenv-data jsonwebtoken bcryptjs url bcryptjs dataloader lodash moment request jest prettier typescript jest @types/jest @types/node @types/react @types/react-dom @types/socket.io @types/jwt @types/dotenv ejs pug i18next i18next-browser-languagedetector i18nextXHRBackend i18nextHttpBackend i18nextPostProcessor i18nextSSRServer i18nextWebpackI18nextBrowserLanguageDetector i18nextLngDetector i18nextXHRBackend i18nextHttpBackend i18nextPostProcessor i18nextSSRServer i18nextWebpackI18nextBrowserLanguageDetector i18nextLngDetector react react-dom react-router reactredux redux reduxthunk axios socket io socketcluster cluster ws xhr fetch react-query react-intl i18next react