安装之前需要做的工作:

1. 检查当前系统是否已经装有mysql php nginx 等软件包

rpm -qa|grep -E '(mysql|php)' , 若有安装请先删除卸载 ,rpm -e <软件包名字> --nodeps

转载请注明出处: http://www.minunix.com/2013/04/lnmp_install/    作者:MinUnix

一 .  安装开发工具,及所需的软件包

yum -y groupinstall 'Development tools'
yum -y install gcc automake autoconf libtool-ltdl-devel make gcc-c++ glibc libxml2-devel libcurl-devel curl-devel openldap-devle openssl-devel bzip2-devel
useradd -M -s /sbin/nologin mysql
useradd -M -s /sbin/nologin nginx

二 .下载所需软件

mysql-5.5.30.tar.gz
php-5.4.7.tar.gz
nginx-1.2.8.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
zlib-1.2.7.tar.gz
mhash-0.9.9.9.tar.gz
pcre-8.31.tar.gz
openssl-1.0.1c.tar.gz

三 .  安装mysql

cd /tmp/src
tar xf mysql-5.5.30.tar.gz
cd mysql-5.5.30

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
make
make install
[/cce]
添加环境变量,

vim /etc/profile.d/mysql.sh
###默认没有此文件,需要自行添加 //添加以下内容
PATH=/usr/local/mysql/bin:$PATH
export PATH

### 创建lib库文件 (默认没有此文件)
vim /etc/ld.so.conf.d/mysql.conf
######输入以下内容
/usr/loca/mysql/lib
/usr/loca/mysql/include
###保存退出
#ldconfig -v

mysql 初始化

检查数据库是否已经启动:
#ps axu|grep mysql
#netstat -ant|grep :3306

四 .   安装PHP

cd /tmp/src
tar xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr/local/mhash
make && make install
ln –sv /usr/loca/mhash/lib/* /usr/local/lib64/
ln –sv /usr/loca/mhash/include/* /usr/local/include/
tar xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure –prefix=/usr/local/libmcrypt
make && make install
ln –s /usr/local/libmcrypt/lib/* /usr/lib
ln –s /usr/local/libmcrypt/lib/* /usr/lib64
tar xf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib64 ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt
make && make install

编译PHP环境

tar xf php-5.4.7.tar.gz
cd php-5.4.7

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql --with-mysqli \
--with-iconv-dir --with-freetype-dir \
--with-jpeg-dir --with-png-dir --with-zlib \
--with-libxml-dir --enable-xml \
--disable-rpath --enable-bcmath \
--enable-shmop --with-gettext --enable-sysvsem \
--enable-inline-optimization --with-curl \
--with-curlwrappers --enable-mbregex \
--enable-fpm --with-fpm-user=nginx \
--with-fpm-group=nginx --enable-mbstring \
--with-mcrypt=/usr/local/libmcrypt \
--with-gd --enable-gd-native-ttf \
--with-openssl --with-mhash --enable-pcntl \
--enable-sockets --with-ldap \
--with-ldap-sasl --with-xmlrpc \
--enable-zip --with-pcre-dir --enable-soap \
--enable-zend-signals --without-pear \
--disable-cgi --disable-pdo \
--disable-debug --with-bz2 \
--with-pcre-regex --enable-sysvshm

make && make install
cp php-ini.production /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
###\\取消一下行的注释:
pid = run/php-fpm.pid

chmod +x /etc/init.d/php-fpm
chkconfig –add php-fpm
chkconfig php-fpm on
service php-fpm start
### 检查是否已经正常启动
ps aux|grep php-fpm
netstat -ant|grep :9000
service php-fpm stop

转载请注明出处: http://www.minunix.com/2013/04/lnmp_install/    作者:MinUnix

五 . 安装nginx

cd /tmp/src
tar xf pcre-8.31.tar.gz
tar xf zlib-1.2.7.tar.gz
tar xf openssl-1.0.1c.tar.gz
tar xf nginx-1.2.8.tar.gz
cd nginx-1.2.8
./configure
--user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-select_module --with-poll_module --with-http_sub_module --with-http_ssl_module --with-md5=/usr/lib64 --with-sha1=/usr/lib64 --pid-path=/usr/local/nginx/var/run/nginx.pid --with-pcre=/tmp/src/pcre-8.31 --with-zlib=/tmp/src/zlib-1.2.7 --with-openssl=/tmp/src/openssl-1.0.1c
make && make install

修改配置文件

vim /usr/local/nginx/conf/nginx.conf

####\\\开启一下内容:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; /// 注意此行信息
include fastcgi_params;
}

六 .  启动程序, 添加php网页文件 ,测试

service php-fpm start
/usr/local/nginx/sbin/nginx
### 查看nginx php-fpm 是否已经正常启动
netstat -tnlp
### \\nginx默认的web目录在/usr/local/nginx/html 下
vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

找台客户端访问 http;//192.168.133.179/index.php

 

恭喜您,您已经完成搭建了LNMP环境

转载请注明出处: http://www.minunix.com/2013/04/lnmp_install/    作者:MinUnix