vagrant搭建lamp開發環境

使用vagrant快速搭建分享開發環境

本案列操做環境

  1. windows7 vagrant1.8.1 virtualbox4.3

安裝virtualbox4.x(或更高)

  1. virtualbox, win7下傻瓜式安裝, 無需配置, 略過.

安裝vagrant

  1. 下載vagrant軟件包 地址, 安裝(windows傻瓜式安裝, 很少說).php

  2. 建立vagrant工程目錄, 初始化Vagrantfile.html

    F:\> mkdir vagrant
     F:\> cd vagrant
     F:\vagrant>vagrant.exe init
         A `Vagrantfile` has been placed in this directory. You are now
         ready to `vagrant up` your first virtual environment! Please read
         the comments in the Vagrantfile as well as documentation on
         `vagrantup.com` for more information on using Vagrant.
  3. 添加box(相似docker的容器), 到官方源下載須要的box, 本案例下載(puppetlabs/centos-6.6-64-nocm)(https://atlas.hashicorp.com/puppetlabs/boxes/centos-6.6-64-nocm),公司服務器是centos6.x.mysql

    F:\vagrant>vagrant box add puppetlabs/centos-6.6-64-nocm
     ==> box: Loading metadata for box 'puppetlabs/centos-6.6-64-nocm'
         box: URL: https://atlas.hashicorp.com/puppetlabs/centos-6.6-64-nocm
     This box can work with multiple providers! The providers that it
     can work with are listed below. Please review the list and choose
     the provider you will be working with.
    
     1) virtualbox
     2) vmware_desktop
    
     Enter your choice: 1
     ==> box: Adding box 'puppetlabs/centos-6.6-64-nocm' (v1.0.3) for provider: virtualbox
         box: Downloading: https://atlas.hashicorp.com/puppetlabs/boxes/centos-6.6-64-nocm/versions/1.0.3/providers/virtualbox.box
         box: Progress: 0% (Rate: 27052/s, Estimated time remaining: 3:23:32)==> box: Waiting for cleanup before exiting...
    
         box: Progress: 0% (Rate: 23813/s, Estimated time remaining: 3:26:33)
     ==> box: Box download was interrupted. Exiting.

    ps: 慢的有的一B啊, 果斷複製連接, 迅雷下載, 安裝*.box文件. 速度還能接受.
    downloadlinux

    box命令略解: vagrant box add [可選參數] <官方源名稱, url連接地址, 下載後的*.box文件>web

    安裝box文件(秒幹):sql

    F:\vagrant>vagrant box add --name puppetlabs/centos-6.6-64-nocm  F:\boxes\virtualbox.box
         ==> box: Box file was not detected as metadata. Adding it directly...
         ==> box: Adding box 'puppetlabs/centos-6.6-64-nocm' (v0) for provider:
             box: Unpacking necessary files from: file://F:/boxes/virtualbox.box
             box: Progress: 100% (Rate: 658M/s, Estimated time remaining: --:--:--)
         ==> box: Successfully added box 'puppetlabs/centos-6.6-64-nocm' (v0) for 'virtualbox'!
  4. 使用剛下在的boxdocker

    1. 編輯vagrant工程目錄下的Vagrantfile文件apache

      15行: config.vm.box = "puppetlabs/centos-6.6-64-nocm"
    2. 啓動vagrant(此處會啓動virtualbox, 預先安裝virtualbox, win7安裝有點小問題, 請自行google或百度解決)windows

      vagrant up
    3. ssh上去(默認F:/vagrant 自動掛載到/vagrant)上centos

      F:\vagrant>vagrant ssh
       Last login: Fri May  6 02:33:11 2016 from 10.0.2.2
       [vagrant@localhost ~]$ ls /
       bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  vagrant  var
       [vagrant@localhost ~]$
    4. 在/vagrant建立的文件, 會同步到 F:>vagrant下.

Centos Box 安裝lamp環境

本案列使用 apache2.4, php5.6.12 mysql5.7 編譯安裝, 源文件都一打包好, 有須要能夠找我要loovien@163.com.

  1. 默認全部服務安裝到/usr/local/webserver目錄下.

  2. 安裝必要的依賴.

    $ sudo yum groupinstall "Development tools"
  3. apache2.4 編譯.

    1. http2.4.x源碼包中不含有apr apr-util 下載它們, 解壓到http2.4.x/srclib下.
    2. 下載pcre-8.3.x.tar.gz, 解壓 執行 ./configure && make && make install.
    3. 編譯apache2.4.x 定位到httpd源碼目錄, 執行編譯./configure --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-expires --enable-headers --enable-usertrack --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --with-include-apr --prefix=/usr/local/webserver, make && make install
    4. 配置httpd DocumentRoot => /vagrant/www目錄下.
  4. 編譯php

    1. 安裝依賴, 沒辦法, 編譯就是這樣, 少了什麼依賴就安裝什麼依賴, 編譯安裝.

      $ sudo yum install libxml2 libxml-devel
      $ ./configure --prefix=/usr/local/webserver/php --with-mysql
      $ make && make install

  5. 編譯mysql

    1. 徹底編譯mysql5.5工程量比較大, 本例下載二進制包, 下載.
    2. 解壓後查看README文檔安裝便可
  6. 運行項目可能須要編譯php擴展, 自行安裝便可, 使用 phpize.

  7. 在/etc/rc.local, 添加apache2, mysql 啓動命令, 是開機啓動.

開發

  1. 後期自動把項目掛載F:\vagrant下, 讓虛擬box的http Document目錄軟連接到 /vagrant目錄便可.
相關文章
相關標籤/搜索