一.基本介紹
laravel下載安裝環境配套
Vagrant是一個基於Ruby的工具,用於創建和部署虛擬化開發環境,相當於在windows上面搭建一個服務器,相當於一個系統。
virtualBox相當於vmware.本質上仍然是一個操作系統
說明文件: https://gitee.com/apanly/mooc/tree/master/vagrant
二.下載地址:
01,Virtualbox(v5.1.8)
下載地址:https://www.virtualbox.org/wiki/Download_Old_Builds_5_1
02.vagrant(1.8.6)
下載地址:https://releases.hashicorp.com/vagrant/1.8.6/
(上面兩個軟件一直下一步就好,自己指定目錄會報錯)
windows下載vagrant_1.8.6.msi
mac : dmg結尾
03,XSHELL
04,GIT
三. 基本命令
exit :退出虛擬機
vagrant -v :檢查是否安裝成功
vagrant box list : 查看目前已經有的Box
vagrant box add ubuntu_imooc ubuntu16.01.box :添加一個box,以ubuntu16.01.box爲基礎
vagrant box remove ubuntu_imooc :刪除box
虛擬機:
vagrant init : 初始化配置vagrantfile
vagrant up : 啓動虛擬機
vagrant ssh : ssh登錄虛擬機
vagrant suspend : 掛起虛擬機
vagrant reload : 重啓虛擬機
vagrant halt : 關閉虛擬機
vagrant status : 查看虛擬機狀態
vagrant destroy :刪除虛擬機
三.基本步驟:
01.下載鏡像
檢查: vagrant box list
如果沒有box: cd box
02.添加:vagrant box add ubunt1404 ubuntu1404.box
其中ubuntu1404.box就是上面list列表裏面的
cd ..
mkdir imooc
cd imooc
03.初始化虛擬機配置 vagrant init ubuntu1404
04.啓動虛擬機 vagrant up
四.安裝LNMP
01. 進入虛擬機系統,只有進入了虛擬機系統,才能安裝軟件
首先進入imooc文件夾,裏面會有Vagrantfile這個文件,查看虛擬機是否正在運行,如果沒有,請運行虛擬機
使用命令:vagrant ssh
02.修改下載源
001:sudo cp /etc/apt/sources.list /etc/apt/sources.list.bac
002:將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
003:更新源
sudo apt-get update
004:安裝nginx
001:查看nginx是否存在: apt-cache search nginx
002: 安裝nginx: sudo apt-get install nginx -y
003: 查看nginx是否安裝成功:nginx -v
004:測試是否成功: curl -I 'http://127.0.0.1'
005: 其他命令
001: sudo /etc/init.d/nginx stop
005:安裝Apache
001. sudo apt-get install apache2
002. 檢查是否成功: apache2 -v
003. 啓動: sudo /etc/init.d/apache2 start
重啓: sudo /etc/init.d/apache2 restart
004. 修改端口
|- cd /etc/apache2
|- sudo vim ports.conf
|- sudo /etc/init.d/apache2 restart
005.檢測: curl -I 'http://127.0.0.1:80'
006:安裝mysql
001:安裝服務器端: sudo apt-get install mysql-server
- 這裏不設置密碼,直接enter
002:客戶端: sudo apt-get install mysql-client
- mysql -uroot -p -h127.0.0.1 測試連接庫,上面沒有設置密碼,這裏直接enter進入
007.安裝php
001.安裝命令: sudo apt-get install php5-cli
說明:表示命令行的php, php -v檢查是否安裝成功
002.安裝php擴展
- php5-mcrypt
- php5-mysql
- php5-gd
003. 安裝一個模塊,才能支撐apache和php之間的訪問: sudo apt-get install libapache2-mod-php5
004.fast-cgi 是nginx和php之間的: sudo apt-get install php5-cgi php5-fpm
008. 修改網絡,使用瀏覽器127.0.0.1:8888能夠訪問apache,nginx
001.首先exit退出,然後vagrant suspend掛起虛擬機
002.點上虛擬機,點擊設置,點擊網絡,點擊高級,點擊端口轉發
名稱 | 協議 | 主機IP | 主機端口 | 子系統IP | 子系統端口 |
nginx | TCP | 127.0.0.1 | 8888 |
80 |
apache 127.0.0.1 8889 8888
003. 啓動虛擬機使用:vagrant up 進行啓動 ,訪問:127.0.0.1:8888 ,出現nginx大功告成
測試訪問:
curl -I 'http://127.0.0.1'
五:修改配置文件,將代碼放進去,還有轉發ip
00:vagrant ssh
01: vim Vagrantfile
config.vm.box = "ubunt1404"
config.vm.network "forwarded_port" ,guest:80,host:8888
config.vm.network "forwarded_port" ,guest:8888,host:8889
config.vm.synced_folder "D:\demo" ,"/home/www",:nfs=>true
config.vm.network "private_network", ip:"192.168.199.101"
02: 重新加載 : vagrant reload
03.在conf下面重寫server
server{
server_name tp5.imooc.test;
root /home/www/imooc/tp5/public;
index index.php index.html;
location / {
if ( -f $request_filename ){
break;
}
if ( !-e $request_filename ){
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
try_files $uri = 404;
}
}
03:查錯: tail -f
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
03-1:
cd /etc/php5/fpm/
cd pool.d
; listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
sudo service php5-fpm restart