搭建环境: CentOS6.5 软件包版本: nginx-1.2.0.tar.gz mysql-5.5.13.tar.gz php-5.4.9.tar.gz PHP依赖包: mhash-0.9.9.9.tar.gz libiconv-1.13.tar.gz libmcrypt-2.5.8.tar.gz libevent-2.0.21-stable.tar.gz IP地址设置: server:10.21.1.80 client:10.21.1.81 一、安装nginx [iyunv@dev-16~]# useradd -s /sbin/nologin -M nginx [iyunv@dev-16lnmp+memcached]# tar -zxf nginx-1.2.0.tar.gz -C /usr/src/ [iyunv@dev-16lnmp+memcached]# cd /usr/src/nginx-1.2.0/ --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 二、安装mysql 1、安装mysql配置工具cmake [iyunv@dev-16lnmp+memcached]# tar -zxf cmake-2.8.10.2.tar.gz -C /usr/src/ [iyunv@dev-16lnmp+memcached]# cd /usr/src/cmake-2.8.10.2/ 2、安装源码mysql (1)创建mysql用户 [iyunv@dev-16~]# useradd -s /sbin/nologin -M mysql (2)解包,配置,编译,安装mysql [iyunv@dev-16lnmp+memcached]# tar -zxf mysql-5.5.13.tar.gz -C /usr/src/ [iyunv@dev-16lnmp+memcached]# cd /usr/src/mysql-5.5.13/ -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\ (2)mysql初始化设置 [iyunv@dev-16mysql]# chown -R mysql.mysql . [iyunv@dev-16mysql]# ./scripts/mysql_install_db –user=mysql //初始化操作 (3)创建配置文件my.cnf [iyunv@dev-16~]# cd /usr/src/mysql-5.5.13/support-files/ [iyunv@dev-16support-files]# cp my-medium.cnf /etc/my.cnf //配置文件 [iyunv@dev-16support-files]# cp mysql.server /etc/init.d/mysqldd //创建启动脚本 [iyunv@dev-16support-files]# chmod +x /etc/init.d/mysqldd //添加启动脚本执行权限 [iyunv@dev-16support-files]# chkconfig --add mysqldd [iyunv@dev-16support-files]# chkconfig --list mysqldd mysqldd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 [iyunv@dev-16support-files]# service mysqldd start //启动服务 (3)将mysql提供的命令添加到PATH变量中 [iyunv@dev-16support-files]# export PATH=/usr/local/mysql/bin/:$PATH [iyunv@dev-16~]# vim /etc/bashrc //文件末尾添加一行记录 export PATH=/usr/local/mysql/bin:$PATH (4)指定mysql库文件的位置 [iyunv@dev-16~]# cat /etc/ld.so.conf includeld.so.conf.d/*.conf /usr/local/mysql/lib/ [iyunv@dev-16~]# ldconfig 三、安装PHP (1)安装PHP依赖包 mhash、libiconv、libmcrypt直接编译安装就可以 libmcrypt包中包含一个libltdl的工具,该工具也需要安装 [iyunv@dev-16libltdl]# ./configure --with-gmetad --enable-gexec–enable-ltdl-install [iyunv@dev-16libltdl]# make && make install
(2)指定扩展包库文件的位置 [iyunv@dev-16~]# ln -sv /usr/local/lib/libmcrypt* /usr/lib/ [iyunv@dev-16~]# ln -sv /usr/local/lib/libmhash.* /usr/lib/ [iyunv@dev-16~]# 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 配置完成后执行编译: (4)为PHP程序创建php配置文件 进入php源码目录: 四、整合Nginx与FastCGI (1)生成php-fpm住配置文件 进入php的安装目录下的etc目录 [iyunv@dev-16etc]# cp php-fpm.conf.default php-fpm.conf //生成php-fpm的配置文件 (2)准备php-fpm的启动脚本 进入php源码目录下: [iyunv@dev-16~]# cd /usr/src/php-5.4.9/sapi/fpm/ [iyunv@dev-16fpm]# cp init.d.php-fpm /etc/init.d/php-fpm [iyunv@dev-16fpm]# chmod +x /etc/init.d/php-fpm [iyunv@dev-16fpm]# chkconfig --add php-fpm [iyunv@dev-16fpm]# chkconfig --list php-fpm php-fpm 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 [iyunv@dev-16~]# service php-fpm start (3)编辑nginx配置文件,整合nginx与FastCGI [iyunv@dev-16~]# cd /usr/local/nginx/conf/ [iyunv@dev-16conf]# vim nginx.conf …… location/ { root html; index index.html index.php; } …… location~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; includefastcgi_params; } …… (4)修改fastcgi_params文件内容,重启nginx服务 [iyunv@dev-16conf]# vim fastcgi_params //添加一行配置 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 重启nginx服务: [iyunv@dev-16sbin]# ./nginx -s stop [iyunv@dev-16sbin]# ./nginx (5)测试 [iyunv@dev-16 ~]# cat /usr/local/nginx/html/test.php //测试php解析 <?php phpinfo(); ?>
d[iyunv@dev-16 ~]# cat /usr/local/nginx/html/db.php //测试数据库链接 <?php $link=mysql_connect('localhost','test',''); //连数据库 if($link)echo "恭喜你,数据库连接成功啦 !!"; //成功时的提示 mysql_close(); //关数据库 ?>
|