一、LNMP安装
Linux系统用centos 6.4,nginx 1.2.7,mysql5.1.67,php5.3.3。都是当前最新稳定版本。
1、添加YUM软件源并更新
#rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
#yum update
2、安装LNMP
# yum install nginx php-fpm php-mysql mysql-server php-mbstring php-gd php-pear php-mcrypt php-mhash php-eaccelerator php-suhosin php-tidy php-curl
二、LNMP设置
1、设置mysql、nginx、php-fpm开机自动启动
# chkconfig nginx on
# chkconfig mysqld on
# chkconfig php-fpm on
2、mysql设置
2.1、设置mysql密码
#service mysqld start
#mysqladmin -u root password '密码'
用root登录mysql的命令是
#mysql -u root -p
重启mysql:
#service mysql restart
2.2 、创建一个名为wordpress的数据库,为下面安装wordpress做装备。
mysql> create database wordpress;
给数据库”wordpress”授权,使用户名为”wpuser”,操作权限是localhost,登录密码是”wp123456”
mysql> grant all on wordpress.* to wpuser@localhost identified by 'wp123456'
显示 Query OK, 0 rows affected (0.00 sec),表示操作已成功。
3、php-fpm设置
centos 6的php-fpm默认是配合apache用的,需要改成nginx。
# vi /etc/php-fpm.d/www.conf
找到以下两行:
user = apache
group = apache
将其中的apache都改为nginx。
4、nginx设置
4.1、修改nginx配置文件
# vi /etc/nginx/nginx.conf
更改网站的根目录,添加php默认文件:
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
#启用伪静态规则,可以支持自定义链接和日志别名
if (!-e $request_filename)
{
rewrite ^/(.+)$ /index.php last;
}
}
修改代码,添加php-fpm支持
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
删除上面所有行的#和其中带root那一行,修改网站目录和前面一致。
4.2、重启php-fpm和nginx服务
# service nginx start
# service php-fpm start
至此,lnmp安装设置完毕。
上传wordpress文件至 /usr/share/nginx/html/,并设置权限为711即可,注意html目录及其下面的所有文件属主为nginx,组为nginx。
补充:Nginx下WordPress伪静态规则设置
1. 打开nginx配置文件:
# vim /etc/nginx/nginx.conf(此路径根据Linux版本与安装路径会有不同)
2. 在server容器中添加下面这几行
location /
{
try_files $uri $uri/ /index.php?q=$uri&$args;
}
3. 重新加载nginx配置文件
# /etc/init.d/nginx reload
完成设置。