前言

又到了写博客的时间,今天总结一下在ubuntu 14.04 x86下配置LNMP及wordpress,环境是我们上一篇中已经安装好的,如果没有像上文一样配置过的话,请注意修改系统的LL_ALL与LC_CTYPE,不然会卡在MySQL的安装上,最后尽管只安装了这么少的东西,128mb内存的压力依旧巨大,这里只复习下配置过程,写博客什么的,还是呆在这个域名里就好。所以配置完后,拍个快照,就恢复到只安装了ss的状态。

安装

步骤:

1.安装配置MySQL与php5-mysql

2.安装配置nginx与php-fpm

3.下载wordpress,配置路径

4.安装配置phpmyadmin

5.配置wordpress

相关依赖会自动安装

命令:

apt-get install mysql-server php5-mysql

输出如下

 

lnmp00

 

安装后会提示输入MySQL的root密码,因为已经配置好语言环境,所以不用担心乱码了。

然后是nginx与php-fpm

apt-get install nginx php-fpm

这里不列出自动安装的依赖了,安装完成后,直接访问vps的ip地址就可以看到index.html了,接下来开始配置

修改/etc/php5/fpm/php.ini,将cgi.fix_pathinfo注释解除设置为0

 

lnmp01

 

vim的搜索技巧

在命令模式下按/或者?可以向下或者向上搜索,输入匹配单词后按回车确认,接下来按n可以找到下一个匹配项目

然后修改/etc/php5/fpm/pool.d/www.conf 

user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
lnmp02
PHP配置完成,接下来是nginx的配置
修改/etc/nginx/sites-available/default,它的默认内容如下
 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
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;root /usr/share/nginx/html;
index index.html index.htm;# Make site accessible from http://localhost/
server_name localhost;location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

去掉所有注释后如下,可以看到仅仅配置了根目录与错误404页面

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;

location / {
try_files $uri $uri/ =404;
}
}

让我们首先在域名解析处绑定好一个域名(banwa.wbuntu.com)到服务器,然后再具体配置如下

先下载wordpress

wget http://wordpress.org/latest.tar.gz

解压

tar -zxvf latest.tar.gz

创建文件夹,复制文件,最后修改权限

mkdir -p /var/www

cp -r ~/wordpress/* /var/www

chown –R www-data:www-data /var/www

接下来配置/etc/nginx/sites-available/default

 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
server {

listen   80;

root /var/www;

index index.php index.html index.htm;

server_name banwa.wbuntu.com;

location / {

try_files $uri $uri/ /index.php?q=$uri&$args;

}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ \.php$ {

try_files $uri =404;

#fastcgi_pass 127.0.0.1:9000;

# With php5-fpm:

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

}
}
完成后重启nginx与php-fpm
service nginx restart

service php5-fpm restart

现在可以访问了

最后是安装phpmyadmin,对sql熟悉的同学可以手工配置,这里为了方便,我使用phpmyadmin配置wordpress数据库。

apt-get install phpmyadmin

中间会出现三个提示,我们使用默认设置,然后输入MySQL的root密码,并设定一个给phpmyadmin用于注册MySQL的密码,不填的话会随机生成

lnmp03

最后弹出选择web server的选项,这里一直不明白,居然没nginx的选项,我就直接回车,居然默默正常设置完了……
lnmp04
还要建立软连接
ln -s /usr/share/phpmyadmin /var/www

输入MySQL的root密码

lnmp05

在右侧菜单上选择用户

lnmp07

然后添加用户

lnmp06

最后执行

接下来访问http://banwa.wbuntu.com/wp-admin/install.php开始安装,填入刚才创建的用户名,主机与密码,安装到此结束