vagrant的学习 之 LNMP和LAMP
vagrant的学习 之 LNMP和LAMP
本文根据慕课网的视频教程练习,感谢慕课网!
慕课的参考文档地址:https://github.com/apanly/mooc/tree/master/vagrant。
(1)安装nginx:
搜索nginx:
apt-cache search nginx
安装nginx:
sudo apt-get install nginx
查看nginx版本,检测是否安装成功:
vagrant@vagrant-ubuntu-trusty:/etc/apt$ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)
测试nginx,查看是否成功,,执行 curl 127.0.0.1:
vagrant@vagrant-ubuntu-trusty:/etc/apt$ curl '127.0.0.1'
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
如果执行时加上参数 -I,则返回如下:
vagrant@vagrant-ubuntu-trusty:/etc/apt$ curl -I '127.0.0.1'
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 29 Aug 2018 07:09:14 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
证明安装成功!
(2)安装apache:
sudo apt-get install apache2
会有一些错误,是80端口被刚安装的nginx占用了,启动失败:
* Starting web server apache2 ()Address already in use: AH00072: make_sock: could not bind to address [::]:
()Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:
no listening sockets available, shutting down
AH00015: Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
*
* The apache2 instance did not start within seconds. Please read the log files to discover problems
invoke-rc.d: initscript apache2, action "start" failed.
Setting up ssl-cert (1.0.) ...
Processing triggers for libc-bin (2.19-0ubuntu6) ...
Processing triggers for ufw (0.34~rc-0ubuntu2) ...
Processing triggers for ureadahead (0.100.-) ...
停掉nginx服务:
sudo /etc/init.d/nginx stop
启动apache服务:
sudo /etc/init.d/apache2 start
然后测试apache,服务安装成功!
vagrant@vagrant-ubuntu-trusty:/etc/apt$ curl -I 'http://127.0.0.1'
HTTP/1.1 OK
Date: Wed, Aug :: GMT
Server: Apache/2.4. (Ubuntu)
Last-Modified: Wed, Aug :: GMT
ETag: "2cf6-5748dbfa366e3"
Accept-Ranges: bytes
Content-Length:
Vary: Accept-Encoding
Content-Type: text/html
(3)安装mysql:
安装服务端:
sudo apt-get install mysql-server
过程中需要设置数据库的root的密码。
安装客户端:
sudo apt-get install mysql-client
测试mysql是否安装成功:
mysql -uroot -p
然后输入密码,连接mysql成功!
查看mysql版本:
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.5.61-0ubuntu0.14.04.1 |
+-------------------------+
1 row in set (0.00 sec)
输入 exit 退出,继续安装下一软件。
(4)安装PHP:
sudo apt-get install php5-cli
使用php -v查看php版本:
vagrant@vagrant-ubuntu-trusty:~$ php -v
PHP 5.5.-1ubuntu4. (cli) (built: May ::)
Copyright (c) - The PHP Group
Zend Engine v2.5.0, Copyright (c) - Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) -, by Zend Technologies
安装php扩展:
sudo apt-get install php5-mcrypt
sudo apt-get install php5-mysql
sudo apt-get install php5-gd
(5)配置apache支持php
sudo apt-get install libapache2-mod-php5
(6)配置nginx支持php
sudo apt-get install php5-cgi php5-fpm
查看apache 是否在启动状态:
ps -ef | grep apache
查看nginx 是否在启动状态:
ps -ef | grep nginx
修改apache的默认端口为8888:
sudo vim /etc/apache2/ports.conf
重启apache:
sudo /etc/init.d/apache2 restart
这样两个服务可以同时运行。
配置端口转发:
注意:前提是虚拟机里的ip不是静态地址,不然无法配置端口转发。
打开本地文件 Vagrantfile,
找到:config.vm.box = "ubuntu1404"
在后边添加:
config.vm.network "forwarded_port" ,guest:80,host:8888
config.vm.network "forwarded_port" ,guest:8888,host:8889
含义为:
本地主机访问8888端口,对应的虚拟机的端口为80端口(刚配置的nginx端口为80),
本地主机访问8889端口,对应的虚拟机的端口为8888端口(刚配置的apache端口为8888),
执行vagrant reload 重启虚拟机,
可以看到如下内容:
==> default: Forwarding ports... default: 80 (guest) => 8888 (host) (adapter 1)
default: 8888 (guest) => 8889 (host) (adapter 1)
这样就可以在本机上
使用127.0.0.1:8888访问虚拟机的nginx服务,
使用127.0.0.1:8889访问虚拟机的apache服务。
虚拟机的【设置】-->【网络】-->【高级】-->【端口转发】就会自动出现如下信息:

如果先去这个地方配置,则只会生效一次,重启之后就没了,通过文件配置,可以一直生效。
配置共享目录(未成功,略过)
打开本地文件 Vagrantfile,增加共享同步的配置:
config.vm.synced_folder "D:/study/web/","/home/www",:nfs=>true
vagrant的学习 之 LNMP和LAMP的更多相关文章
- vagrant的学习 之 打包分发
vagrant的学习 之 打包分发 一.打包Box: (1)关闭虚拟机. vagrant halt (2)打包: vagrant package 这样打包出来的文件叫package.box. 指定生成 ...
- lnmp、lamp、lnmpa一键安装包(Updated: 2015-10-25)
lnmp.lamp.lnmpa一键安装包(Updated: 2015-10-25) 2014-12-26 Posted by yeho 这个脚本是使用shell编写,为了快速在生产环境上部署lnmp/ ...
- LNMP 与 LAMP 架构的区别及配置解决方案
2014-12-31 10:33| 发布者: digitser| 查看: 5618| 评论: 0|原作者: liangsheng 摘要: LNMP 与 LAMP 架构的区别及配置解决方案 LNMP 的 ...
- lnmp、lamp、lnmpa一键安装包(Updated: 2016-4-12)
lnmp.lamp.lnmpa一键安装包(Updated: 2016-4-12) 文章目录 脚本特性 安装步骤 如何添加虚拟主机? 如何删除虚拟主机? 如何管理ftp账号? 数据备份 如何管理服务 ...
- vagrant的学习之Git学习
vagrant的学习之Git学习 参考学习网址: http://www.runoob.com/git/git-install-setup.html. http://www.bootcss.com/p/ ...
- vagrant的学习 之 优化
vagrant的学习 之 优化 一.修改虚拟机名字: 默认的虚拟机的名字很长:study_default_1535505004652_97747. (1)打开Vagrantfile文件:(2)找到: ...
- vagrant的学习 之 Laravel
vagrant的学习 之 Laravel 本文根据慕课网的视频教程练习,感谢慕课网! 慕课视频学习地址:https://www.imooc.com/video/14218. 慕课的参考文档地址:htt ...
- vagrant的学习 之 Yii2
vagrant的学习 之 Yii2 本文根据慕课网的视频教程练习,感谢慕课网! 慕课视频学习地址:https://www.imooc.com/video/14218. 慕课的参考文档地址:https: ...
- vagrant的学习 之 ThinkPHP3.2
vagrant的学习 之 ThinkPHP3.2 (1)在web目录下新建tp32目录: cd /home/www/ mkdir tp32 (2)下载框架 我从ThinkPHP官网下载了ThinkPH ...
随机推荐
- linux下常用网络操作汇总 专题
centos 更改主机名,需要更改的几个地方: (1) /etc/sysconfig/network //更改主机名(2)/etc/hostname //更改主机名(3) /etc/hosts ...
- Android开发学习--MVP模式入门
1.模型与视图完全分离,我们可以修改视图而不影响模型2.可以更高效地使用模型,因为所有的交互都发生在一个地方——Presenter内部3.我们可以将一个Presenter用于多个视图,而不需要改变Pr ...
- $.extend(x,y); 函数用法介绍。
第一篇资料: 转自: https://www.cnblogs.com/yuqingfamily/p/5813650.html 语法:jQuery.extend( [deep ], target, o ...
- R in action读书笔记(10)-第八章:回归-- 异常观测值 改进措施
8.4 异常观测值 8.4.1 离群点 car包也提供了一种离群点的统计检验方法.outlierTest()函数可以求得最大标准化残差绝对值Bonferroni调整后的p值: > library ...
- uoj #15. 【NOIP2014】生活大爆炸版石头剪刀布
石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一 样,则不分胜负.在<生活大爆炸>第二季第 8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的石头剪 ...
- Leetcode_638.Shopping Offers
https://leetcode.com/problems/shopping-offers/ In LeetCode Store, there are some kinds of items to s ...
- viewer && ImageFlow 图片滚动组件 图片点击放大 可以滚轮放大缩小 viewer
ImageFlow https://finnrudolph.com/products/imageflow https://github.com/countzero/ImageFlow http://w ...
- console.log()与console.dir()
console.log()可以取代alert()或document.write(),在网页脚本中使用console.log()时,会在浏览器控制台打印出信息. console.dir()可以显示一个对 ...
- No-1.第一个 Python 程序
1. 第一个 HelloWorld 程序 1.1 Python 源程序的基本概念 Python 源程序就是一个特殊格式的文本文件,可以使用任意文本编辑软件做 Python 的开发 Python 程序的 ...
- P2P实现的原理
为了项目的后期IM应用,最近在研究libjingle,中间看了也收集了很多资料,感慨网上很多资料要么太过于纠结协议(如STUN.ICE等)实现细节,要么中间有很多纰漏.最后去伪存真,归纳总结了一下,希 ...