一、LNMP环境搭建前的准备

    LNMP就是Linux系统下Nginx+MySQL+PHP这种网站服务器架构,所以需要下载mysql,php,与nginx这三套软件。

    MySQL :

          32位 :http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

          64位 :http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz         

    PHP :http://cn2.php.net/distributions/php-5.3.28.tar.gz

    Nginx :http://nginx.org/download/nginx-1.6.2.tar.gz

    软件镜像下载地址

    关闭selinux

    安装库文件

    yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libtiff-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel fontconfig-devel zlib zlib-devel libevent-devel gcc gcc-c++ flex bison bzip2-devel libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

    

二、MySQL的安装

    MySQL的安装方法与LAMP中的MySQL安装方法一样,具体操作方法请参考LAMP的环境搭建:

三、PHP的安装

    1、编译

[root@LNMP php-5.4.22]# ./configure --prefix=/usr/local/php   --with-config-file-path=/usr/local/php/etc  --enable-fpm   --with-fpm-user=php-fpm  --with-fpm-group=php-fpm   --with-mysql=/usr/local/mysql  --with-mysql-sock=/tmp/mysql.sock  --with-libxml-dir  --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir  --with-iconv-dir   --with-zlib-dir   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-ftp  --enable-mbstring  --enable-exif    --disable-ipv6     --with-curl

[root@LNMP php-5.4.22]# make

[root@LNMP php-5.4.22]# make install

    2、配置

# 添加用户[root@ZLNMP ~]# useradd -s /sbin/nologin php-fpm# 复制php配置文件[root@ZLNMP php]# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini# 复制启动脚本[root@ZLNMP src]# cp php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm[root@ZLNMP src]# chmod 755 !$chmod 755 /etc/init.d/php-fpm# 制作一份php-fpm配置文件[root@ZLNMP php]# cd /usr/local/php/etc/[root@ZLNMP etc]# mv php-fpm.conf.default php-fpm.conf# 设置开机启动[root@ZLNMP ~]# chkconfig --add php-fpm[root@ZLNMP ~]# chkconfig php-fpm on[root@ZLNMP ~]# service php-fpm startStarting php-fpm  done

四、Nginx

# 解包软件[root@ZLNMP src]# tar -xvf nginx-1.6.2.tar.gz# 进入目录,编译[root@ZLNMP nginx-1.6.2]# ./configure --prefix=/usr/local/nginx   --with-pcre# 编译安装[root@ZLNMP nginx-1.6.2]# make[root@ZLNMP nginx-1.6.2]# make install#启动Nginx[root@ZLNMP nginx-1.6.2]# /usr/local/nginx/sbin/nginx

五、编辑Nginx开机启动脚本

    脚本内容请查看:

# 编辑启动脚本,加入脚本[root@ZLNMP ~]# vim /etc/init.d/nginx[root@ZLNMP ~]# chmod +x /etc/init.d/nginx# 添加启动服务[root@ZLNMP ~]# chkconfig --add nginx[root@ZLNMP ~]# chkconfig nginx on# 因为之前启动过,这里重启就好[root@ZLNMP ~]# service nginx restart停止 Nginx:                                               [确定]正在启动 Nginx:                                           [确定]

六、编辑nginx配置

   

[root@ZLNMP ~]# vim /usr/local/nginx/conf/nginx.conf找到下面这一段,把注释符“#”都取消掉        location ~ \.php$ {            root           html;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            # 修改Nginx监控目录            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;            include        fastcgi_params;        }

    在浏览器测试nginx

    如果无法访问,请检查iptables与SELINUX

七、测试php

    在监控目录添加php测试文件

[root@ZLNMP ~]# vim /usr/local/nginx/html/phpinfo.php# 添加如下内容

     在浏览器中进行测试,