当前位置:   article > 正文

如何离线安装 homestead

fastadmin离线安装

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

系统环境需要

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

创建 metadata.json

  • 下载 .box 文件之后, 在.box文件同级目录下创建一个 metadata.json 文件
  1. {
  2. "name": "laravel/homestead",
  3. "versions": [{
  4. "version": "6.3.0", // 这个是我的homestead版本, 如果不是这个请自行更改
  5. "providers":[
  6. {
  7. "name": "virtualbox",
  8. "url": "file://C:/vagrant/virtualbox.box" // .box 文件存放的绝对路径
  9. }
  10. ]
  11. }]
  12. }

执行安装命令

vagrant box add metadata.json

查看是否安装成功

vagrant  box  list

克隆homestead切换到指定的版本

  1. git clone https://github.com/laravel/homestead
  2. cd homestead
  3. 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

  1. #!/usr/bin/env bash
  2. declare -A params=$6 # Create an associative array
  3. paramsTXT=""
  4. if [ -n "$6" ]; then
  5. for element in "${!params[@]}"
  6. do
  7. paramsTXT="${paramsTXT}
  8. fastcgi_param ${element} ${params[$element]};"
  9. done
  10. fi
  11. # nginx 配置
  12. block="server {
  13. listen ${3:-80};
  14. listen ${4:-443} ssl http2;
  15. server_name .$1;
  16. root \"$2\";
  17. index index.html index.htm index.php;
  18. charset utf-8;
  19. location / {
  20. #try_files \$uri \$uri/ /index.php?\$query_string;
  21. if (!-e \$request_filename) {
  22. rewrite ^(.*)$ /index.php?s=/\$1 last;
  23. #break;
  24. }
  25. }
  26. location = /favicon.ico { access_log off; log_not_found off; }
  27. location = /robots.txt { access_log off; log_not_found off; }
  28. access_log off;
  29. error_log /var/log/nginx/$1-error.log error;
  30. sendfile off;
  31. client_max_body_size 100m;
  32. location ~* ^(/images|/Static).+.(jpg|jpeg|css|gif|png|ico) {
  33. access_log off;
  34. }
  35. location ~ \.php$ {
  36. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  37. fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
  38. fastcgi_index index.php;
  39. include fastcgi_params;
  40. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  41. fastcgi_intercept_errors off;
  42. fastcgi_buffer_size 16k;
  43. fastcgi_buffers 4 16k;
  44. fastcgi_connect_timeout 300;
  45. fastcgi_send_timeout 300;
  46. fastcgi_read_timeout 300;
  47. include fastcgi_params;
  48. }
  49. location ~ /\.ht {
  50. deny all;
  51. }
  52. ssl_certificate /etc/nginx/ssl/$1.crt;
  53. ssl_certificate_key /etc/nginx/ssl/$1.key;
  54. }
  55. "
  56. echo "$block" > "/etc/nginx/sites-available/$1"
  57. ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
  • /homestead/Homestead.ymlsite 选项中指定一个type属性
  1. sites:
  2. - map: www.fastadmin.local
  3. to: /home/vagrant/code/fastadmin/public
  4. type: thinkphp
  5. - map: www.peiqi.com
  6. to: /home/vagrant/code/peiqi/public
  7. type: thinkphp
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/449266
推荐阅读
相关标签
  

闽ICP备14008679号