• Admin

      会员用户
    • (Admin 2018-04-04 09:26:46 修改)

           vagrant就是一款构建虚拟开发环境的工具,支持window,linux,mac,总有一款适合你。并且vagrant 可以把配置好的环境打包成一个box,分享给其他人直接使用,非常方便。

    undefined 

           第一步:安装virtualBox (本人virtualbox版本 4.3.30)

                  具体安装包请直接从官网下载:https://www.virtualbox.org/wiki/Downloads

           第二步:  安装 vagrant 

                  具体安装包请直接从官网下载:https://www.vagrantup.com/downloads.html

            第三步:vagrant 基本命令

    vagrant init        初始化vagrantfile

    vagrant add box    添加box,自动帮你生成vagrantfile

    vagrant halt        关闭虚拟机

    vagrant destroy    销毁虚拟机

    vagrant ssh        连接虚拟机

    vagrant reload      重新加载vagarntfile文件

    vagrantsuspend暂时挂起虚拟机

    vagrant status      查看虚拟机运行状态

            第四步:下载box

    下面是ubuntu的两个官方地址:

    Ubuntu precise 32 VirtualBoxhttp://files.vagrantup.com/precise32.box

    Ubuntu precise 64 VirtualBoxhttp://files.vagrantup.com/precise64.box

    如果你要其他系统的镜像,可以来这里下载:http://www.vagrantbox.es/

            //===============================番外篇

    Ubuntu 17.04 / 17.10 安装 LAMP, Linux Apache2 Mysql PHP, 以及phpmyadmin, INSTALLING LAMP ON UBUNTU 17.04 / 17.10

    #!/usr/bin/env bash
    
    # https://websiteforstudents.com/installing-lamp-ubuntu-17-04-17-10/
    # https://websiteforstudents.com/install-password-protect-phpmyadmin-ubuntu-17-04-17-10/
    
    # INSTALLING LAMP ON UBUNTU 17.04 / 17.10
    
    # STEP 1: 更新服务器
    sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove
    
    # STEP 2: 安装apache2
    sudo apt-get install apache2
    
    # 可能用的命令
    #sudo systemctl stop apache2.service
    #sudo systemctl start apache2.service
    #sudo systemctl enable apache2.service
    
    # STEP 3: 安装 MYSQL DATABASE
    sudo apt-get install mysql-server mysql-client
    
    # 可能用的命令
    #sudo systemctl stop mysql.service
    #sudo systemctl start mysql.service
    #sudo systemctl enable mysql.service
    
    #设置 secure MySQL server (参看最下方)
    sudo mysql_secure_installation
    
    # STEP 4: 安装 PHP
    sudo apt-get install php libapache2-mod-php php-mysql
    
    # STEP 5: 安装 PHPMYADMIN ON UBUNTU 17.04 / 17.10
    sudo apt-get install phpmyadmin
    
    # STEP 6: 打开地址重写 URL Rewrite
    sudo a2enmod rewrite
    # sudo vi /etc/apache2/apache2.conf
    # (没有的话,可以尝试sudo vi /etc/apache2/sites-available/000-default.conf)
    # 打开apache配置文件
    
    #实际目录根据网站根目录而定
    #<Directory /var/www/>
    #
    #    Options Indexes FollowSymLinks
    #    AllowOverride None  #改为All
    #    Require all granted
    #
    #</Directory>
    
    #Restart Server
    sudo service apache2 restart

    设置 secure MySQL server的时候,会出现以下内容:


    Enter password for user root: TYPE CURRENT ROOT PASSWOD
    
    VALIDATE PASSWORD PLUGIN can be used to test passwords
    and improve security. It checks the strength of password
    and allows the users to set only those passwords which are
    secure enough. Would you like to setup VALIDATE PASSWORD plugin?
    
    Press y|Y for Yes, any other key for No: y
    
    There are three levels of password validation policy:
    
    LOW    Length >= 8
    MEDIUM Length >= 8, numeric, mixed case, and special characters
    STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
    
    Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
    Using existing password for root.
    
    Estimated strength of the password: 50 
    Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
    
     ... skipping.
    By default, a MySQL installation has an anonymous user,
    allowing anyone to log into MySQL without having to have
    a user account created for them. This is intended only for
    testing, and to make the installation go a bit smoother.
    You should remove them before moving into a production
    environment.
    
    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    Success.
    
    
    Normally, root should only be allowed to connect from
    'localhost'. This ensures that someone cannot guess at
    the root password from the network.
    
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    Success.
    
    By default, MySQL comes with a database named 'test' that
    anyone can access. This is also intended only for testing,
    and should be removed before moving into a production
    environment.
    
    
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
     - Dropping test database...
    Success.
    
     - Removing privileges on test database...
    Success.
    
    Reloading the privilege tables will ensure that all changes
    made so far will take effect immediately.
    
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    Success.
    
    All done! 

    //=============================================

    对虚拟机优化


    • 替换源

      • sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
      • 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

      "


      • sudo apt-get update #更新列表

    • L(A|N)MP

      • Ngnix

        • sudo apt-get install nginx

        • nginx -v

          nginx version: nginx/1.4.6 (Ubuntu)

        • 测试Nginx

          
              HTTP/1.1 200 OK
              Server: nginx/1.4.6 (Ubuntu)
              Date: Sat, 07 Jan 2017 07:49:41 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

        • sudo apt-get install apache2

        • apache2 -v

          Server version: Apache/2.4.7 (Ubuntu) Server built: Jul 15 2016 15:34:04

        • 测试访问,此时不能访问,因为80端口被nginx占用了,可以先把nginx停掉

          
               HTTP/1.1 200 OK
               Date: Sat, 07 Jan 2017 08:15:26 GMT
               Server: Apache/2.4.7 (Ubuntu)
               Last-Modified: Sat, 07 Jan 2017 07:17:45 GMT
               ETag: "2cf6-5457bee51dd0d"
               Accept-Ranges: bytes
               Content-Length: 11510
               Vary: Accept-Encoding
               Content-Type: text/html`
          
        • 更改端口,将端口设置为8888

          
               HTTP/1.1 200 OK
               Date: Sat, 07 Jan 2017 08:24:15 GMT
               Server: Apache/2.4.7 (Ubuntu)
               Last-Modified: Sat, 07 Jan 2017 07:17:45 GMT
               ETag: "2cf6-5457bee51dd0d"
               Accept-Ranges: bytes
               Content-Length: 11510
               Vary: Accept-Encoding
               Content-Type: text/html`
          
      • Mysql

        • sudo apt-get install mysql-server #服务器端
          • 安装期间会提示输入为mysql设置root密码,我这边不操作,直接enter 不设置密码
        • sudo apt-get install mysql-client #客户端
          • mysql -uroot -p #测试连接库,上面安装服务端没有设置密码,这里直接enter进入
      • php

        • 安装php

          • sudo apt-get install php5-cli
            • php -v
            
                  PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct  3 2016 13:00:37)
                  Copyright (c) 1997-2014 The PHP Group
                  Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
                  with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
            
        • PHP扩展

          • php5-mcrypt
          • php5-mysql
          • php5-gd
        • 支持apache2的php模块

          • sudo apt-get install libapache2-mod-php5
          • 开启rewrite功能
            • sudo a2enmod rewrite
        • 支持nginx fastcgi

          • sudo apt-get install php5-cgi php5-fpm
          • 修改成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
    • 端口转发 为了验证nginx是否按照成功~~

    //========================================

    Vagrant高级配置


    • 0人收藏了本帖
    写点什么...
    • 快速搭建跨平台开发环境 vagrant + virtualbox + box