


Laravel 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 包括以下两个东西
一个 vagrant box 虚拟机, 里面软件什么都下载好了;
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框架入门教程。
相关文章推荐:
相关课程推荐:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Both Django and Laravel are full-stack frameworks. Django is suitable for Python developers and complex business logic, while Laravel is suitable for PHP developers and elegant syntax. 1.Django is based on Python and follows the "battery-complete" philosophy, suitable for rapid development and high concurrency. 2.Laravel is based on PHP, emphasizing the developer experience, and is suitable for small to medium-sized projects.

How does Laravel play a role in backend logic? It simplifies and enhances backend development through routing systems, EloquentORM, authentication and authorization, event and listeners, and performance optimization. 1. The routing system allows the definition of URL structure and request processing logic. 2.EloquentORM simplifies database interaction. 3. The authentication and authorization system is convenient for user management. 4. The event and listener implement loosely coupled code structure. 5. Performance optimization improves application efficiency through caching and queueing.

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

Want to learn the Laravel framework, but suffer from no resources or economic pressure? This article provides you with free learning of Laravel, teaching you how to use resources such as online platforms, documents and community forums to lay a solid foundation for your PHP development journey from getting started to master.

To learn Laravel 6, you can get video tutorials from Laracasts (recommended), official documentation and YouTube. Recommended courses include Laracasts’ “Laravel 6 From Beginner to Mastery” and “Official Laravel 6 Tutorial” produced by the official team. When choosing a video course, consider skill level, teaching style, project experience and frequency of updates.

In this era of continuous technological advancement, mastering advanced frameworks is crucial for modern programmers. This article will help you improve your development skills by sharing little-known techniques in the Laravel framework. Known for its elegant syntax and a wide range of features, this article will dig into its powerful features and provide practical tips and tricks to help you create efficient and maintainable web applications.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.
