一、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
软件镜像下载地址http://mirrors.sohu.com/
关闭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、编译
[[email protected] 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
[[email protected] php-5.4.22]# make
[[email protected] php-5.4.22]# make install
2、配置
# 添加用户 [[email protected] ~]# useradd -s /sbin/nologin php-fpm # 复制php配置文件 [[email protected] php]# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini # 复制启动脚本 [[email protected] src]# cp php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [[email protected] src]# chmod 755 !$ chmod 755 /etc/init.d/php-fpm # 制作一份php-fpm配置文件 [[email protected] php]# cd /usr/local/php/etc/ [[email protected] etc]# mv php-fpm.conf.default php-fpm.conf # 设置开机启动 [[email protected] ~]# chkconfig --add php-fpm [[email protected] ~]# chkconfig php-fpm on [[email protected] ~]# service php-fpm start Starting php-fpm done
四、Nginx
# 解包软件 [[email protected] src]# tar -xvf nginx-1.6.2.tar.gz # 进入目录,编译 [[email protected] nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-pcre # 编译安装 [[email protected] nginx-1.6.2]# make [[email protected] nginx-1.6.2]# make install #启动Nginx [[email protected] nginx-1.6.2]# /usr/local/nginx/sbin/nginx
五、编辑Nginx开机启动脚本
脚本内容请查看:地址
# 编辑启动脚本,加入脚本 [[email protected] ~]# vim /etc/init.d/nginx [[email protected] ~]# chmod +x /etc/init.d/nginx # 添加启动服务 [[email protected] ~]# chkconfig --add nginx [[email protected] ~]# chkconfig nginx on # 因为之前启动过,这里重启就好 [[email protected] ~]# service nginx restart 停止 Nginx: [确定] 正在启动 Nginx: [确定]
六、编辑nginx配置
[[email protected] ~]# 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测试文件
[[email protected] ~]# vim /usr/local/nginx/html/phpinfo.php # 添加如下内容 <?php phpinfo(); ?>
在浏览器中进行测试,