Ubuntu LNMP 安裝小記


雖然回到家都十一點.
不過既定好的事情都總要做.
不能一天拖一天.但明天還要早起.
所以簡單描述一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# 更新
apt-get update
apt-get dist-upgrade

# 安裝必要環境工具
apt-get install python-software-properties
apt-get install wget

# 刪除原系統中的 Apache
/etc/init.d/apache2 stop
apt-get remove --purge apache2

# 安裝 Nginx 和 MySQL Server 跟 Client
apt-get install nginx
apt-get install mysql-server mysql-client

# 安裝 PHP with FPM 模式,和相關套件
apt-get install php-fpm
apt-get install php-pear php5-curl php5-gd php5-mysql php5-sqlite php5-tidy php5-xmlrpc php5-imagick php5-mcrypt php5-memcached php5-ming php5-xcache
/etc/init.d/php5-fpm restart

# 安裝 FTP 軟件 (個人愛用 Proftpd)
apt-get install proftpd

# 修改 FTP 的配置 (困在自己的Home內,給NoSSH權限登入的驗證等等)
vim /etc/proftpd/proftpd.conf

DefaultRoot ~
RequireValidShell off
DelayEngine off

RootLogin off
UseReverseDNS off
ServerIdent off

# 修改 Nginx 的配置
vim /etc/nginx/nginx.conf

worker_processes 4;

http {
keepalive_timeout 2;
server_tokens off;
}

# 修改預設的 Default site 位置等等
# 更重要的是支持類 apache 的 userdir (~username) 方式
vim /etc/nginx/sites-available/default

server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www;
index index.html index.htm index.php;

server_name _;

location / {
try_files $uri $uri/ /index.html;
}

location ~ ^/~([^/]+)/(.+\.php)$ {
if (!-f /home/$1/public_html/$2) {
rewrite ^ 404;
}

alias /home/$1/public_html/$2;

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}

location ~ ^/~([^/]+)(/.*)?$ {
alias /home/$1/public_html$2;
}

location ~ /phpmyadmin(.+\.php)$ {
alias /home/www-data/public_html/phpmyadmin/$1;

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}

location /phpmyadmin {
alias /home/www-data/public_html/phpmyadmin/$1;
index index.php;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

# 更改完設定重開 Nginx 和 Proftpd
/etc/init.d/nginx restart
/etc/init.d/proftpd restart

# 增加一個測試帳號,測試 Proftpd 和 Nginx 的配置是否正確
groupadd tester
useradd -g tester -s /sbin/nologin tester
mkdir -p /home/tester/public_html
chown -Rf tester:tester /home/tester

# 登入 MySQL 裡邊新增一個 test 用戶測試一下
mysql -uroot -p
CREATE USER 'tester'@'localhost' identified by 'testerpasswd';
GRANT ALL PRIVILEGES ON `tester\_%` . * TO 'tester'@'localhost';
exit

# 安裝 Git 版本控制工具
apt-get install git

# 安裝 ZSH Shell 工具,取代原有的 Bash Shell
# 並安裝 command-not-found 插件
apt-get install command-not-found && update-command-not-found
apt-get install zsh
cd ~
wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
chsh -s /bin/zsh
su -

# 編輯 zsh 的 runtime 參數
# 打開 Plugin command-not-found
# 並設定一些常量
vim ~/.zshrc

plugins=(command-not-found git)

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# 安裝 mosh 這個工具,方便控制 ssh 的不斷連線到別的 ssh 裡
add-apt-repository ppa:keithw/mosh
apt-get update
apt-get install mosh

# 安裝 AG 這個比 grep 和 ack 更好的搜尋代碼工具
add-apt-repository ppa:ggreer/ag
apt-get update
apt-get install the-silver-searcher

# 最後執行一次大清理
apt-get clean