当前位置: > 数据库 > MySQL >

CentOS 6.0编译安装Nginx+MySQL+PHP+Zend

时间:2014-06-21 03:39来源:linux.it.net.cn 作者:IT网

操作系统:CentOS 6.0 32位

下载地址:http://mirrors.163.com/centos/6.0/isos/i386/CentOS-6.0-i386-bin-DVD.iso
安装方式:采用最小化安装,在安装系统的时候选择Minimal(CentOS 6.0默认就是Minimal安装模式,不含有任何可选安装包)
最小化安装完成之后,系统占用900M左右磁盘空间
备注:操作系统的安装,这里就不演示了,如果有疑问可以参考相关教程
CentOS 6.0安装图解教程   http://wenku.baidu.com/view/668f53e9e009581b6bd9ebc9.html
=================================================================================================================
安装前准备:
1、配置好ip dns 网关,确保使用远程连接工具能够连接服务器
2、关闭selinux
   vi /etc/selinux/config 把SELINUX=enforcing  SELINUXTYPE=targeted注释掉,然后新加一行为:SELINUX=disabled
3、开启防火墙相应端口,apache需要开启80端口  MySQL需要开启3306端口
   vi /etc/sysconfig/iptables
   添加下面的内容
   -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT     #(允许80端口通过防火墙)
   -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT   #(允许3306端口通过防火墙)
   重启防火墙使配置生效
   /etc/init.d/iptables restart
4 、系统约定
    软件源代码包存放位置:/usr/local/src
    源码包编译安装位置:/usr/local/软件名字
5、下载软件
   (1)下载pcre  (支持nginx伪静态)
        ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz
   (2)下载nginx(目前稳定版)
        http://nginx.org/download/nginx-1.0.6.tar.gz
   (3)下载mysql
        http://gd.tuwien.ac.at/db/mysql/Downloads/MySQL-5.1/mysql-5.1.59.tar.gz
   (4)下载php
        http://cn.php.net/distributions/php-5.2.17.tar.gz
   (5)下载php-5.2.17-fpm  (支持php FastCGI模式)
        http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
   (6)下载ZendOptimize
       http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
   (7)下载libmcrypt
       ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz  #下载libmcrypt
   (8)下载编译工具(要编译安装软件,必须先安装编译工具)
       下载地址 http://mirror.centos.org/centos/6.0/os/i386/Packages/
       或者直接从CentOS 6.0的安装光盘中复制出来,打开安装光盘,在Packages文件夹下面,找到下面的安装包
kernel-headers-2.6.32-71.el6.i686.rpm
compat-glibc-headers-2.5-46.2.i686.rpm
compat-glibc-2.5-46.2.i686.rpm
compat-libstdc++-33-3.2.3-69.el6.i686.rpm
compat-libf2c-34-3.4.6-19.el6.i686.rpm
compat-libgcc-296-2.96-144.el6.i686.rpm
mpfr-2.4.1-6.el6.i686.rpm
cpp-4.4.4-13.el6.i686.rpm
glibc-headers-2.12-1.7.el6.i686.rpm
glibc-devel-2.12-1.7.el6.i686.rpm
libgomp-4.4.4-13.el6.i686.rpm
libstdc++-devel-4.4.4-13.el6.i686.rpm
ppl-0.10.2-11.el6.i686.rpm
cloog-ppl-0.15.7-1.2.el6.i686
gcc-4.4.4-13.el6.i686.rpm
compat-gcc-34-3.4.6-19.el6.i686.rpm
compat-gcc-34-c++-3.4.6-19.el6.i686.rpm
make-3.81-19.el6.i686.rpm
keyutils-libs-devel-1.4-1.el6.i686.rpm
libcom_err-devel-1.41.12-3.el6.i686.rpm
libsepol-devel-2.0.41-3.el6.i686.rpm
libselinux-devel-2.0.94-2.el6.i686.rpm
krb5-devel-1.8.2-3.el6.i686.rpm
zlib-devel-1.2.3-25.el6.i686.rpm
openssl-devel-1.0.0-4.el6.i686.rpm
libXpm-3.5.8-2.el6.i686.rpm
gd-2.0.35-10.el6.i686.rpm
freetype-2.3.11-5.el6.i686.rpm
libxml2-2.7.6-1.el6.i686.rpm
libxml2-devel-2.7.6-1.el6.i686.rpm
curl-7.19.7-16.el6.i686.rpm
libjpeg-devel-6b-46.el6.i686.rpm
libjpeg-6b-46.el6.i686.rpm
libjpeg-static-6b-46.el6.i686.rpm
libpng-1.2.44-1.el6.i686.rpm
libpng-devel-1.2.44-1.el6.i686.rpm
libpng-static-1.2.44-1.el6.i686.rpm
php-common-5.3.2-6.el6.i686.rpm
php-gd-5.3.2-6.el6.i686.rpm
gcc-c++-4.4.4-13.el6.i686.rpm
ncurses-devel-5.7-3.20090208.el6.i686.rpm
ncurses-term-5.7-3.20090208.el6.i686.rpm
ncurses-static-5.7-3.20090208.el6.i686.rpm
perl-Pod-Escapes-1.04-115.el6.i686.rpm
perl-libs-5.10.1-115.el6.i686.rpm
perl-version-0.77-115.el6.i686.rpm
perl-Module-Pluggable-3.90-115.el6.i686.rpm
perl-Pod-Simple-3.13-115.el6.i686.rpm
perl-5.10.1-115.el6.i686.rpm
autoconf213-2.13-20.1.el6.noarch.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-1.2.el6.noarch.rpm
automake14-1.4p6-19.2.el6.noarch.rpm
automake16-1.6.3-18.el6.1.noarch.rpm
libtool-ltdl-2.2.6-15.5.el6.i686.rpm
libtool-ltdl-devel-2.2.6-15.5.el6.i686.rpm
libtool-2.2.6-15.5.el6.i686.rpm
patch-2.6-6.el6.i686.rpm
把这些安装包用WinSCP远程连接工具上传到服务器的/usr/local/src下面
到此,安装前准备工作完成,
注意:这里我们是把软件下载好之后,再通过远程连接工具上传到服务器上面的。
因为最小化安装完系统之后是不带wget命令的,所以无法直接从服务器下载,
      当然,不建议直接在服务器上面下载软件。
==============================================================
正式安装开始
   以下是用putty工具远程登录到服务器,在终端命令行下面操作的
1、安装编译工具
   cd /usr/local/src #进入软件包存放目录
   按照以下顺序进行安装,特别注意:顺序一定不能错,否则安装失败
   小技巧:可以把下面的所有行按顺序一次性复制到终端命令行,
系统会自动安装的,这样会节省很对时候,同时也避免操作错误!
####################################################################
rpm -ivh kernel-headers-2.6.32-71.el6.i686.rpm
rpm -ivh compat-glibc-headers-2.5-46.2.i686.rpm
rpm -ivh compat-glibc-2.5-46.2.i686.rpm
rpm -ivh compat-libstdc++-33-3.2.3-69.el6.i686.rpm
rpm -ivh compat-libf2c-34-3.4.6-19.el6.i686.rpm
rpm -ivh compat-libgcc-296-2.96-144.el6.i686.rpm
rpm -ivh mpfr-2.4.1-6.el6.i686.rpm
rpm -ivh cpp-4.4.4-13.el6.i686.rpm
rpm -ivh glibc-headers-2.12-1.7.el6.i686.rpm
rpm -ivh glibc-devel-2.12-1.7.el6.i686.rpm
rpm -ivh libgomp-4.4.4-13.el6.i686.rpm
rpm -ivh libstdc++-devel-4.4.4-13.el6.i686.rpm
rpm -ivh ppl-0.10.2-11.el6.i686.rpm
rpm -ivh cloog-ppl-0.15.7-1.2.el6.i686.rpm
rpm -ivh gcc-4.4.4-13.el6.i686.rpm
rpm -ivh compat-gcc-34-3.4.6-19.el6.i686.rpm
rpm -ivh compat-gcc-34-c++-3.4.6-19.el6.i686.rpm
rpm -ivh make-3.81-19.el6.i686.rpm
rpm -ivh keyutils-libs-devel-1.4-1.el6.i686.rpm
rpm -ivh libcom_err-devel-1.41.12-3.el6.i686.rpm
rpm -ivh libsepol-devel-2.0.41-3.el6.i686.rpm
rpm -ivh libselinux-devel-2.0.94-2.el6.i686.rpm
rpm -ivh krb5-devel-1.8.2-3.el6.i686.rpm
rpm -ivh zlib-devel-1.2.3-25.el6.i686.rpm
rpm -ivh openssl-devel-1.0.0-4.el6.i686.rpm
rpm -ivh libXpm-3.5.8-2.el6.i686.rpm
rpm -ivh gd-2.0.35-10.el6.i686.rpm
rpm -ivh freetype-2.3.11-5.el6.i686.rpm
rpm -ivh libxml2-2.7.6-1.el6.i686.rpm
rpm -ivh libxml2-devel-2.7.6-1.el6.i686.rpm
rpm -ivh curl-7.19.7-16.el6.i686.rpm
rpm -ivh libjpeg-devel-6b-46.el6.i686.rpm
rpm -ivh libjpeg-6b-46.el6.i686.rpm
rpm -ivh libjpeg-static-6b-46.el6.i686.rpm
rpm -ivh libpng-1.2.44-1.el6.i686.rpm
rpm -ivh libpng-devel-1.2.44-1.el6.i686.rpm
rpm -ivh libpng-static-1.2.44-1.el6.i686.rpm
rpm -ivh php-common-5.3.2-6.el6.i686.rpm
rpm -ivh php-gd-5.3.2-6.el6.i686.rpm
rpm -ivh  gcc-c++-4.4.4-13.el6.i686.rpm
rpm -ivh  ncurses-devel-5.7-3.20090208.el6.i686.rpm
rpm -ivh  ncurses-term-5.7-3.20090208.el6.i686.rpm
rpm -ivh  ncurses-static-5.7-3.20090208.el6.i686.rpm
rpm -ivh  --nodeps perl-Pod-Escapes-1.04-115.el6.i686.rpm
rpm -ivh  --nodeps perl-libs-5.10.1-115.el6.i686.rpm
rpm -ivh  --nodeps perl-version-0.77-115.el6.i686.rpm
rpm -ivh  --nodeps perl-Module-Pluggable-3.90-115.el6.i686.rpm
rpm -ivh  --nodeps perl-Pod-Simple-3.13-115.el6.i686.rpm
rpm -ivh  --nodeps perl-5.10.1-115.el6.i686.rpm
rpm -ivh autoconf213-2.13-20.1.el6.noarch.rpm
rpm -ivh autoconf-2.63-5.1.el6.noarch.rpm
rpm -ivh automake-1.11.1-1.2.el6.noarch.rpm
rpm -ivh automake14-1.4p6-19.2.el6.noarch.rpm
rpm -ivh automake16-1.6.3-18.el6.1.noarch.rpm
rpm -ivh libtool-ltdl-2.2.6-15.5.el6.i686.rpm
rpm -ivh libtool-ltdl-devel-2.2.6-15.5.el6.i686.rpm
rpm -ivh libtool-2.2.6-15.5.el6.i686.rpm
rpm -ivh patch-2.6-6.el6.i686.rpm
#####################################################
=======================================================================================================================
  2、安装mysql
 cd /usr/local/src
  tar zxvf mysql-5.1.59.tar.gz
  cd mysql-5.1.59
  ./configure --prefix=/usr/local/mysql  --localstatedir=/usr/local/mysql/data/ --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static  --with-unix-socket-path=/tmp/mysql.sock --with-shared --without-debug --with-extra-charsets=all --without-embedded-server --enable-profiling  --enable-assembler --enable-thread-safe-client --with-server-suffix=-community --with-extra-charset=utf8,gbk
  make
  make install
 特别注意:在执行make install编译的过程中,如果你看到屏幕上出现下面这一行,卡在那里,很久都过不去,千万别以为是编译错误了,或者服务器卡住了,只需要坚持,耐心的等待几分钟,就会编译成功!Mysql编译安装告诉我们,任何事情,只要坚持下去,终会成功!
  make[4]: Entering directory `/usr/local/src/mysql-5.1.59/mysql-test'
  groupadd mysql  #添加mysql组
  useradd -g mysql mysql -s /bin/false  #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
  chown -R root /usr/local/mysql/   #允许root访问
  chgrp -R mysql /usr/local/mysql/  #允许mysql组访问
  cd /usr/local/mysql/   #进入mysql安装目录
  cp share/mysql/my-huge.cnf /etc/my.cnf   #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
  cp share/mysql/mysql.server /etc/init.d/mysqld    #把Mysql加入系统启动
  chmod 755 /etc/init.d/mysqld   #执行权限
  vi /etc/profile   #把mysql服务加入系统环境变量:
  在最后添加下面这一行
  export PATH=$PATH:/usr/local/mysql/bin
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
  ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
  ln -s /usr/local/mysql/include/mysql /usr/include/mysql
  /usr/local/mysql/bin/mysql_install_db --user=mysql &  #生成mysql系统数据库
  /usr/local/mysql/bin/mysqld_safe  --user=mysql &   #启动mysql
  /etc/rc.d/init.d/mysqld start #启动
  chkconfig mysqld on  #加入开机启动
  shutdown -r now     #需要重启系统,等待系统重新启动之后继续在终端命令行下面操作
  mysql_secure_installation    #设置Mysql密码
  根据提示按Y 回车输入2次密码
  或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码
  service mysqld restart  #重启
  到此,mysql安装完成!
===============================================================================================================
3、安装pcre
cd /usr/local/src
 tar  zxvf pcre-8.13.tar.gz
 mkdir /usr/local/pcre  #创建安装目录
 cd pcre-8.13
 ./configure  --prefix=/usr/local/pcre  #配置
make
make install
4、安装 nginx
cd /usr/local/src
tar  zxvf nginx-1.0.6.tar.gz
cd nginx-1.0.6
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.13
注意:--with-pcre=/usr/local/src/pcre-8.13指向的是源码包解压的路径,而不是安装的路径,否则会报错
make
make install
启动 /usr/local/nginx/sbin/nginx
chown nobody.nobody -R /usr/local/nginx/html
chmod 700 -R /usr/local/nginx/html
=======================================================
设置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 and proxy server.
#              It has a lot of features, but it's not for everyone.
# 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" ] && exit 0
[ -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    #设置开机启动
/etc/rc.d/init.d/nginx restart
service nginx restart
=======================================================
5、安装libmcrypt
cd /usr/local/src
tar zxvf  libmcrypt-2.5.7.tar.gz   #解压
cd  libmcrypt-2.5.7 #进入目录
./configure    #配置
make           #编译
make install   #安装
6、安装php
cd /usr/local/src
tar  zxvf  php-5.2.17.tar.gz
gunzip php-5.2.17-fpm-0.5.14.diff.gz
patch -d php-5.2.17 -p1 < php-5.2.17-fpm-0.5.14.diff  #给php源码打上fpm补丁
cd  php-5.2.17
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd  --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt
make
make install
cd /usr/local/php5/
mkdir etc
cp  /usr/local/src/php-5.2.17/php.ini-dist  /usr/local/php5/etc/php.ini  #复制php配置文件到安装目录
rm -rf  /etc/php.ini   #删除默认配置文件
ln -s   /usr/local/php5/etc/php.ini  /etc/php.ini    #创建链接到系统默认的位置
=========================================================
vi /usr/local/php5/etc/php-fpm.conf
把下面两行的注释去掉
Unix user of processes
<value name="user">nobody</value>
Unix group of processes
<value name="group">nobody</value>
:wq!保存退出
==========================================================
启动php-fpm
/usr/local/php5/sbin/php-fpm start
设置 php-fpm开机启动
cp /usr/local/php5/sbin/php-fpm  /etc/rc.d/init.d/php-fpm
vi /etc/rc.d/init.d/php-fpm
在#!/bin/bash下面添加两行
#chkconfig:345 62 62
#description:php-fpm
:wq!保存退出
chmod 775 /etc/rc.d/init.d/php-fpm  #赋予文件执行权限
chkconfig php-fpm on    #设置开机启动
=========================================================
7、安装Zend optimizer
cd /usr/local/src
mkdir /usr/local/zend
tar xvfz ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz  #解压安装文件
cp /usr/local/src/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so  /usr/local/zend #拷贝文件到安装目录
       rm -rf /usr/local/src/ZendOptimizer-3.3.9-linux-glibc23-i386*   #删除安装包
配置Zend optimizer
       vi /usr/local/php5/etc/php.ini    #编辑文件
       在最后位置添加以下内容
        [Zend Optimizer]
zend_optimizer.optimization_level=15
zend_extension="/usr/local/zend/ZendOptimizer.so"
重启web服务器
       /etc/init.d/nginx restart
/etc/rc.d/init.d/php-fpm   restart
=========================================================================================================
8、配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf
  修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改
  user nobody nobody;          (首行user去掉注释,并与/usr/local/php5/etc/php-fpm.conf中的user,group配置同)
      server {
listen       80;      (修改所使用的端口)
        server_name  localhost; (修改所使用的服务器名)
       index index.php  index.html index.htm;
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  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;
  }
     (取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径)
  完成配置后启动
       /etc/init.d/nginx restart
/etc/rc.d/init.d/php-fpm   restart
=======================================================
#########################################################################################
到此,Nginx+MySQL+PHP+Zend基本运行环境搭建完成!
网站程序上传到/usr/local/nginx/html目录里面,如果安装有问题,请检查目录权限
确保改目录为以下权限
chown nobody.nobody -R /usr/local/nginx/html
chmod 700 -R /usr/local/nginx/html
注意:如果要用于正式生产环境,还需要进一步详细的设置配置系统的安全等各个方面,
安全设置不在本次教程的范围之内,请大家参考相关系统运行安全设置方面的教程!

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容