通过YUM源安装nginx+mysql+php-fpm+eaccelerator

论坛: 

一、LNMP安装
Linux系统用centos 6.3,nginx 1.2.5,mysql5.5,php5.3.18。都是当前最新稳定版本。
1、YUM软件更新

yum update

2、安装LNMP

yum install nginx-stable 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 '密码'

PS:如果启动报错,先设置完2.2里的内存优化再启动。

2.1.1 、用root登录mysql的命令是

#mysql -u root -p

2.2、编码和内存优化设置。编码都设为utf-8,

#vi /etc/my.cnf

添加下面内容:

复制代码
[client]
default-character-set=utf8
 
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
#去掉innodb,使用MyISAM,内存占用会少很多
default-storage-engine =MyISAM
skip-innodb
复制代码

重启mysql:

#service mysql restart

现在用root登录并查看mysql字符编码:

mysql> status;

应该有类似下面显示的内容:

Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8

可见字符编码都已经是utf8了。
2.3 、创建一个名为wordpress的数据库,为下面安装wordpress做装备。

mysql> create database wordpress;

给数据库”wordpress”授权,使用户名为”wp”,操作权限是localhost,登录密码是”wppasswd”

mysql> grant all on wordpress.* to wp@localhost identified by 'wppasswd'

显示 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安装设置完毕。