LNMP环境搭建

LNMP环境搭建
环境介绍:
系统版本:CentOS 5.6 i386(Linux localhost.localdomain 2.6.18-164.el5)
软件版本:Mysql-5.0.83
         Nginx-1.1.11
         Php-5.2.17
代码下载目录:/tmp/srv          
1、检查系统环境(确保已经安装以下环境)
[root@localhost ~]# rpm -q make gcc gcc-c++
2、安装mysql
[root@localhost srv]# tar -zxvf mysql-5.0.83.tar.gz 
[root@localhost srv]# cd mysql-5.0.83
[root@localhost mysql-5.0.83]# groupadd mysql
[root@localhost mysql-5.0.83]# useradd -r -g mysql mysql 
[root@localhost mysql-5.0.83]# ./configure --prefix=/usr/local/mysql
*编译报错error: No curses/termcap library found
*挂载系统光盘,安装ncurses-devel软件包,问题解决
[root@localhost mysql-5.0.83]# make 
[root@localhost mysql-5.0.83]# make install
[root@localhost mysql-5.0.83]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@localhost mysql-5.0.83]# chown -R mysql /usr/local/mysql/var/
[root@localhost mysql-5.0.83]# /usr/local/mysql/bin/mysqld_safe &
[root@localhost mysql-5.0.83]# /usr/local/mysql/bin/mysqladmin -u root password 123456
[root@localhost mysql-5.0.83]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.0.83]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.0.83]# chmod +x /etc/init.d/mysqld 
[root@localhost mysql-5.0.83]# chkconfig --add mysqld
[root@localhost mysql-5.0.83]# chkconfig mysqld on
3、安装Nginx
[root@localhost srv]# tar -zxvf nginx-1.1.11.tar.gz 
[root@localhost srv]# cd nginx-1.1.11
[root@localhost nginx-1.1.11]# ./configure --prefix=/usr/local/nginx
*编译报错./configure: error: the HTTP rewrite module requires the PCRE library.
*安装pcre-devel软件包# yum install pcre-devel zlib-devel -y问题解决
[root@localhost nginx-1.1.11]# make 
[root@localhost nginx-1.1.11]# make install
[root@localhost nginx-1.1.11]# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local 
*[root@localhost nginx-1.1.11]# /usr/local/nginx/sbin/nginx -s reload Nginx重启
*[root@localhost nginx-1.1.11]# /usr/local/nginx/sbin/nginx -t  查看Nginx配置是否正确
4、安装libpng
[root@localhost srv]# tar -zxvf libpng-1.5.2.tar.gz 
[root@localhost srv]# cd libpng-1.5.2
[root@localhost libpng-1.5.2]# ./configure --prefix=/usr/local/png/ --enable-shared 
[root@localhost libpng-1.5.2]# make
[root@localhost libpng-1.5.2]# make install
5、安装jpeg
[root@localhost srv]# tar -zxvf jpegsrc.v8c.tar.gz 
[root@localhost srv]# cd ./jpeg-8c/
[root@localhost jpeg-8c]# mkdir /usr/local/jpeg/
[root@localhost jpeg-8c]# mkdir /usr/local/jpeg/bin/
[root@localhost jpeg-8c]# mkdir /usr/local/jpeg/lib/
[root@localhost jpeg-8c]# mkdir /usr/local/jpeg/include/
[root@localhost jpeg-8c]# mkdir -p /usr/local/jpeg/man/man1
[root@localhost jpeg-8c]# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static
[root@localhost jpeg-8c]# make 
[root@localhost jpeg-8c]# make install
6、安装freetype
[root@localhost srv]# tar -zxvf freetype-2.4.4.tar.gz 
[root@localhost freetype-2.4.4]# cd freetype-2.4.4
[root@localhost freetype-2.4.4]# ./configure --prefix=/usr/local/freetype/ --enable-shared
[root@localhost freetype-2.4.4]# make
[root@localhost freetype-2.4.4]# make install
7、安装autoconf
[root@localhost srv]# tar -zxvf autoconf-2.68.tar.gz 
[root@localhost srv]# cd autoconf-2.68
[root@localhost autoconf-2.68]# ./configure 
[root@localhost autoconf-2.68]# make
[root@localhost autoconf-2.68]# make install
8、安装gd
[root@localhost srv]# tar -zxvf gd-2.0.35.tar.gz
[root@localhost srv]# cd gd-2.0.35
*在make的时候一直报gd-png错误,执行下面cp命令解决问题
[root@localhost gd-2.0.35]# cp /usr/local/libpng/include/png.h ./
[root@localhost gd-2.0.35]# cp /usr/local/libpng/include/pngconf.h ./
[root@localhost gd-2.0.35]# cp /usr/local/libpng/include/libpng15/pnglibconf.h ./
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd/ --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/png/ --with-freetype=/usr/local/freetype/
[root@localhost gd-2.0.35]# make
[root@localhost gd-2.0.35]# make install
9、安装php
默认情况下Nginx和PHP是没有联系的。在之前很多朋友都搭建过Apache+PHP,Apache+PHP编译后生成的是模块文件,
而Nginx+PHP需要PHP生成可执行文件才可以,所以要利用fastcgi技术来实现N ginx与PHP的整合,这个只要我们安装是启用FastCGI即可。
此次我们安装PHP不仅使用了FastCGI,而且还使用了PHP-FPM这么一个东东。
PHP-FPM说白了是一个管理FastCGI的一个管理器,它作为PHP的插件纯在,在安装PHP要想使用PHP-FPM时就需要把PHP-FPM以补丁的形式安装到PHP中;
而且PHP要与PHP-FPM版本一致,这是必须的,切记!
[root@localhost srv]# tar -zxvf php-5.2.17.tar.gz 
*PHP-FPM源码包下载地址http://php-fpm.org/downloads/
[root@localhost srv]# gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 
[root@localhost php-5.2.17]# cd php-5.2.17
[root@localhost php-5.2.17]# ./configure --prefix=/usr/local/php --with-gd=/usr/local/gd/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/png/ 
                             --with-freetype-dir=/usr/local/freetype/ --with-mysql=/usr/local/mysql/ --enable-fastcgi --enable-fpm 
*注:Nginx+PHP整合,在安装时必须启用--enable-fastcgi和--enable-fpm
*编译报错configure: error: XML configuration could not be found;#yum install -y libxml2-devel解决问题
*make报错(错误信息如下)
make: *** [sapi/cgi/php-cgi] 错误 1,下载libiconv软件包,问题解决,下载地址http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
*libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。
先安装libiconv
[root@localhost srv]# tar -zxvf libiconv-1.14.tar.gz 
[root@localhost srv]# cd libiconv-1.14
[root@localhost libiconv-1.14]# ./configure --prefix=/usr/local/
[root@localhost libiconv-1.14]# make
[root@localhost libiconv-1.14]# make install
再编译安装php的时候带上-–with-iconv=/usr/local/即可
[root@localhost php-5.2.17]# cd php-5.2.17
[root@localhost php-5.2.17]# ./configure --prefix=/usr/local/php --with-gd=/usr/local/gd/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/png/ --with-freetype-dir=/usr/local/freetype/ --with-mysql=/usr/local/mysql/ --enable-fastcgi --enable-fpm --with-iconv=/usr/local/
[root@localhost php-5.2.17]# make
[root@localhost php-5.2.17]# make install
[root@localhost php-5.2.17]# cp php.ini-dist /usr/local/php/etc/php.ini
10、启动PHP-FPM
[root@localhost php-5.2.17]# vim /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.2.17]# /usr/local/php/sbin/php-fpm start
[root@localhost php-5.2.17]# echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.local 
11、整合Nginx和Php
[root@localhost ~]# 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  /usr/local/nginx/html/$fastcgi_script_name;                   include        fastcgi_params;          }

[root@localhost ~]# vim /usr/local/php/etc/php-fpm.conf(去掉注释)

 62                         Unix user of processes    63                         <value name="user">nobody</value>    64     65                         Unix group of processes    66                         <value name="group">nobody</value>

12、测试
启动nginx和php
[root@localhost]#/usr/local/nginx/sbin/nginx
[root@localhost]#/usr/local/php/sbin/php-fpm start
然后创建PHP测试程序
[root@localhost]#vim /usr/local/nginx/html/index.php,写入如下内容
<?php
phpinfo();
?>
打开浏览器,输入访问地址,如果出现php的版本介绍就说明整合成功!!!

你可能感兴趣的:(职场,LNMP,休闲,darren,darrenpan)