(转)CentOS下用yum搭建LNMP服务器

原文链接:http://www.xiaohuai.com/2733

CentOS下搭服务器也折腾好几次了, 每次都知道个大概, 具体repo的地址什么的还都要现找, 实在不效率, 干脆整理记录下来.

yum安装比较简单快捷, 但默认配置的安全和性能方面不如LNMP一键安装包. 推荐生产环境用一键安装包

如果你在国内的话, 先替换CentOS-Base.repo

  1. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  2. # 如果是CentOS 5.*
  3. wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
  4. # 如果是CentOS 6.*
  5. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
  6. yum makecache

如果之前有apache, 卸载

  1. yum remove httpd

更新软件到最新版本

  1. yum -y update

安装源

  1. # 如果是CentOS 5.*
  2. rpm -ivh http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm
  3. rpm -ivh http://mirrors.sohu.com/fedora-epel/5/i386/epel-release-5-4.noarch.rpm
  4. rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
  5. # 如果是CentOS 6.*
  6. rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
  7. rpm -ivh http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm(zsm:这一步文件的版本可能有更新,可以根据链接去查看最新的安装)
  8. rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

编辑启用remi源

  1. vi /etc/yum.repos.d/remi.repo
  2. # 将[remi]下的enabled=0改为enabled=1
  3. # 按esc
  4. # :x回车

执行安装, 根据需要增减要安装的php模块

  1. yum install nginx mysql mysql-server php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy

启动nginx, php-fpm, mysqld

  1. service nginx restart
  2. service php-fpm restart
  3. service mysqld restart

设置自动启动

  1. chkconfig nginx on
  2. chkconfig php-fpm on
  3. chkconfig mysqld on

mysql密码设置

  1. mysql_secure_installation

至于目录权限管理什么的, 就不写了.

niginx配置文件在/etc/nginx/nginx.conf
php-fpm配置文件在/etc/php-fpm.conf
php配置文件/etc/php.ini
mysql配置文件/etc/my.cnf

--------------------------------------

mysql文件夹位置:/var/lib/mysql;

mysql错误日志位置:/var/log/mysql.log;

参考文章:

http://www.ppkj.net/2011/11/18/centos6-yum-%E6%90%AD%E5%BB%BAlinux-nginx-php-mysql-lnmp/

http://www.centos.bz/2011/03/yum-install-nginx-mysql-php-fastcgi-lnmp/

posted on 2014-02-02 00:59  BuildyMan  阅读(197)  评论(0编辑  收藏  举报

导航