PHP学习心得


homestead环境安装

<h2>windows+vagrant+homestead环境安装</h2> <ul> <li>参考网址</li> <li><a href="https://segmentfault.com/a/1190000005796157">https://segmentfault.com/a/1190000005796157</a></li> <li><a href="https://blog.csdn.net/xigedanganxi/article/details/88792746">https://blog.csdn.net/xigedanganxi/article/details/88792746</a></li> </ul> <h2>安装前提</h2> <ul> <li>安装软件顺序为Git,Vagrant,VirtualBox</li> <li>安装成功后,可以使用Git自带的“Git Bash”来执行软件命令</li> </ul> <h2>Vagrant安装</h2> <ul> <li> <p>是一个操作虚拟机的工具,基于Ruby的工具,用于创建和部署虚拟化开发环境</p> </li> <li> <p>下载地址</p> <ul> <li><a href="https://www.vagrantup.com/downloads">https://www.vagrantup.com/downloads</a></li> </ul> </li> <li> <p>安装目录</p> <ul> <li>D:\HashiCorp\Vagrant</li> </ul> </li> <li>查看版本</li> </ul> <pre><code class="language-bash"># 使用Git Bash终端查看,输入命令 vagrant --version vagrant # 直接查看有哪命令,如何使用相关命令帮助 # vagrant --version 不能执行,请设置环境变量 # vagrant设置环境变量路径为安装后的路径 D:\HashiCorp\Vagrant\bin</code></pre> <h2>VirtualBox安装</h2> <ul> <li> <p>下载地址</p> <ul> <li><a href="https://www.virtualbox.org/wiki/Downloads">https://www.virtualbox.org/wiki/Downloads</a></li> </ul> </li> <li> <p>安装目录</p> <ul> <li>D:\Program Files\Oracle\VirtualBox\</li> </ul> </li> </ul> <h2>安装homestead</h2> <h5>安装laravel/homestead盒子到vagrant中</h5> <pre><code class="language-bash"># 使用Git Bash终端查看,虚拟机名称为:laravel/homestead,输入命令 vagrant box add laravel/homestead # 此命令报错,请使用下边命令执行安装 vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead</code></pre> <h5>显示</h5> <pre><code class="language-bash">This box can work with multiple providers! The providers that itcan work with are listed below. Please review the list and choose the provider you will be working with. 1) hyperv 2) parallels 3) virtualbox Enter your choice: # 输入 3</code></pre> <h5>安装时间特别长,慢慢等待,大概需要10到20分钟</h5> <h5>安装成功显示</h5> <pre><code class="language-bash">==&gt; box: Adding box 'laravel/homestead' (v11.3.0) for provider: virtualbox box: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/11.3.0/providers/virtualbox.box box: box: Calculating and comparing box checksum... ==&gt; box: Successfully added box 'laravel/homestead' (v11.3.0) for 'virtualbox'!</code></pre> <h2>克隆已有的Homestead仓</h2> <pre><code class="language-bash">cd d: cd phpstudy_pro/WWW git clone https://github.com/laravel/homestead.git Homestead # 如果 git clone 不成功,使用手动下载代码,下载地址为 https://github.com/laravel/homestead/releases # 由于 Homestead 的 master 分支并不总是稳定的,使用打过标签的版本,选择版本为 v12.3.2 https://codeload.github.com/laravel/homestead/zip/refs/tags/v12.3.2 # 下载后为 homestead-12.3.2.zip,解压并重命名为homestead,复制到 D:\phpstudy_pro\WWW\ </code></pre> <h5>生成yaml文件</h5> <pre><code class="language-bash">cd d: cd phpstudy_pro/WWW # 进入到 homestead 目录中 cd homestead/ # 完整路径为 D:\phpstudy_pro\WWW\homestead # 生成yaml文件 bash init.sh # 原本目录下只有 Homestead.yaml.example 文件,现在多了一个 Homestead.yaml 文件</code></pre> <h5>Homestead.yaml 也可以手动复制,但要修改内容为</h5> <pre><code class="language-yaml">folders: - map: D:/phpstudy_pro/WWW/laravel8_test to: /home/vagrant/code sites: - map: laravel.homestead.test to: /home/vagrant/code/public databases: - homestead features: - mysql: true - mariadb: false - postgresql: false - ohmyzsh: false - webdriver: false</code></pre> <h5>配置ssh公钥</h5> <pre><code class="language-bash">ssh-keygen -t rsa -C "you@homestead" # 回车 Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/86136/.ssh/id_rsa): Enter passphrase (empty for no passphrase): # 回车 Enter same passphrase again: # 回车 Your identification has been saved in /c/Users/86136/.ssh/id_rsa. Your public key has been saved in /c/Users/86136/.ssh/id_rsa.pub. The key fingerprint is: SHA256:3P0UPfIA4RaSxnwTvfhW8Ei347qBWmHw1Nd9JZHmE4w you@homestead The key's randomart image is: +---[RSA 2048]----+ | o..=+ooo.| | =ooE+=++| | ...++*B+*| | . .=o oB*o| | S .+o +o.| | . o= . | | o..o | | o .. | | . .. | +----[SHA256]-----+</code></pre> <h2>vagrant虚拟机操作</h2> <pre><code class="language-bash">vagrant init vagrant up</code></pre> <h5>vagrant up出现报错</h5> <pre><code class="language-bash">报错部分显示信息为 Bringing machine 'default' up with 'virtualbox' provider... ==&gt; default: Box 'base' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: &gt;= 0 ==&gt; default: Box file was not detected as metadata. Adding it directly... ==&gt; default: Adding box 'base' (v0) for provider: virtualbox An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again. # 解决方法为 1-找到用户下 Vagrantfile 文件,如目录为: C:\Users\sinan 2-修改 Vagrantfile 文件,config.vm.box 修改为虚拟机的名称 config.vm.box = "laravel/homestead" 3-虚拟机的名称查看,vagrant box add 后边 laravel/homestead 就是虚拟机的名称 vagrant box add laravel/homestead</code></pre> <h5>修改host文件</h5> <pre><code class="language-bash"># host文件路径为 C:\Windows\System32\drivers\etc\hosts # 修改内容为 192.168.10.10 laraveltest.com</code></pre> <h5>运行 laravel 项目</h5> <pre><code class="language-bash"># 使用Git Bash终端查看,输入命令 cd d: cd phpstudy_pro/WWW/homestead # 链接(打开)虚拟机 vagrant ssh # 回车 # 显示内容,启动成功 Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-73-generic x86_64) _ _ _ | | | | | | | |__ ___ _ __ ___ ___ ___| |_ ___ __ _ __| | | '_ \ / _ \| '_ ` _ \ / _ \/ __| __/ _ \/ _` |/ _` | | | | | (_) | | | | | | __/\__ \ || __/ (_| | (_| | |_| |_|\___/|_| |_| |_|\___||___/\__\___|\__,_|\__,_| * Homestead v12.3.1 | Thanks for using Homestead * Settler v11.3.0 Last login: Fri Aug 6 03:52:09 2021 from 10.0.2.2 # 也可以通过界面化工具 Oracle VM VirtualBox 打开查看虚拟机是否启动 桌面,选择 Oracle VM VirtualBox 图标,双击打开,在界面左侧,就可以看到正在运行的虚拟机了</code></pre> <h5>访问 laravel 项目</h5> <pre><code class="language-bash"># 打开浏览器,地址输入配置host文件中配置的访问地址 laraveltest.com # 可以显示laravel页面</code></pre>

页面列表

ITEM_HTML