43fdw 发表于 2014-12-1 08:31:46

源码包编译搭建LNMP+FastCGI平台

搭建环境:CentOS6.5软件包版本:nginx-1.2.0.tar.gzmysql-5.5.13.tar.gzphp-5.4.9.tar.gzPHP依赖包:mhash-0.9.9.9.tar.gzlibiconv-1.13.tar.gzlibmcrypt-2.5.8.tar.gzlibevent-2.0.21-stable.tar.gzIP地址设置:server:10.21.1.80client:10.21.1.81一、安装nginx# useradd -s /sbin/nologin -M nginx# tar -zxf nginx-1.2.0.tar.gz -C /usr/src/# cd /usr/src/nginx-1.2.0/[root@dev-16nginx-1.2.0]# ./configure \--prefix=/usr/local/nginx\--pid-path=/usr/local/nginx/nginx.pid\--user=nginx\--group=nginx\--with-http_ssl_module\--with-http_flv_module\--with-http_stub_status_module\--with-http_gzip_static_module\--http-client-body-temp-path=/usr/local/nginx/client\--http-proxy-temp-path=/usr/local/nginx/proxy\--http-fastcgi-temp-path=/usr/local/nginx/fcgi\--http-uwsgi-temp-path=/usr/local/nginx/uwsgi\--http-scgi-temp-path=/usr/local/nginx/scgi\--with-pcre[root@dev-16nginx-1.2.0]# make && make install二、安装mysql1、安装mysql配置工具cmake# tar -zxf cmake-2.8.10.2.tar.gz -C /usr/src/# cd /usr/src/cmake-2.8.10.2/[root@dev-16cmake-2.8.10.2]# ./bootstrap –prefix=/usr/local/cmake[root@dev-16cmake-2.8.10.2]# make[root@dev-16cmake-2.8.10.2]# make install2、安装源码mysql(1)创建mysql用户# useradd -s /sbin/nologin -M mysql(2)解包,配置,编译,安装mysql# tar -zxf mysql-5.5.13.tar.gz -C /usr/src/# cd /usr/src/mysql-5.5.13/[root@dev-16mysql-5.5.13]#/usr/local/cmake/bin/cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DSYSCONFDIR=/etc\-DMYSQL_DATADIR=/usr/local/mysql/data\-DMYSQL_TCP_PORT=3306\-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock\-DMYSQL_USER=mysql\-DEXTRA_CHARSETS=all\-DWITH_READLINE=1\-DWITH_SSL=system\-DWITH_EMBEDDED_SERVER=1\ -DENABLED_LOCAL_INFILE=1\-DWITH_INNOBASE_STORAGE_ENGINE=1\[root@dev-16mysql-5.5.13]# make && make install(2)mysql初始化设置[root@dev-16mysql-5.5.13]# cd /usr/local/mysql/# chown -R mysql.mysql .# ./scripts/mysql_install_db –user=mysql                //初始化操作(3)创建配置文件my.cnf# cd /usr/src/mysql-5.5.13/support-files/# cp my-medium.cnf /etc/my.cnf                //配置文件# cp mysql.server /etc/init.d/mysqldd        //创建启动脚本# chmod +x /etc/init.d/mysqldd                //添加启动脚本执行权限# chkconfig --add mysqldd# chkconfig --list mysqlddmysqldd               0:关闭        1:关闭        2:启用        3:启用        4:启用        5:启用        6:关闭# service mysqldd start                        //启动服务(3)将mysql提供的命令添加到PATH变量中# export PATH=/usr/local/mysql/bin/:$PATH# vim /etc/bashrc                //文件末尾添加一行记录exportPATH=/usr/local/mysql/bin:$PATH(4)指定mysql库文件的位置# cat /etc/ld.so.confincludeld.so.conf.d/*.conf/usr/local/mysql/lib/# ldconfig三、安装PHP(1)安装PHP依赖包mhash、libiconv、libmcrypt直接编译安装就可以libmcrypt包中包含一个libltdl的工具,该工具也需要安装[root@dev-16libmcrypt-2.5.8]# cd libltdl/# ./configure --with-gmetad --enable-gexec–enable-ltdl-install# make && make install
(2)指定扩展包库文件的位置# ln -sv /usr/local/lib/libmcrypt* /usr/lib/# ln -sv /usr/local/lib/libmhash.* /usr/lib/# ldconfig -v                //系统加载当前链接文件(3)安装PHP进入解压后目录配置:./configure--prefix=/usr/local/php5nginx \--with-config-file-path=/usr/local/php5nginx/etc\--with-mysql=/usr/local/mysql\--with-mysqli=/usr/local/mysql/bin/mysql_config\--with-iconv-dir=/usr/local\--with-freetype-dir\--with-jpeg-dir\--with-png-dir\--with-zlib\--with-libxml-dir=/usr\--enable-xml\--disable-rpath\--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配置完成后执行编译:[root@dev-16php-5.4.9]# make ZEND_EXTRA_LIBS='-liconv'[root@dev-16php-5.4.9]# make install(4)为PHP程序创建php配置文件进入php源码目录:[root@dev-16php-5.4.9]# cp php.ini-production /usr/local/php5nginx/etc/php.ini四、整合Nginx与FastCGI(1)生成php-fpm住配置文件进入php的安装目录下的etc目录# cp php-fpm.conf.default php-fpm.conf                //生成php-fpm的配置文件(2)准备php-fpm的启动脚本进入php源码目录下:# cd /usr/src/php-5.4.9/sapi/fpm/# cp init.d.php-fpm /etc/init.d/php-fpm# chmod +x /etc/init.d/php-fpm # chkconfig --add php-fpm# chkconfig --list php-fpmphp-fpm               0:关闭        1:关闭        2:启用        3:启用        4:启用        5:启用        6:关闭# service php-fpm start(3)编辑nginx配置文件,整合nginx与FastCGI# cd /usr/local/nginx/conf/# vim nginx.conf……location/ {roothtml;index index.html index.php;}……location~ \.php$ {root   html;fastcgi_pass127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME/scripts$fastcgi_script_name;includefastcgi_params;}……(4)修改fastcgi_params文件内容,重启nginx服务# vim fastcgi_params                //添加一行配置fastcgi_param SCRIPT_FILENAME    $document_root$fastcgi_script_name;重启nginx服务:# ./nginx -s stop# ./nginx(5)测试# cat /usr/local/nginx/html/test.php          //测试php解析<?phpphpinfo();?>
d# cat /usr/local/nginx/html/db.php                                                         //测试数据库链接<?php$link=mysql_connect('localhost','test','');    //连数据库if($link)echo "恭喜你,数据库连接成功啦 !!";//成功时的提示mysql_close();   //关数据库?>
页: [1]
查看完整版本: 源码包编译搭建LNMP+FastCGI平台