下载安装
1 | VirtualBox 5.1.8 |
vagrant常用命令
查看vagrant list
uiste:box uiste$ vagrant box list
添加vagrant box
uiste:box uiste$ vagrant box add ubuntu1404 ubuntu1404.box
添加虚拟机
1
2
3uiste:local_lamp_dev uiste$ pwd
/Users/uiste/vagrant/local_lamp_dev
uiste:local_lamp_dev uiste$ vagrant init ubuntu1404启动虚拟机
uiste:local_lamp_dev uiste$ vagrant up
取得链接
1
2uiste:local_lamp_dev uiste$ vagrant ssh
vagrant@vagrant-ubuntu-trusty-64:~$退出、挂起虚拟机
1
2
3
4vagrant@vagrant-ubuntu-trusty-64:~$ exit
logout
Connection to 127.0.0.1 closed.
uiste:local_lamp_dev uiste$ vagrant suspend重启虚拟机
1
uiste:local_lamp_dev uiste$ vagrant reload
对虚拟机进行优化
- 替换源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
vagrant@vagrant-ubuntu-trusty-64:~$ sudo vim /etc/apt/sources.list #修改源
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get update #更新列表
L(A|N)MP软件安装
安装nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install nginx -y
// 安装成功测试
vagrant@vagrant-ubuntu-trusty-64:~$ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)
vagrant@vagrant-ubuntu-trusty-64:~$ curl -I 'http://127.0.0.1'
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Tue, 04 Apr 2017 17:17:02 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 04 Mar 2014 11:46:45 GMT
Connection: keep-alive
ETag: "5315bd25-264"
Accept-Ranges: bytes安装Apache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install apache2 -y
// 安装成功测试
vagrant@vagrant-ubuntu-trusty-64:~$ apache2 -v
Server version: Apache/2.4.7 (Ubuntu)
// nginx 服务停止
vagrant@vagrant-ubuntu-trusty-64:~$ sudo /etc/init.d/nginx stop
// 启动 apache2 服务
vagrant@vagrant-ubuntu-trusty-64:~$ sudo /etc/init.d/apache2 start
* Starting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppress this message
*
vagrant@vagrant-ubuntu-trusty-64:~$ curl -I 'http://127.0.0.1'
HTTP/1.1 200 OK
Date: Tue, 04 Apr 2017 17:24:09 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Tue, 04 Apr 2017 17:18:42 GMT
ETag: "2cf6-54c5a77b221fa"
Accept-Ranges: bytes
Content-Length: 11510
Vary: Accept-Encoding
Content-Type: text/html
#端口修改-Apache
vagrant@vagrant-ubuntu-trusty-64:~$ sudo vim /etc/apache2/ports.conf
Listen 8888
vagrant@vagrant-ubuntu-trusty-64:~$ sudo /etc/init.d/apache2 restart
#端口修改-Nginx
#修改成9000端口 ,默认sock模式
cd /etc/php5/fpm/pool.d
sudo vim www.conf # search listen = 127.0.0.1:9000
sudo /etc/init.d/php5-fpm restart安装MySQL软件
1
2
3
4
5
6
7
8#服务器端
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install mysql-server
安装期间会提示输入为mysql设置root密码,我这边不操作,直接enter 不设置密码
#客户端
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install mysql-client
#测试连接库,上面安装服务端没有设置密码,这里直接enter进入
vagrant@vagrant-ubuntu-trusty-64:~$ mysql -uroot -p
Enter password:安装PHP
1
2
3
4
5
6
7
8
9
10
11
12
13#安装php
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install php5-cli -y
#安装成功测试
vagrant@vagrant-ubuntu-trusty-64:~$ php -v
PHP 5.5.9-1ubuntu4.21 (cli) (built: Feb 9 2017 20:54:58)
#安装php扩展
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install php5-mcrypt php5-mysql php5-gd -y
#支持apache2的php模块
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install libapache2-mod-php5
#支持nginx fastcgi 启动php
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install php5-cgi php5-fpm
#开发Apache文件.htaccess重写功能
vagrant@vagrant-ubuntu-trusty-64:/$ sudo a2enmod rewrite安装git
1
vagrant@vagrant-ubuntu-trusty-64:/home/www/code$ sudo apt-get install git -y
Vagrant高级配置
端口转发
1
2
3
4
5
6
7
8配置
config.vm.network "forwarded_port", guest: 80, host: 8888
config.vm.network "forwarded_port", guest: 8888, host: 8889
测试效果
http://127.0.0.1:8888/
http://127.0.0.1:8889/网络设置
1
2
3
4
5
6
7配置
config.vm.network "private_network", ip: "192.168.199.101"
效果
http://192.168.199.101/ 或者 http://192.168.199.101:80/
http://192.168.199.101:8888/
*共享目录1
2
3配置
config.vm.synced_folder "/Users/uiste/www/code/", "/home/www"
框架配置
tp5
1 | git clone https://github.com/top-think/think tp5 |
yii2
1 | 下载:github.com/yiisoft/yii2/releases/download/2.0.10/yii-basic-app-2.0.10.tgz |
laravel5
1 | 下载: down.golaravel.com/laravel/laravel-v5.1.11.zip |
vagrant虚拟机配置
虚拟机名称vb.name = "ubuntu_code"
虚拟机主机名config.vm.hostname = "code"
配置虚拟机内存和CPUvb.memory = "1024"
vb.cpus = 2
打包命令
vagrant package --output uiste.box
- 打包升级
1 | config.vm.provision "shell", inline: <<-SHELL |