Original: https://blog.csdn.net/woqianduo/article/details/81091154/
1 Introduction
1.1 What is Homestead
Laravel Homestead is an official pre-packaged Vagrant box, it provides a perfect development environment for you, without having to install PHP on the local machine, Web servers and other server software. Do not worry about messing up your operating system! Vagrant boxes are disposable. If a problem arises, you can be destroyed in minutes and create a Box!
Homestead can run on any Windows, Mac, or Linux system, which includes the Nginx web server, PHP 7.2, PHP 7.1, PHP 7.0, PHP 5.6, MySQL, PostgreSQL, Redis, Memcached, Node, and the development of Laravel applications needed thing.
1.2 What is the Vagrant
Vagrant built on virtualization technology to run virtual machine environment management tool
1.3 Before You Begin
Before installing Homestead, install Git, Virtualbox and Vagrant yourself and download homestead.box
2, installation Homestead
My Vagrant installation directory selection in D: / Vagrant
2.1, open Git Bash enter D: / Vagrant
2.2, add homestead.box to Vagrant
2.2.1, no homestead.box local execution (recommend use the second approach, first download)
vagrant box add laravel/homestead
2.2.2, with a local homestead.box, copy homestead.box to D: / Vagrant under (current directory)
vagrant box add laravel/homestead homestead.box
2.2.3, see the installation results execution
vagrant box list
//laravel/homestead (virtualbox, 6.1.0)
//见以上结果为安装成功
2.3 Cloning Laravel Homestead repository to D: / vagrant / homestead
git clone https://github.com/laravel/homestead.git
cd homestead
2,4. # Execution init.sh (generation Homestead.yaml file)
bash init.sh
. 2.5 Create a working directory
D: / vagrant / www
because the composer to specify php version, windows environment if no php (when there can be no), because soon use the homestead of lnmp environment. So to not install windows laravel, such as homestead installed after installing composer and laravel in lnmp environment can, you can build a simple directory of the D: / vagrant / www / test / public build a index.php (echo 'hello laravel ').
2.6, placed Hi钥
cd ~/.ssh
ls
Id_rsa and see if there is even a id_rsa.pub file, if you do not, reproduction, if not execute the following command
ssh-keygen -t rsa -C "[email protected]
2.7, # Homestead.yaml configuration files (My Documents in the D: / vagrant / homestead directory)
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: D:/Vagrant/code
to: /home/vagrant/code
sites:
- map: test.homestead.com
to: /home/vagrant/laravel/public
databases:
- homestead
2.8, configuration windows hosts file
to open the C: / Windows / System32 / drivers / etc / host Add
192.168.10.10 test.homestead.com
2.9, if you use a local box files installed, you need to find the homestead \ scripts \ folder, open the file homestead.rb
config.vm.box_version = settings [ "version"] || = "> = 0"
2.10, the basic use
//启动虚拟机
cd d:/homestead
vagrant up
//进入虚拟机
vagrant ssh
//登录mysql 密码为secret (查看mysql版本是否为自己想要的)
mysql -u homestead -p
//查看php版本、nginx版本
php -v
nginx -v
3, the installation is complete
3.1, success
After installation in the local browser, visit: test.homestead.com
If the previous output written script: hello laravel
Then it ended.
3.2, an error
Error: 502 Bad Gateway
1. Check the nginx error log
/var/log/nginx && ls
//access.log error.log test.laravel.com-error.log
cat test.laravel.com-error.log
//看到错误日志:
2019/05/29 16:02:47 [crit] 844#844: *1 connect() to unix:/var/run/php/php7.3-fpm.sock failed (2: No such file or directory) while connecting to upstream, client@@@
//大致意思是php7.3未找到
2. Check php
cd /var/run/php && ls
//php5.6-fpm.sock php7.0-fpm.sock php7.1-fpm.sock php7.2-fpm.sock
//没有php7.3
3. Modify the site configuration nginx
cd /etc/nginx/sites-enabled && ls
//test.laravel.com
sudo vim test.laravel.com
/*
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
*/
//将php7.3-fpm.sock修改为:php7.2-fpm.sock,保存退出
4. Restart nginx
sudo nginx -s reload