


The content of this article is about how to solve the problem of setting up Laravel development environment. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Text: Simple steps
Install VirtualBox
Install Vagrant
-
Import Homestead Box virtual machine box
Install Git
Install Homestead management script
Configure Homestead.yaml file
Start Homestead
Install VirtualBox
VirtualBox百科词条 https://baike.baidu.com/item/VirtualBox/5842786?fromtitle=virtual%20box&fromid=3961028&fr=aladdin
Simple understanding: Simulate the system you want
Installation: Click Next to
Install Vagrant
百度词条 https://baike.baidu.com/item/Vagrant/1321946?fr=aladdin
Simple understanding: Create and deploy a virtualized development environment.
Installation: next
When you first start using the vagrant command, always enter vagrant up as vargant. It is customary to think that it means var assignment. Later, I got inspiration from mysql grant permissions and inquired about its English word meaning, and then I understood that grant means recognition; agreement; grant. This is transformed into a program context, which is somewhat similar to "granting permissions". To use things developed by foreigners, you still have to master basic English skills to better understand...
Homestead introduction
The homestead provided by the original link actually packages N types of software required for development. and vagrant boxes. The main purpose is to provide an excellent development environment. PHP, Composer, Nginx, Mysql, git... and other tool software have been transplanted into the box.
The purpose is to build a consistent development environment for team development members, ensure that member environments are consistent, and avoid unpredictable errors due to environment configuration. This is why Laravel Academy requires beginners to download and import customized boxes~
1. Homestead management script
Homestead script is written using Ruby and Shell scripts. The principle is to customize the vagrantfile file. Configuration information will be read from ~/Homestead/Homestead.yaml
. During provisioning, parse to vagrant command and configure the virtual machine
At the same time, it provides an extremely simple and easy-to-use interface, and simple configuration can complete complex tasks
IP configuration , Port mapping
Nginx Site creation
Database creation
The host folder is hung to Tasks such as virtual machines
Installing and using Homestead
Download and import the Homestead virtual machine box
Install Git and prepare to download the Homestead management script
Use Git to download the Homestead management script
1. Download and import Homestead Box
Under Windows, you need to use the import command to find the path where the box is located. Enter the following command in cmd
> vagrant box add metadata.json
2. Install GIT
Keyword: next
There are many installation mode options, so Find time to study it
3. Download the homestead management script
Clone the git project of summer homepage under WINDOWS, the default is C drive username/homstead. The file can be found
> cd ~ > git clone https://git.coding.net/summerblue/homestead.git Homestead
After completion, create a branch checkout v7.8.0 for GIT (Note that the file name is case-sensitive)
> cd ~/Homestead > git checkout v7.8.0 #刚开始不知道checkout是什么,还以为是检查版本,后来发现这是git版本管理一个强大的功能
Next, initialize Homestead
> bash init.sh
After successful operation, three files will be generated in the ~/Homestead
directory
Homestead.yaml main configuration information file, from which you can read the battle points and Database and other information
after.sh-Every time the homestead box is reset (provision), the shell script file will be called
alsaes-Every time After the homestead box is reset, it will be replaced in the
~/.bash_alisases
file of the virtual machine.aliases
Put the various configuration information of some files for details
Here vagrant provision is used in conjunction with vagrant reload to load the modified yaml file configuration, similar to restarting apache after modifying it
Homestead.yaml configuration file
Next, configure Homestead.yaml
in detail
> cd ~/Homestead/ #进入到Homestead/文件夹下> explorer . #打开该文件夹视图,然后打开homestead.yaml配置进行修改
Another way to use commands to quickly open the Homestead.yaml file
> subl ~/Homestead/Homestead.yaml #subl是sublime打开文件的命令,需要单独配置,详见下方
转:终端用sublime打开文件的方法 作者:**QUETAL** https://blog.csdn.net/u011240016/article/details/54434923
Homestead.yaml configuration is roughly divided into Configure the following
virtual machines
SSH key login settings
Shared files Folder configuration
Site configuration
Database configuration
Custom variables
1. Virtual machine configuration
Homestead supports us to configure the IP, memory, CPU, and default provider of the virtual machine. We basically don’t need to do any configuration here.
ip: "192.168.10.10" #ip映射,配置虚拟域名,需要在终端hosts添加该ip.后续有memory: 2048cpus: 1provider: virtualbox
2.SSH key login configuration
authorize
option is to assign the public key file for logging into the virtual machine to authorize the connection. This file is filled with host# The public key file address on ## is . When the virtual machine is initialized, the contents of this file will be copied and stored by default to the virtual machine /home/vagrant/.ssh/authorized_keys file. , thereby achieving
ssh password-free login. Here we fill in by default
authorize ~/.ssh/id.rsa.pub #这就是为什么输入vagrant up && vagrant ssh即可免密码登录
keys
是数组选项,填写的是本机SSH私钥文件地址。虚拟机初始化时,会将此处填写的所有SSH私钥文件赋值到虚拟机的/home/vagrant/.ssh/
文件夹中,从而使虚拟机能共享主机上的SSH私钥文件,使虚拟机具备等同于主机的身份认证。此功能为SSH授权提供了便利。例如在后面章节中,我们只需要在Github配置一个SSH公钥即可实现GITHUB对虚拟机和主机共同认证(GitHub是代码托管,终端代码提交需要配置公钥连接)
keys: - ~/.ssh/id_ras- ~/.ssh/id_rsa.pub #变化在这里,此处我们将公钥和私钥一起同步到虚拟机中
接下来生成ssh key,请先检查主机是否已生成过SSH key C:/……./用户/用户名/.ssh 可查看是否已配置
> ls -al ~/.ssh #输入这个即可查询是否配置> > #ls (选项)(参数) > #ls命令用来显示目标列表,在Linux中是使用率较高的命令> # -a 显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为影藏,不会列出);> # -l与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;> # cannot access '/c/Users/用户名/.ssh': No such file or directory 即没有配置过
生成 SSH key
ssh-keygen -t rsa -C "your_email@example.com"#上面的邮箱替换成自己的
接下来命令行会提示让你指定秘钥的名称,按回车键将 SSH KEY保存到默认文件名即可
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
设置密码,回车键默认为空密码
再次查看是否配置成功
ls -al ~/.ssh
如下图
SSH秘钥的连个文件
id_rsa
——–SSH秘钥 的 私钥 (Private Key)id_ras.pub
———SSH秘钥的公钥 (Public Key)
3.共享文件夹配置
可以通过folders
来致命本机要映射到Homestead虚拟机上的文件夹
map
对应的是我们本机的文件夹,例如 C:/Code 。to
对应的是Homestead上的文件夹,即虚拟机中的文件夹。一定一定要注意映射文件夹的大小写名字,否则会出现 no input file specified
一定一定要保存修改完后的配置文件,如果没有保存直接配置加载也没关系,你会学习到一系列有趣的问题(手动微笑)
folders: - map :~/Code - to:/home/vagrant/Code
联想:
相当于在本机修改程序文件,最终是会映射到虚拟机的文件夹上。
PS:使用IDE最好是轻量级的,例如editplus、sublime等。如果ide有git相关插件。以后每次修改文件,会遍历整个目录树,机器不好的容易卡。例如laravel默认是9000个文件,映射到虚拟机的文件同样是9000个,那么修改代码时,相当于遍历18000个文件。这也间接体现了laravel为什么是重量级框架,集成了现代商业化项目大部分需要的功能。由于是深度配置,所以定制功能时的修改也相对麻烦。
关于laravel框架 和 ide 的选择上,适合自己的才是最好的,未必集成的功能越多就越好。具体看项目开发/开发者自身需求
默认Homestead
会将我们本地的~/Code
文件映射到/home/vagrant/Code
文件夹上。目前还没有~/Code,需创建
> cd ~ > mkdir Code #在默认路径下创建Code文件夹> > #可使用 explorer .打开该文件夹的视图
4.站点配置(网站根目录映射)
站点配置允许你在唉主机里,通过域名来访问虚拟机的Laravel应用。如下面sites
配置所示,将homestead.test映射到一个Laravel项目的public
目录上。这一行配置,会命令homestead为我们新建一个Nginx站点,并且把Web Root配置到指定目录下。Laravel应用的Nginx站点 Web Root 配置,默认就是根目录的public
目录下
sites: - map: homestead.test to: /home/vagrant/Code/Laravel/public #此处的Laravel还没创建,待会会用COMPOSER下载
另外,主机里直接访问虚拟机站点,必须通过绑定hosts
来实现。终端需要修改hosts文件绑定到homestead.test
到虚拟机IP192.168.10.10
上,hosts
完整路径为 C:\Windows\System32\Drivers\ect\hosts
> subl C:\Windows\System32\Drivers\ect\hosts
在hosts文件中添加
192.168.10.10 homestead.test
注意:WINDOWS 10因为权限设置相关问题,即使打开了该文件可能也无法修改成功,此处有两种方式替代
打开该路径,复制hosts到任意目录并修改配置,最后覆盖
-
使用powershell打开并修改
2.1windows 开始菜单图标【即最左下角的菜单】—> 点击右键2.2 单击Windows PowerShell(管理员)
2.3 cd drivers/etc
2.4 notepad hosts
5.数据库配置
可以为homestead指定数据库名称,这里使用默认设置即可
databases: - homestead
运行Vagrant
完成相关配置后,开启虚拟机
以下为相关命令
命令行 | 说明 | 相关例子 |
---|---|---|
vagrant init | 初始化vagrant | |
vagrant up | 启动vagrant | |
vagrant halt | 关闭虚拟机 | 如果直接在cmd中exit 不halt,下次启动会出现仍在运行 |
vagrant ssh | 通过SSH登录vagrant (需要先启动vagrant) | 需要在homestead配置公钥而免密码登录 |
vagrant provision | 重新应用更改vagrant配置 | 类似apache修改配置项后需要重启,此处同理 |
vagrant reload | 重载虚拟机 | 搭配 vagrant provision && vagrant reload |
vagrant destroy | 删除vagrant |
接下来开启Homestead
> cd ~/Homestead && vagrant up
第一次启动时,vagrant会做以下几件事
以导入的Homestead虚拟机盒子为模版,新建一台虚拟机(之前导入的homestead)
并按照
homestead.yaml
里的配置信息,对这台新建的虚拟机进行配置配置完成后启动虚拟机
成功启动后还是在~/Homestead
目录中,通过以下命名来来SSH登录Homestead虚拟机中
> vagrant ssh
> exit #退出当前虚拟机
> vagrant halt #关闭整个虚拟机
The above is the detailed content of How to solve the problem of setting up Laravel development environment. For more information, please follow other related articles on the PHP Chinese website!

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

Configuring a Debian mail server's firewall is an important step in ensuring server security. The following are several commonly used firewall configuration methods, including the use of iptables and firewalld. Use iptables to configure firewall to install iptables (if not already installed): sudoapt-getupdatesudoapt-getinstalliptablesView current iptables rules: sudoiptables-L configuration

The steps to install an SSL certificate on the Debian mail server are as follows: 1. Install the OpenSSL toolkit First, make sure that the OpenSSL toolkit is already installed on your system. If not installed, you can use the following command to install: sudoapt-getupdatesudoapt-getinstallopenssl2. Generate private key and certificate request Next, use OpenSSL to generate a 2048-bit RSA private key and a certificate request (CSR): openss


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version

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