使用vagrant快速搭建boxjp开发环境

本文介绍如何使用Vagrant和VirtualBox快速部署一个名为boxjp的开发环境。文章详细记录了从环境准备到启动虚拟机的全过程,并提供了配置文件示例及服务启动指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用vagrant快速搭建boxjp开发环境

前提

  • 已经安装好virtualbox
  • 已经安装好vagrant

部署开发环境

  • 下载boxjp.box 文件,放到任意目录;

假设下载的文件放到了~/Desktop下

  • 创建一个目录用于存放代码和开发环境配置文件

mkdir ~/Workspace/test/vagrant

  • 初始化

cd ~/Workspace/test/vagrant

vagrant box add boxjp ~/Desktop/boxjp.box

vagrant init boxjp

  • 修改配置Vagrantfile

增加如下内容:

config.ssh.username = "vagrant"

config.ssh.password = "vagrant"

config.vm.network "private_network"ip: "10.10.1.5" 

完整Vagrantfile文件内容:

# -*- mode: ruby -*-

# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure

# configures the configuration version (we support older styles for

# backwards compatibility). Please don't change it unless you know what

# you're doing.

Vagrant.configure("2") do |config|

# The most common configuration options are documented and commented below.

# For a complete reference, please see the online documentation at

https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for

# boxes at https://vagrantcloud.com/search.

config.vm.box = "boxjp"

config.ssh.username = "vagrant"

config.ssh.password = "vagrant"

config.vm.network "private_network", ip: "10.10.1.5"

# Disable automatic box update checking. If you disable this, then

# boxes will only be checked for updates when the user runs

# `vagrant box outdated`. This is not recommended.

# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port

# within the machine from a port on the host machine. In the example below,

# accessing "localhost:8080" will access port 80 on the guest machine.

# NOTE: This will enable public access to the opened port

# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a forwarded port mapping which allows access to a specific port

# within the machine from a port on the host machine and only allow access

# via 127.0.0.1 to disable public access

# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

# Create a private network, which allows host-only access to the machine

# using a specific IP.

# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.

# Bridged networks make the machine appear as another physical device on

# your network.

# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is

# the path on the host to the actual folder. The second argument is

# the path on the guest to mount the folder. And the optional third

# argument is a set of non-required options.

# config.vm.synced_folder "../data", "/vagrant_data"

# Provider-specific configuration so you can fine-tune various

# backing providers for Vagrant. These expose provider-specific options.

# Example for VirtualBox:

#

# config.vm.provider "virtualbox" do |vb|

# # Display the VirtualBox GUI when booting the machine

# vb.gui = true

#

# # Customize the amount of memory on the VM:

# vb.memory = "1024"

# end

#

# View the documentation for the provider you are using for more

# information on available options.

# Enable provisioning with a shell script. Additional provisioners such as

# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the

# documentation for more information about their specific syntax and use.

# config.vm.provision "shell", inline: <<-SHELL

# apt-get update

# apt-get install -y apache2

# SHELL

end

  • 部署代码

mkdir ~/Workspace/test/vagrant/boxjp

cd ~/Workspace/test/vagrant/boxjp

git git@code.aliyun.com:zy/btc_boxjp_www.git

  • 修改项目配置文件
    • cp btc_boxjp_www/conf/application.ini.dev btc_boxjp_www/conf/application_local.ini

application_local.ini 内容如下:(application_local.ini下载

 [common]

application.directory APPLICATION_PATH "/application"

application.modules "Index,Admin,Ajax,Cms,Api,Product,Wap,Account"

;application.dispatcher.throwException = 1

;application.dispatcher.catchException = 1

application.use_namespace 1

application.layout.directory APPLICATION_PATH "/application/views/layouts"

application.protect_from_csrf 1

db.default.dsn "mysql:dbname=btcbox_jp;host=box-db00;port=3306"

db.default.username root

db.default.password 123456

db.slave01.dsn "mysql:dbname=btcbox_jp;host=box-db00;port=3306"

db.slave01.username root

db.slave01.password 123456

redis.default.host 127.0.0.1

redis.default.port 6379

redis.default.db 4

redis.cache.host 127.0.0.1

redis.cache.port 6379

redis.cache.db 0

; 短信发送间隔(秒)

sms.mintime 60

; 每天发送量(次)

sms.maxday 50

; 邮件发送间隔

mail.mintime 60

;登录错误次数

login.errcnt 5

;登录账号个数

login.user 5

[cli : common]

application.directory APPLICATION_PATH "/application"

application.modules="Cli"

[www : common]

[test : common]

[aws : common]

[git : common]

[m : common]

[appapi : common]

  • 修改本机hosts文件,增加如下内容

10.10.1.5 www.testboxjp.com

  • 启动虚拟机

cd ~/Workspace/test/vagrant

vagrant up

  • 访问测试环境

使用浏览器分别访问hosts文件中配置的域名:www.testboxjp.com

测试环境说明

  • 启动boxjp测试环境

cd ~/Workspace/test/vagrant

vagrant up

  • 关闭测试环境

cd ~/Workspace/test/vagrant

vagrant halt

  • 登录测试环境

cd ~/Workspace/test/vagrant

vagrant ssh

 

  • 销毁测试环境(虚拟机)
        cd ~/Workspace/test/vagrant

 

vagrant destroy

  • 测试环境nginx,redis,mysql,php-fpm 配置文件

nginx: /etc/nginx

redis: /etc/redis.conf

php.ini: /opt/remi/php56/root/etc/php.ini

php-fpm.ini: opt/remi/php56/root/etc/php-fpm.conf

mysql: /etc/my.cnf

  • 如何启动nginx,redis,mysql, php-fpm

systemctl start nginx

systemctl start redis

systemctl start mysqld

systemctl start php-fpm

  • nginx 日志目录

/var/log/nginx/

  • msyql

账号:root

密码:123456

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gftoso

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值