Skip to content

Commit

Permalink
add the linux install lnmp
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 7, 2014
1 parent 284aafd commit dee93d8
Show file tree
Hide file tree
Showing 16 changed files with 1,303 additions and 806 deletions.
Binary file modified build/designiot.epub
Binary file not shown.
568 changes: 343 additions & 225 deletions build/designiot.mobi

Large diffs are not rendered by default.

Binary file modified build/iot.pdf
Binary file not shown.
551 changes: 331 additions & 220 deletions build/pdf.html

Large diffs are not rendered by default.

Binary file added images/box-model.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dom_tree.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/edit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
551 changes: 331 additions & 220 deletions index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/1.1.anywhere-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

从html开始的原因在于我们不需要去配置一个复杂的开发环境,也许你还不知道开始环境是什么东西,而这些需要去慢慢的了解才能接触,特别是对于普通的业余爱好者来说,对于专业的选手那些自然不是问题。HTML是Web的核心语言,也算是基础的语言。

##html的hello,world##
##html的hello,world
Hello,world是一个传统,所以在这里也遵循这个有趣的传统,我们所要做的事情事实很简单。虽然也有点hack的感觉,所以让我们新建一个文件叫"helloworld.html"。

(PS:大部分人应该都是在windows下工作的,所以你需要新建一个文本,然后重命名,或者你需要一个编辑器,在这里推荐用<strong>sublime text</strong>。破解不破解,注册不注册都不会对你的使用有太多的影响。)
Expand Down
33 changes: 32 additions & 1 deletion src/1.4.anywhere-hjc.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
##从源码学习##
过去总会觉得学了一种语言的语法便算是学了一种语言,于是有一天发现到了这个语言的项目上的时候,虽然会写上几行代码,但是却不像这语言的风格。于是这也是这一篇的意义所在了:

##浏览器渲染过程

###HTML###
写好HTML的一个要点在于看别人写的代码,这只是一方面,我们所说的HTML方面的内容可能不够多,原因有很多,很多东西都需要在实战中去解决。读万卷书和行万里路,分不清哪个有重要的意义,但是如果可以同时做好两个的话,成长会很快的。

Expand Down Expand Up @@ -49,6 +51,10 @@

##DOM树形结构图##

> DOM是文档对象化模型(Document Object Model)的简称。DOM Tree是指通过DOM将HTML页面进行解析,并生成的HTML tree树状结构和对应访问方法。
![DOM Tree](./images/dom_tree.jpg)

###javascript###
这里以未压缩的jQuery源码和zepto.js作一个小小的比较,zepto.js是兼容jQuery的,因此我们举几个有意思的函数作一简单的比较,关于源码可以在官网上下载到。

Expand Down Expand Up @@ -175,7 +181,32 @@ a[href^="#"]:after {

其他的还需要去好好了解的就是**CSS的盒模型**,作为CSS的基石之一。

##CSS盒模型图##
##CSS盒模型图

(ps:以下内容来自于Mozilla Developer NetWorks)

CSS下这些矩形盒子由标准盒模型描述。这个模型描述元素内容占用空间。盒子有四个边界:外边距边界margin edge, 边框边界border edge, 内边距边界padding edge 与 内容边界content edge。

![CSS Box Model](./images/box-model.gif)


内容区域content area 是真正包含元素内容的区域。位于内容边界的内部,它的大小为内容宽度 或 content-box宽及内容高度或content-box高。

如果 box-sizing 为默认值, width, min-width, max-width, height, min-height 与 max-height 控制内容大小。

内边距区域padding area 用内容及可能的边框之间的空白区域扩展内容区域。它位于内边距边界内部,通常有背景——颜色或图片(不透明图片盖住背景颜色). 它的大小为 padding-box 宽与 padding-box 高。

内边距与内容边界之间的空间可以由 padding-top, padding-right, padding-bottom, padding-left 和简写属性 padding 控制。

边框区域border area 是包含边框的区域,扩展了内边距区域。它位于边框边界内部,大小为 border-box 宽和 border-box 高。由 border-width 及简写属性 border控制。

外边距区域margin area用空白区域扩展边框区域,以分开相邻的元素。它的大小为 margin-box 的高宽。

外边距区域大小由 margin-top, margin-right, margin-bottom, margin-left 及简写属性 margin 控制。

在 外边距合并 的情况下,由于盒之间共享外边距,外边距不容易弄清楚。

最后注意,对于行内非替换元素,其占用空间(行高)由 line-height 决定,即使有内边距与边框。

诸如

Expand Down
148 changes: 148 additions & 0 deletions src/1.5.linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,151 @@ Linux 下的软件包通常是以下三种格式:
- rpm - 此格式由 Red Hat Linux 所创建,并经由 LSB 标准化,现已为众多 Linux 发行版所采用,是一个优秀的软件包格式。openSUSE 即是用此格式。更多信息可以参阅此处。

> 所以这就需要能自动解决依赖关系的软件包管理器。软件包管理系统就是一个工具集,为系统提供一个统一的安装、升级、删除软件的方式。
##Ubuntu LNMP

在余下的章节中,我们需要去部署,需要去使用Ubuntu。如果在Windows下可以使用LAMP,但是在这里我们只说Ubuntu。开始之前你需要安装好Ubuntu,无论是在虚拟机,还是在真机安装,或者是Docker。

###Update软件包列表

``apt-get``是debian,ubuntu发行版的包管理工具。``apt-get update``可以确保我们的软件包列表是最新的,下面是一个简单的更新过程。

打开Terminal或者Konsole等等之类的终端控制台。

```bash
root@70cdc7a176a5:/# sudo apt-get update
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
Ign http://archive.ubuntu.com trusty-security InRelease
Ign http://archive.ubuntu.com trusty-proposed InRelease
Get:1 http://archive.ubuntu.com trusty Release.gpg [933 B]
Get:2 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]
Get:3 http://archive.ubuntu.com trusty-security Release.gpg [933 B]
Get:4 http://archive.ubuntu.com trusty-proposed Release.gpg [933 B]
Get:5 http://archive.ubuntu.com trusty Release [58.5 kB]
Get:6 http://archive.ubuntu.com trusty-updates Release [62.0 kB]
Get:7 http://archive.ubuntu.com trusty-security Release [62.0 kB]
Get:8 http://archive.ubuntu.com trusty-proposed Release [209 kB]
Get:9 http://archive.ubuntu.com trusty/main Sources [1335 kB]
Get:10 http://archive.ubuntu.com trusty/restricted Sources [5335 B]
Get:11 http://archive.ubuntu.com trusty/universe Sources [7926 kB]
Get:12 http://archive.ubuntu.com trusty/main amd64 Packages [1743 kB]
Get:13 http://archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB]
Get:14 http://archive.ubuntu.com trusty/universe amd64 Packages [7589 kB]
64% [14 Packages 664 kB/7589 kB 9%] 58.3 kB/s 1min 58s
```

更新完应该会显示:

```bash
Fetched 20.5 MB in 5min 22s (63.6 kB/s)
Reading package lists... Done
```

###安装MySQL

安装命令

```bash
sudo apt-get install mysql-server php5-mysql
```
过程:

```bash
root@70cdc7a176a5:/# sudo apt-get install mysql-server php5-mysql
Reading package lists... 0%
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18
libterm-readkey-perl libwrap0 lsof mysql-client-5.5 mysql-client-core-5.5
mysql-common mysql-server-5.5 mysql-server-core-5.5 php5-common php5-json
psmisc tcpd
Suggested packages:
libclone-perl libmldbm-perl libnet-daemon-perl libplrpc-perl
libsql-statement-perl libipc-sharedcache-perl tinyca mailx php5-user-cache
The following NEW packages will be installed:
libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18
libterm-readkey-perl libwrap0 lsof mysql-client-5.5 mysql-client-core-5.5
mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 php5-common
php5-json php5-mysql psmisc tcpd
0 upgraded, 19 newly installed, 0 to remove and 12 not upgraded.
Need to get 9982 kB of archives.
After this operation, 99.1 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libaio1 amd64 0.3.109-4 [6364 B]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main mysql-common all 5.5.40-0ubuntu0.14.04.1 [14.1 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libmysqlclient18 amd64 5.5.40-0ubuntu0.14.04.1 [598 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty/main libwrap0 amd64 7.6.q-25 [46.2 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ trusty/main libdbi-perl amd64 1.630-1 [879 kB]
Get:6 http://archive.ubuntu.com/ubuntu/ trusty/main libdbd-mysql-perl amd64 4.025-1 [99.3 kB]
Get:7 http://archive.ubuntu.com/ubuntu/ trusty/main libterm-readkey-perl amd64 2.31-1 [27.4 kB]
Get:8 http://archive.ubuntu.com/ubuntu/ trusty-updates/main mysql-client-core-5.5 amd64 5.5.40-0ubuntu0.14.04.1 [703 kB]
Get:9 http://archive.ubuntu.com/ubuntu/ trusty-updates/main mysql-client-5.5 amd64 5.5.40-0ubuntu0.14.04.1 [1466 kB]
Get:10 http://archive.ubuntu.com/ubuntu/ trusty-updates/main mysql-server-core-5.5 amd64 5.5.40-0ubuntu0.14.04.1 [3215 kB]
47% [10 mysql-server-core-5.5 850 kB/3215 kB 26%] 79.9 kB/s 1min 6s
```

在安装的过程中会要求你输入数据库密码。(默认为空)

###安装Nginx

```bash
echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nginx-stable.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
sudo apt-get update
sudo apt-get install nginx
```

启动Nginx Server

```bash
sudo service nginx start
```

###安装PHP

sudo apt-get install php5-fpm

安装过程

```bash
root@70cdc7a176a5:/# sudo apt-get install php5-fpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libsystemd-daemon0
Suggested packages:
php-pear
The following NEW packages will be installed:
libsystemd-daemon0 php5-fpm
0 upgraded, 2 newly installed, 0 to remove and 12 not upgraded.
Need to get 2201 kB of archives.
After this operation, 9326 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty-proposed/main libsystemd-daemon0 amd64 204-5ubuntu20.8 [9608 B]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe php5-fpm amd64 5.5.9+dfsg-1ubuntu4.5 [2191 kB]
Fetched 2201 kB in 1min 5s (33.6 kB/s)
Selecting previously unselected package libsystemd-daemon0:amd64.
(Reading database ... 13105 files and directories currently installed.)
Preparing to unpack .../libsystemd-daemon0_204-5ubuntu20.8_amd64.deb ...
Unpacking libsystemd-daemon0:amd64 (204-5ubuntu20.8) ...
Selecting previously unselected package php5-fpm.
Preparing to unpack .../php5-fpm_5.5.9+dfsg-1ubuntu4.5_amd64.deb ...
Unpacking php5-fpm (5.5.9+dfsg-1ubuntu4.5) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up libsystemd-daemon0:amd64 (204-5ubuntu20.8) ...
Setting up php5-fpm (5.5.9+dfsg-1ubuntu4.5) ...

Creating config file /etc/php5/fpm/php.ini with new version
php5_invoke: Enable module pdo for fpm SAPI
php5_invoke: Enable module pdo_mysql for fpm SAPI
php5_invoke: Enable module opcache for fpm SAPI
php5_invoke: Enable module json for fpm SAPI
php5_invoke: Enable module mysql for fpm SAPI
php5_invoke: Enable module mysqli for fpm SAPI
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for libc-bin (2.19-0ubuntu6.3) ...
Processing triggers for ureadahead (0.100.0-16) ...
```
24 changes: 12 additions & 12 deletions src/1.6.arduino.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void loop(){
}
```

"setup()"函数用于初始化(如GPIO初始化,串口初始化,定时器初始化等)特点是只执行一次;"loop()"函数是一个死循环,可以看做C语言的"while(1)"函数。
``setup()``函数用于初始化(如GPIO初始化,串口初始化,定时器初始化等)特点是只执行一次;``loop()``函数是一个死循环,可以看做C语言的``while(1)``函数。

##点亮一个LED##

Expand Down Expand Up @@ -60,23 +60,23 @@ void loop()
}
```

该程序实现Arduino单片机13号引脚以1S时间电平翻转,如果外接一个led,就可以看到led以1S的间隔闪烁;函数"pinMode()"有两个参数pin、value,pin参数用来指定引脚号,本程序中设置为13号引脚,mode用于设置引脚模式,有三个值:
该程序实现Arduino单片机13号引脚以1S时间电平翻转,如果外接一个led,就可以看到led以1S的间隔闪烁;函数``pinMode()``有两个参数pin、value,pin参数用来指定引脚号,本程序中设置为13号引脚,mode用于设置引脚模式,有三个值:

- "INPUT"
- "OUTPUT"
- "INPUT_PULLUP"
- ``INPUT``
- ``OUTPUT``
- ``INPUT_PULLUP``

表示让某一个IO引脚作输入,反之,

- "OUTPUT"则使一个IO引脚做输出
- "INPUT_PULLUP"则配置一个IO引脚具有上拉输入功能(上拉电阻的目的是为了保证在无信号输入时输入端的电平为高电平),从英文意思也能很直观的看出来。
- ``OUTPUT``则使一个IO引脚做输出
- ``INPUT_PULLUP``则配置一个IO引脚具有上拉输入功能(上拉电阻的目的是为了保证在无信号输入时输入端的电平为高电平),从英文意思也能很直观的看出来。

理解了"pinMode()"函数,"digitalWrite()"就很容易理解啦,value的取值有两个"HIGH"、"LOW","HIGH"表示让某一个引脚输出高电平,反之,"LOW"则使某一个引脚输出低电平。
程序中还是用到"delay(ms)"函数,它表示延时多少毫秒,例如延时500 ms ,直接调用"delay(500);"就可以了。
理解了``pinMode()``函数,``digitalWrite()``就很容易理解啦,value的取值有两个``HIGH````LOW``,``HIGH``表示让某一个引脚输出高电平,反之,``LOW``则使某一个引脚输出低电平。
程序中还是用到``delay(ms)``函数,它表示延时多少毫秒,例如延时500 ms ,直接调用``delay(500);``就可以了。

如果你仔细查看我的描述,你会发现我没有讲13号引脚怎么来的,是这样的:Arduino团队为了简化对引脚描述,对每个引脚都进行了编号,以UNO开发板为例,可以发现开发板排座的附近有对应的白颜色的数字,那便是所有的引脚编号,A0~A5是6路ADC输入引脚,0-13表示13路基本IO,数字前面的"~"表示该引脚具有PWM功能。如果要使用某一引脚,只要知道引脚编号就可行操作
如果你仔细查看我的描述,你会发现我没有讲13号引脚怎么来的,是这样的:Arduino团队为了简化对引脚描述,对每个引脚都进行了编号,以UNO开发板为例,可以发现开发板排座的附近有对应的白颜色的数字,那便是所有的引脚编号,A0~A5是6路ADC输入引脚,0-13表示13路基本IO,数字前面的``~``表示该引脚具有PWM功能。如果要使用某一引脚,只要知道引脚编号就可行操作

例如"digitalWrite(2,LOW)"表示向2号引脚输出低电平。其他操作类似,是不是so easy ^-^ !
例如``digitalWrite(2,LOW)``表示向2号引脚输出低电平。其他操作类似,是不是so easy ^-^ !

##串口通信##

Expand All @@ -86,7 +86,7 @@ void loop()
+ Serial.read()
+ Serial.available()

在此项目中需要使用串口,Arduino串口初始化使用"Serial.begin(9600);",其传输波特率为9600,其他波特率也行,函数位于"setup()"中,之后可以使用"Serial.read()"、"Serial.write()"读入一个字符,输出一个字符,使用"Serial.print()"输出字符串.代码如下:
在此项目中需要使用串口,Arduino串口初始化使用``Serial.begin(9600);``,其传输波特率为9600,其他波特率也行,函数位于``setup()``中,之后可以使用``Serial.read()````Serial.write()``读入一个字符,输出一个字符,使用``Serial.print()``输出字符串.代码如下:

```cpp
char ch='1';
Expand Down
2 changes: 1 addition & 1 deletion src/2.1.restful.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

###资源

互联网上的一切信息都可以看作是一种资源。
互联网上的一切信息都可以看作是一种资源。

0 comments on commit dee93d8

Please sign in to comment.