赞
踩
学习laravel的话,homestead可以说是必备的,而且laravel的作者也推荐使用,国内的社区也都有相关的教程.
但是大多都是在线安装, 但是在线安装最大的缺点就是: 慢, 非常慢, 奇慢无比
...服务器在国外,而且.box
文件本分也有1G多, 要想体验在线安装, 可以晚上执行命令, 然后去睡觉, 运气好的话,就安装成功了
在安装之前homestead之前, 请确保你的电脑安装好了, virtual box
和 vagrant
metadata.json
文件- {
- "name": "laravel/homestead",
- "versions": [{
- "version": "6.3.0", // 这个是我的homestead版本, 如果不是这个请自行更改
- "providers":[
- {
- "name": "virtualbox",
- "url": "file://C:/vagrant/virtualbox.box" // .box 文件存放的绝对路径
- }
- ]
- }]
- }
vagrant box add metadata.json
vagrant box list
- git clone https://github.com/laravel/homestead
- cd homestead
- git checkout v6.3.0
./init.bat
./init.sh
ssh-keygen -t rsa -C "your email address"
将这里的 your email address
换成你的邮箱, 然后一路回车, 为什么要加个邮箱? 因为github免密提交的秘钥是这样生成的, 如果这样生成的话, 不用再重新配置了
vagrant up
homestead默认nginx重写规则是只支持laravel, 如果想用其他框架也运行在 homestead 中又不想自己再配置一个环境,这里以ThinkPHP框架为例
在
/homestead/scripts/
目录下新建一个serve-thinkphp.sh
- #!/usr/bin/env bash
- declare -A params=$6 # Create an associative array
- paramsTXT=""
- if [ -n "$6" ]; then
- for element in "${!params[@]}"
- do
- paramsTXT="${paramsTXT}
- fastcgi_param ${element} ${params[$element]};"
- done
- fi
-
- # nginx 配置
- block="server {
- listen ${3:-80};
- listen ${4:-443} ssl http2;
- server_name .$1;
- root \"$2\";
- index index.html index.htm index.php;
- charset utf-8;
- location / {
- #try_files \$uri \$uri/ /index.php?\$query_string;
- if (!-e \$request_filename) {
- rewrite ^(.*)$ /index.php?s=/\$1 last;
- #break;
- }
- }
- location = /favicon.ico { access_log off; log_not_found off; }
- location = /robots.txt { access_log off; log_not_found off; }
- access_log off;
- error_log /var/log/nginx/$1-error.log error;
- sendfile off;
- client_max_body_size 100m;
- location ~* ^(/images|/Static).+.(jpg|jpeg|css|gif|png|ico) {
- access_log off;
- }
- location ~ \.php$ {
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
- fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
- fastcgi_index index.php;
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
- fastcgi_intercept_errors off;
- fastcgi_buffer_size 16k;
- fastcgi_buffers 4 16k;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- include fastcgi_params;
- }
- location ~ /\.ht {
- deny all;
- }
- ssl_certificate /etc/nginx/ssl/$1.crt;
- ssl_certificate_key /etc/nginx/ssl/$1.key;
- }
- "
-
- echo "$block" > "/etc/nginx/sites-available/$1"
- ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"

/homestead/Homestead.yml
的 site
选项中指定一个type
属性- sites:
- - map: www.fastadmin.local
- to: /home/vagrant/code/fastadmin/public
- type: thinkphp
- - map: www.peiqi.com
- to: /home/vagrant/code/peiqi/public
- type: thinkphp
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。