如何离线安装 homestead

学习laravel的话,homestead可以说是必备的,而且laravel的作者也推荐使用,国内的社区也都有相关的教程.
但是大多都是在线安装, 但是在线安装最大的缺点就是: 慢, 非常慢, 奇慢无比...服务器在国外,而且.box文件本分也有1G多, 要想体验在线安装, 可以晚上执行命令, 然后去睡觉, 运气好的话,就安装成功了

系统环境需要

在安装之前homestead之前, 请确保你的电脑安装好了, virtual boxvagrant

创建 metadata.json

  • 下载 .box 文件之后, 在.box文件同级目录下创建一个 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

克隆homestead切换到指定的版本

git  clone  https://github.com/laravel/homestead
cd homestead
git checkout v6.3.0

初始化

  • windows ./init.bat
  • macos or linux ./init.sh
  • 生成链接秘钥
ssh-keygen  -t rsa -C "your email address"

将这里的 your email address 换成你的邮箱, 然后一路回车, 为什么要加个邮箱? 因为github免密提交的秘钥是这样生成的, 如果这样生成的话, 不用再重新配置了

启动 homestead

vagrant  up

如何在homestead中运行其他的框架

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.ymlsite 选项中指定一个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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值