CentOS5.6(64bit)下编译安装Nginx1.2.0、Percona-Server-5.1.61、PHP5.3.10
一、安装centos5.6(64位)
此步骤省略(详情见CentOs5.6的文本安装)
二、安装前环境配置
安装完centos5.6后的一些配置
1、关掉不用的系统服务项
#chkconfig --list | grep :on
#chkconfig iscsi --del
#chkconfig iscsi --del
#chkconfig iscsid --del
#chkconfig lvm2-monitor --del
#chkconfig ip6tables --del
#chkconfig iptables --del
#chkconfig haldaemon --del
#chkconfig avahi-daemon --del
#chkconfig avahi-dnsconfd --del
2、配置好IP、DNS、网关确保远程工具能够连接到服务器
#vi /etc/sysconfig/network-scripts/ifcf-eth0 配置IP
#vi /etc/sysconfig/network 配置网关
#vi /etc/resolv.conf 配置DNS
#service network restart 重启网卡服务
3、关闭SELINUX
#vi /etc/selinux/config
#SELINUX=enforcing 注释掉
#SELINUXTYPE=targeted 注释掉
SELINUX=disabled 增加
:wq 保存,退出
#shutdown -r now 重启系统
4、新建软件包存放和安装目录
#mkdir /data/src
#mkdir /usr/local/软件名字
5、下载下面的软件包到存放目录
#cd /data/src/
下载nginx(最新稳定版)
#wget http://nginx.org/download/nginx-1.2.0.tar.gz
下载pcre(支持nginx伪静态)
#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
下载php
#wget http://cn.php.net/distributions/php-5.3.10.tar.gz
下载percona(mysql的衍生版)
#wgethttp://www.percona.com/downloads/Percona-Server-5.1/Percona-Server-5.1.61-13.2/source/Percona-Server-5.1.61.tar.gz
下载libmcrypt(php模块)
#wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
下载libiconv(php库文件)
#wger http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
下载mhash(哈希函数库)
#wget http://cdnetworks-kr-2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
下载xcache(php缓存器)
#wgethttp://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz
三、安装软件包
注:以下是用SecureCRT工具远程登录到服务器,在命令行下面操作的
1、在安装软件包之前安装编译工具和库文件(使用centos yum命令安装)
#yum install make apr* autoconf automake curl curl-devel gcc gcc-c++zlib-devel openssl open ssl-devel pcre-devel gd kernel keyutils patch perlkernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-pplkeyutils-libs-devel libcom_err-devel libsepol-devel libselin ux-devel kr b5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gdncurses* libtool* libxm l2 libxml2-devel patch
2、进入到软件包存放目录安装软件
#cd/data/src/
#ls
安装mysql
#tar xvfPercona-Server-5.1.61.tar.gz 解压Percona-Server-5.1.61.tar.gz
#mvPercona-Server-5.1.61 percona 重命名Percona-Server-5.1.61为percona
#cd/data/src/percona/ 进入percona目录
#mkdir/data/mysqldb 新建mysqldb目录
#groupaddmysql 新建mysql组
#useradd -gmysql -s /sbin/nologin mysql 新建mysql用户并添加到mysql组中不允许mysql登陆
#./configure--prefix=/usr/local/mysql --localstatedir=/data/mysqldb --enable-assembler--enable-thr ead-safe-client--with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-unix-socket-p ath=/tmp/mysql.sock--with-charset=utf8 --with-collation=utf8_general_ci--with-extra-charsets=co mplex--with-pthread --with-big-tables --without-embedded-server
配置编译文件
#make -j 2 以两个CPU编译mysql
#make install 安装mysql
安装完成后计入mysql安装目录更改mysql的用户、组的属性和权限
#cdsupport-files/
#cpmy-medium.cnf /etc/my.cnf 拷贝配置文件
#/usr/local/mysql/bin/mysql_install_db--user=mysql 初始化mysql
#cd/usr/local/mysql/
#chown -Rmysql mysql 更改mysql的所属用户为mysql
#chgrp -Rmysql mysql 更改mysql所属组为mysql
#cp/data/src/percona/support-files/mysql.server /etc/init.d/mysql 把Mysql加入系统启动
#chmod 755/etc/init.d/mysql 增加mysql的执行权限
#ldconfig 刷新新安装的库文件
#cd/etc/init.d/ 进入init.d目录
#./mysqlrestart 重启mysql服务
下面这三行把mysql的库文件建立mysql客户端、备份等软件的软连接
#ln -s/usr/local/mysql/bin/mysql /usr/bin/mysql
#ln -s/usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
#ln -s/usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
#/usr/local/mysql/bin/mysqladmin-u root password wanhuajinhui 设置Mysql密码
#mysql -uroot -p 进入mysql
#chkconfig--add mysql 添加mysql到服务中
#init 6 重启系统
到这里mysql安装完成
在安装nginx和php前先安装其关联的库
1、安装libmcrypt
#cd /usr/local/src
#tar zxvf libmcrypt-2.5.8.tar.gz 解压
#cd libmcrypt-2.5.8 进入目录
#./configure 配置
#make -j 2 编译
#make install 安装
2、安装libiconv
#cd /usr/local/src
#tar zxvf libiconv-1.14.tar.gz
#cd libiconv-1.14
#./configure
#make -j 2 编译
#make install 安装
3、安装pcre
#cd /usr/local/src
#mkdir /usr/local/pcre 创建安装目录
#tar zxvf pcre-8.30.tar.gz
#cd pcre-8.30
#./configure --prefix=/usr/local/pcre 配置
#make -j 2
#make install
安装Nginx
#groupaddwebuser 添加webuser组
#useradd -g webuser webuser -s/bin/false
创建nginx运行账户webuser并加入到webuser组,不允许webuser用户直接登录系统
#cd /usr/local/src
#tar zxvf nginx-1.2.0.tar.gz
#cd nginx-1.2.0
#./configure --prefix=/usr/local/nginx--user=webuser --group=webuser --with-http_stub_status_mo dul e--with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.30
#make -j 2 编译nginx
#make install 安装nginx
#/usr/local/nginx/sbin/nginx 启动nginx
编辑下面文件设置开机启动nginx
#vi/etc/rc.d/init.d/nginx 编辑启动文件添加下面内容
#!/bin/bash
=================================================================================
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web andproxy server.
# It has a lot of features, but it's not foreveryone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch/var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f/var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog{start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
=================================================================================
:wq 保存退出
#chmod 775/etc/rc.d/init.d/nginx 赋予文件执行权限
#chkconfig nginx on 设置开机启动
进入data目录下修改www目录的所属用户和组
#cd /data/
#ll
#chownwebuser:webuser www
#/etc/rc.d/init.d/nginx restart 重启nginx
#service nginx restart 重启nginx
安装php
#cd/data/src/
#ls
#tarphp-5.3.10.tar.gz
#cdphp-5.3.10
#./configure --with-libdir=lib64 --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc -- wit h-mysql=/usr/bin--with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --disable-fi leinfo --with-freetype-dir --with-jpeg-dir--with-png-dir --with-zlib --with-libxml-dir=/usr --enabl e-xml --d isable-rpath --enable-safe-mode --enable-bcmath --enable-shmop--enable-sysvsem --en able-inline-o ptimization --with-curl --with-curlwrappers--enable-mbregex --enable-fpm --with-fp m-user=webuse r--with-fpm-group=webuser --enable-mbstring --with-mcrypt --with-gd --enable- gd-native-ttf --wit h-openssl --with-mhash --enable-pcntl--enable-sockets --with-xsl --with-ldap - -with-ldap-sasl --wit h-xmlrpc--enable-zip --enable-soap --with-pear=/opt/pear --with-gettext --wi th-xpm-dir=/usr/lib64
#makeZEND_EXTRA_LIBS='-liconv' -j 2
#make install
#cp php.ini-production /usr/local/php/etc/php.ini 复制php配置文件到安装目录
#rm -rf /etc/php.ini 删除系统自带配置文件
#ln -s /usr/local/php/etc/php.ini/etc/php.ini 添加软链接
#cp/usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 拷贝模板文件为php-fpm配置文件
设置 php-fpm开机启动
#cp/usr/local/src/php-5.3.10/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
拷贝php-fpm到启动目录
#chmod 755 /etc/rc.d/init.d/php-fpm 添加执行权限
#chkconfig php-fpm on 设置开机启动
配置nginx支持php
#vi /usr/local/nginx/conf/nginx.conf
修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改
user www www;
首行user去掉注释,修改Nginx运行组为webuser webuser;必须与/usr/local/php/etc/php-fpm.conf中的 user,group配置相同,否则php运行出错
index index.php index.html index.htm; 添加index.php
# pass the PHPscripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME/data/www$fastcgi_script_name;
include fastcgi_params;
}
改为/data/www$fastcgi_script_name,/data/www/目录为php文档根目录
#/etc/init.d/nginx restart 重启nginx
测试php和nginx是否安装成功
#cd /usr/local/nginx/html/ 进入nginx默认网站根目录
#rm -rf /usr/local/nginx/html/* 删除默认测试页
#mkdir index.php 新建index.php文件
#vi index.php 编辑index.php文件
<?php
phpinfo();
?>
:wq! 保存退出
#chown webuser.webuser/usr/local/nginx/html/ -R 设置目录所有者
#chmod 700 /usr/local/nginx/html/ -R 设置目录权限
#shutdown -r now 重启
在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!
#servicenginx restart 重启nginx
#service mysqld restart 重启mysql
#/etc/rc.d/init.d/php-fpm restart 重启php-fpm
#/etc/rc.d/init.d/php-fpm stop 停止php-fpm
#/etc/rc.d/init.d/php-fpm start 启动php-fpm
备注:
nginx默认站点目录是:/usr/local/nginx/html/
权限设置:chown wbuser.webuser /usr/local/nginx/html/ -R
MySQL数据库目录是:/data/mysql
权限设置:chown mysql.mysql -R /data/mysql
444



被折叠的 条评论
为什么被折叠?



