search
HomePHP FrameworkLaravelLaravel local environment construction: Deployment of Homestead development environment

Laravel框架在php开发过程是不断进行优化的,当然也包括了本地环境的开发,下面我们就来具体看看laravel框架中的Homestead 开发环境的部署内容。

首先白以下几个概念

  • VirtualBox -- Oracle 公司的虚拟机软件, 能运行在当前大部分流行的系统上;

  • Vagrant 提供一种命令行接口, 允许自动化安装虚拟机, 并且因为是脚本编写成的 provision 文本文件, 给共享虚拟机配置提供了可能, Homestead 正是构建在 Vagrant 之上;

  • Laravel Homestead 是官方预封装的一个 Vagrant Box,它是一台虚拟机的原型, 用来快速生产一个配置完整的服务器虚拟机, 运行在 VirtualBox 上.

Homestead 生产出来的虚拟机提供了一个完整的开发环境, 有了这个环境, 就不用再担心各种软件的设置会搞乱你的操作系统啦.

因为是虚拟机, 出现故障的时候, 可以在几分种内完成销毁和重建.

Homestead 能运行在所有的Windows、Mac和Linux上,它包含了Nginx、PHP 5.5、MySQL、Postgres、Redis、Memcached和你开发 Laravel应用程序需要的所有其它软件。

在多人协同开的情况下, Homestead 能用来统一开发环境, 让程序员把精力更集中的放在程序业务逻辑上, 免去了各种因为开发环境不一样而造成的混乱.

约定

假设我们要开发一个项目, 项目的名字叫 mytwitter.

首先在我们存放代码的地方 code 文件夹里面创建项目根文件夹 mytwitter_project, 接下来咱们的操作都在此项目下进行

cd ~/codemkdir mytwitter_project
cd mytwitter_project

安装 virtualbox 和 vagrant

在这里下载并安装 VirtualBox , Vagrant .

直接下载 GUI 安装包安装就行.

下载并配置 Homestead

Homestead 包括以下两个东西

  1. 一个 vagrant box 虚拟机, 里面软件什么都下载好了;

  2. Github 代码库, 里面装载着 vagrant 的配置脚本, 用来自动化配置网络, 端口映射, 等一些开发时候用到的配置

克隆 homestead 项目

在文件夹下克隆 homestead 项目到本地

git clone https://github.com/laravel/homestead.git Homestead

加入 homestead box

执行以下命令添加 box

vagrant box add laravel/homestead

在线下载会很慢一般用迅

可以下载最新的box文件

https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.5.0  //新版本地址

下载后执行以下命令, 修改 /path/to/virtualbox.box 为正确的 path.

vagrant box add laravel/homestead /path/to/virtualbox.box

windows中执行如下命令

vagrant box add laravel/homestead file:///D:/download/virtubox.box

修改 homestead 的配置

根据你的情况修改 Homestead 项目里面文件 Homestead.yaml , 类似以下

---ip: "192.168.10.10"memory: 2048cpus: 1authorize: /Users/me/.ssh/id_rsa.pub

keys:    - /Users/me/.ssh/id_rsa

folders:    - map: /Users/me/code/mytwitter_project/mytwitter
      to: /home/vagrant/mytwitter

sites:    - map: mytwitter.app
      to: /home/vagrant/mytwitter/public

variables:    - key: APP_ENV
      value: local

配置 hosts 文件

 修改本机的 hosts 文件, 允许通过自定义域名访问, 这个域名是在上面的 Homestead.yaml 里面设置的.

sudo vi /etc/hosts

添加以下一行

127.0.0.1    mytwitter.app

初始化 homestead 虚拟机

cd Homestead
vagrant up 
注意:要删除homestead目录下的 Vagrantfile 文件重新生成使用命令:vagrant init生成。
然后在启动
vagrant u

生成启动后看提示信息。

最后测试是否能成功连接, 虚拟机里的 ~/mytwitter 文件夹里的文件和本地的文件是一致的.

vagrant ssh cd ~/mytwitter
ll

浏览器访问 http://mytwitter.app:8000/ .

至此, 成功安装.

以上就是本篇文章的全部内容了,更多请关注laravel框架入门教程

相关文章推荐:

基于laravel5.2进行中间件源码的解析

laravel5.4中自定义包开发的实例

相关课程推荐:

laravel基础开发宝典视频教程

2017年最新的五个Laravel视频教程推荐

The above is the detailed content of Laravel local environment construction: Deployment of Homestead development environment. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Tech Troubles: Ensuring Equitable Access to Tools and Resources for Distributed Team MembersTech Troubles: Ensuring Equitable Access to Tools and Resources for Distributed Team MembersApr 29, 2025 am 12:40 AM

Methods to ensure that distributed team members have fair access to tools and resources include: 1) using low-bandwidth alternatives, such as asynchronous video or text updates, to solve connection problems; 2) setting up core overlapping working hours and providing flexible working hours to manage time zone differences; 3) adapt to different cultural needs through translation functions and cultural awareness training. These strategies help create an inclusive and efficient remote working environment.

Instant Messaging Must-Haves: Fostering Real-Time Communication in Remote SettingsInstant Messaging Must-Haves: Fostering Real-Time Communication in Remote SettingsApr 29, 2025 am 12:38 AM

Forenhancingremotecollaboration,aninstantmessagingtoolmusthave:1)reliabilityforconsistentmessagedelivery,2)anintuitiveuserinterfaceforeasynavigation,3)real-timenotificationstostayupdated,4)seamlessfilesharingforefficientdocumentexchange,5)integration

Have you ever faced any challenges while working in distributed teams?Have you ever faced any challenges while working in distributed teams?Apr 29, 2025 am 12:35 AM

Thebiggestchallengeofmanagingdistributedteamsiscommunication.Toaddressthis,usetoolslikeSlack,Zoom,andGitHub;setclearexpectations;fostertrustandautonomy;implementasynchronousworkpatterns;andintegratetaskmanagementwithcommunicationplatformsforefficient

What are the security improvements in the new Laravel version?What are the security improvements in the new Laravel version?Apr 29, 2025 am 12:17 AM

Laravel's latest version has significantly improved security, including: 1. Enhanced CSRF protection, through a more robust token verification mechanism; 2. Improved SQL injection protection, through an enhanced query construction method; 3. Better session encryption to ensure user data security; 4. Improved authentication system, supporting finer granular user authentication and multi-factor authentication (MFA).

Time Zone Tango: Navigating Scheduling Conflicts in a Global WorkforceTime Zone Tango: Navigating Scheduling Conflicts in a Global WorkforceApr 29, 2025 am 12:13 AM

Tonavigateschedulingconflictsinaglobalworkforce,usetechnology,empathy,andstrategicplanning:1)EmploytoolslikeWorldTimeBuddyorCalendlyforscheduling;2)Rotatemeetingtimestoensurefairness;3)Establishcorehoursforoverlap;4)Beculturallysensitiveandflexiblewi

Full-Stack Development with Laravel: Managing APIs and Frontend LogicFull-Stack Development with Laravel: Managing APIs and Frontend LogicApr 28, 2025 am 12:22 AM

In Laravel full-stack development, effective methods for managing APIs and front-end logic include: 1) using RESTful controllers and resource routing management APIs; 2) processing front-end logic through Blade templates and Vue.js or React; 3) optimizing performance through API versioning and paging; 4) maintaining the separation of back-end and front-end logic to ensure maintainability and scalability.

Lost in Translation: Cultural Nuances and Misunderstandings in Distributed TeamsLost in Translation: Cultural Nuances and Misunderstandings in Distributed TeamsApr 28, 2025 am 12:22 AM

Totackleculturalintricaciesindistributedteams,fosteranenvironmentcelebratingdifferences,bemindfulofcommunication,andusetoolsforclarity.1)Implementculturalexchangesessionstosharestoriesandtraditions.2)Adjustcommunicationmethodstosuitculturalpreference

Measuring Connection: Analytics and Insights for Remote Communication EffectivenessMeasuring Connection: Analytics and Insights for Remote Communication EffectivenessApr 28, 2025 am 12:16 AM

Toassesstheeffectivenessofremotecommunication,focuson:1)Engagementmetricslikemessagefrequencyandresponsetime,2)Sentimentanalysistogaugeemotionaltone,3)Meetingeffectivenessthroughattendanceandactionitems,and4)Networkanalysistounderstandcommunicationpa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment