LNMP环境的搭建配置(CentOS6.2+nginx1.1.15+mysql5.5+php5.3.10)
一、安装前的准备
1、下载所需要的安装包
Nginx 下载:http://nginx.org/download/nginx-1.1.15.tar.gz
Mysql下载:http://mysql.cs.pu.edu.tw/Downloads/MySQL-5.5/mysql-5.5.21.tar.gz
php下载:http://cn.php.net/distributions/php-5.3.10.tar.gz
2、首先对环境需要的库和编译工具进行安装
yum -y install gcc
gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype
freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2
glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
openldap openldap-devel nss_ldap openldap-clients openldap-servers
二、安装过程
1、编译安装Mysql
1) 创建mysql安装目录及数据存放目录
# mkdir -p/usr/local/mysql/
# mkdir -p /data/mysql/
2)创建用户和用户组与赋予数据存放目录权限
# groupadd mysql
# useradd mysql -M -s/sbin/nologin
# chown mysql.mysql -R /data/mysql/
3)安装必要的组件
# yum -y install cmake
# yum -y installncurses-devel
4)开始编译安装Mysql
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk
-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
# make
# make install
5)初始化数据库
# cd /usr/local/mysql
#
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
--datadir=/data/mysql/
6)配置环境
# cpsupport-files/my-medium.cnf /etc/my.cnf
# cpsupport-files/mysql.server /etc/init.d/mysql
# chmod 755/etc/init.d/mysql
# chkconfig mysql on
# exportPATH=/usr/local/mysql/bin:$PATH
7)启动并设置初始密码
# /etc/init.d/mysql start
# mysqladmin -urootpassword '123456'
进行再修改密码的语句
> UPDATE mysql.userSET Password = PASSWORD(‘newpwd’) WHERE User = ‘root’;(生新设置密码)
> flush privileges;(刷新权限)
2、 编译安装nginx
1) 添加一个不能登录并且没有主目录的用户
# useradd www -M -s /sbin/nologin
2) 下载必要的组件并安装
# wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.21/pcre-8.21.zip
# unzip pcre-8.21.zip
# cd pcre-8.21
# ./configure
# make && makeinstall
3)下载编译安装nginx
# wgethttp://nginx.org/download/nginx-1.1.15.tar.gz
# tar zxvfnginx-1.1.15.tar.gz
# cd nginx-1.1.15
# ./configure
--prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module
--with-http_ssl_module
# make && makeinstall
4)启动nginx
#/usr/local/nginx/sbin/nginx
启动后,在浏览器里输入IP,即可查看到:Welcome to nginx!的欢迎界面
# echo"/usr/local/nginx/sbin/nginx" >> /etc/rc.local
4 编译安装php
1) 下载安装必要的组件
wget -chttp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget
http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
或者wget
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wgethttp://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wgethttp://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wgethttp://cn.php.net/distributions/php-5.3.10.tar.gz
wget http://pear.php.net/go-pear.phar
# yum -y installlibjpeg-devel libpng-devel
# tar zxvf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure
# make
# make install
# tar -zxvflibmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make
# make install
# /sbin/ldconfig
# cd libltdl/
# ./configure--enable-ltdl-install
# make
# make install
# cd ../../
# tar zxvfmhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9
# ./configure
# make
# make install
# cd ../
ln -s/usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s/usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s/usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s/usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s/usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s/usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s/usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s/usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
ln -s/usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
# tar zxvfmcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8
# /sbin/ldconfig
#./configure
# make
# make install
# cd ../
2)编译安装php
# tar zxvfphp-5.3.10.tar.gz
# cd php-5.3.10
# ./configure
--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config
--with-iconv-dir=/usr/local/lib --with-freetype-dir --with-jpeg-dir
--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml
--disable-rpath --enable-safe-mode
--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization
--with-curl --with-curlwrappers --enable-mbregex --enable-fpm
--enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf
--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap
--with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear
--with-fpm-user=www --with-fpm-group=www
# makeZEND_EXTRA_LIBS='-liconv'
# make install
3) 复制和修改php配置文件
# cp php.ini-production
/usr/local/php/lib/php.ini 或是
/usr/local/lib/php.ini
# cp/usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# /usr/local/php/bin/php--ini //测试ini文件是否加载
注:Nginx+PHP整合,在安装时必须启用–enable-fastcgi 和 –enable-fpm
5 环境测试,写一个phpinfo文件测试一下