您的位置:首页 > 数据库 > Memcache

nginx+php(包含mcrypt bcmath zendguardloader mysqli memcached redis扩展)安装配置手册

2016-01-27 17:34 1081 查看
说明:

1、公司用的web服务器一直是tomcat,前段时间开始转nginx,为此搭建了一套nginx+php的环境;

2、安装过程中出现各类问题,特别是php各个扩展包的安装,网上的教程许多不是很完成,查了各种资料后,整理成本文档;

3、包含php扩展模块:mcrypt  bcmath  zendguardloader  mysqli memcached redis;

4、手册中wget的url若不可用,若不能下载,又找不到,可以找我要啦,不建议下载其他版本的包,容易出现报错。

5、入门学习中,多多交流

软件包列表:

2.2.4.tar.gz【phpredis】                   

libxml2-2.9.0.tar.gz     

mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

libevent-2.0.21-stable.tar.gz  

mcrypt-2.6.8.tar.gz      

nginx-1.5.1.tar.gz

libmcrypt-2.5.7.tar.gz         

memcached-1.4.15.tar.gz  

php-5.4.33.tar.gz

libmcrypt-2.5.8.tar.gz         

memcached-2.2.0.tgz    

zabbix_agents_2.2.1.linux2_6.amd64.tar.gz

libmemcached-0.42.tar.gz      

mhash-0.9.9.9.tar.gz     

ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz

软件版本说明

 
软件名称
软件版本
说明
操作系统
Linux version 2.6.32-431.el6.x86_64
克隆虚拟机
nginx
nginx-1.5.1
参照本手册安装
php
php-5.4.33
参照本手册安装
操作部署如下:

1、yum源更新:

清理旧的yum源文件,创建新的yum源文件【若yum源使用的是163,可跳过此步】

cd /etc/yum.repos.d/

rm  -rf  *

vi 99bill.repo   【新建yum源文件,文件内容如下】

[base]

name=CentOS- - Base

baseurl=http://mirrors.163.com/centos/6/os/x86_64/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

下载key文件,并拷贝到:

wget http://mirrors.163.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6

cp RPM-GPG-KEY-CentOS-6  /etc/pki/rpm-gpg/

 

2、基础类库安装:

yum -y install wget make vim install gcc gcc-c++ ncurses ncurses-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
bzip2 bzip2-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel  zlip zlip-devel

 

3、安装nginx
  wget http://nginx.org/download/nginx-1.5.1.tar.gz[/code] 
  tar zxvf nginx-1.5.1.tar.gz

  cd nginx-1.5.1

  ./configure --prefix=/opt/oracle/nginx

  make && make install


4、配置nginx

编辑/opt/oracle/nginx/conf/nginx.conf文件,修改为如下:

#user  www www;

    worker_processes  1;

    events {

        worker_connections  1024;

    }

    http {

        include       mime.types;

        index  index.php index.html index.htm;

        root   /opt/oracle/nginx/html;

        default_type  application/octet-stream;

        sendfile        on;

        keepalive_timeout  65;

        server {

            listen       80;

            server_name  192.168.63.199;

            if ( $host ~* (.*)\.(.*)\.(.*)){

                set $domain $1;

            }

            location ~ ^/(.*)/data/.*\.(php)?$

            {

                return 404;

                deny all;

            }

            location ~ ^/(.*)/themes/.*\.(php)?$

            {

                return 404;

                deny all;

            }

            location ~ ^/(.*)/wap_themes/.*\.(php)?$

            {

                return 404;

                deny all;

            }

            #伪静态配置开始.....

            if ($request_uri ~ (.+?\.php)(|/.*)$ ){

                break;                                                                                                                                 

            }

            location / {

                autoindex  on;

                send_timeout 1800;

                fastcgi_buffers 8 128k;

                fastcgi_intercept_errors on;

                #伪静态配置

                if ( !-e $request_filename ) {

                    rewrite ^/(.*)$ /index.php/$1 last;

                }

            }

            location ~ ^/shopadmin {

                rewrite  ^/(.*)$  /index.php/$1 last;

                break;

            }

           #伪静态配置结束......

           error_page   500 502 503 504  /50x.html;

           location = /50x.html {

               root   html;

           }

           location ~ \.php {

               include        fastcgi_params;

               set $real_script_name $fastcgi_script_name;

               set $path_info "";

               set $real_script_name $fastcgi_script_name;

               if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {

                   set $real_script_name $1;

                   set $path_info $2;

               }

               fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

               fastcgi_param SCRIPT_NAME $real_script_name;

               fastcgi_param PATH_INFO $path_info;

               fastcgi_pass   127.0.0.1:9000;

               fastcgi_index  index.php;

           }

     }

  }

5、启动nginx

创建 /etc/init.d/nginx文件,内容如下:
   #!/bin/sh

     #

     # nginx - this script starts and stops the nginx daemin

     #

     # chkconfig:   - 85 15

     # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \

     #               proxy and IMAP/POP3 proxy server

     # processname: nginx

     # config:      /usr/local/webserver/nginx/conf/nginx.conf

     # pidfile:     /usr/local/webserver/nginx/logs/nginx.pid

     # Source function library.

     . /etc/rc.d/init.d/functions

     # Source networking configuration.

     . /etc/sysconfig/network

     # Check that networking is up.

     [ "$NETWORKING" = "no" ] && exit 0

     nginx="/usr/local/webserver/nginx/sbin/nginx"

     prog=$(basename $nginx)

     NGINX_CONF_FILE="/usr/local/webserver/nginx/conf/nginx.conf"

     lockfile=/var/lock/subsys/nginx

     start() {

         [ -x $nginx ] || exit 5

         [ -f $NGINX_CONF_FILE ] || exit 6

         echo -n $"Starting $prog: "

         daemon $nginx -c $NGINX_CONF_FILE

         retval=$?

         echo

         [ $retval -eq 0 ] && touch $lockfile

         return $retval

     }

     stop() {

         echo -n $"Stopping $prog: "

         killproc $prog -QUIT

         retval=$?

         echo

         [ $retval -eq 0 ] && rm -f $lockfile

         return $retval

     }

     restart() {

         configtest || return $?

         stop

         start

     }

     reload() {

         configtest || return $?

         echo -n $"Reloading $prog: "

         killproc $nginx -HUP

         RETVAL=$?

         echo

     }

     force_reload() {

         restart

     }

     configtest() {

       $nginx -t -c $NGINX_CONF_FILE

     }

     rh_status() {

         status $prog

     }

     rh_status_q() {

         rh_status >/dev/null 2>&1

     }

     case "$1" in

         start)

             rh_status_q && exit 0

             $1

             ;;

         stop)

             rh_status_q || exit 0

             $1

             ;;

         restart|configtest)

             $1

             ;;

         reload)

             rh_status_q || exit 7

             $1

             ;;

         force-reload)

             force_reload

             ;;

         status)

             rh_status

             ;;

         condrestart|try-restart)

             rh_status_q || exit 0

                 ;;

         *)

             echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

             exit 2

     esac


   

   赋权限   
chmod +x /etc/init.d/nginx


  添加到系统服务器  
/sbin/chkconfig nginx on


  启动nginx服务   service nginx start

6、安装gd2

wget http://120.52.73.45/nchc.dl.sourceforge.net/project/gd2/gd-2.0.35.tar.gz

tar zxvf gd-2.0.35.tar.gz

cd gd-2.0.35

./configure --prefix=/opt/oracle/gd2/

make

make install

7、安装php

先安装libxml

  wget http://xmlsoft.org/sources/libxml2-2.9.0.tar.gz

  tar zxvf libxml2-2.9.0.tar.gz

  cd libxml2-2.9.0

  ./configure

【此步若出现报错cannot remove libtoolT: No such file or directory,则编辑configure文件,删除$RM -f "$cfgfile" 行,然后重新编译】

  make&&make install

再安装php

wget  http://ftp.ntu.edu.tw/php/distributions/php-5.4.33.tar.gz

tar -zxvf php-5.4.33.tar.gz

cd php-5.4.33

 ./configure -prefix=/opt/oracle/php5/ -enable-fpm  -with-config-file-path=/opt/oracle/php5/ -with-gd -with-jpeg-dir   -with-zlib -enable-mbstring  -enable-ftp  -disable-debug 

make

make install

cp php.ini-development /opt/oracle/php5/php.ini

cp /opt/oracle/php5/bin/php  /usr/bin/php

8、配置php-fpm启动脚本:

编辑脚本:vi /etc/init.d/php-fpm ,插入如下内容:

     #! /bin/sh

     ### BEGIN INIT INFO

     # Provides:          php-fpm

     # Required-Start:    $remote_fs $network

     # Required-Stop:     $remote_fs $network

     # Default-Start:     2 3 4 5

     # Default-Stop:      0 1 6

     # Short-Description: starts php-fpm

     # Description:       starts the PHP FastCGI Process Manager daemon

     ### END INIT INFO

     prefix=/opt/oracle/php5

     php_fpm_BIN=${prefix}/sbin/php-fpm

     php_fpm_CONF=${prefix}/etc/php-fpm.conf

     php_fpm_PID=${prefix}/var/run/php-fpm.pid

     php_opts="--fpm-config $php_fpm_CONF"

     php_pid="--pid $php_fpm_PID"

     wait_for_pid () {

             try=0

             while test $try -lt 35 ; do

                     case "$1" in

                             'created')

                             if [ -f "$2" ] ; then

                                     try=''

                                     break

                             fi

                             ;;

                             'removed')

                             if [ ! -f "$2" ] ; then

                                     try=''

                                     break

                             fi

                             ;;

                     esac

                     echo -n .

                     try=`expr $try + 1`

                     sleep 1

             done

     }

     case "$1" in

             start)

                     echo -n "Starting php-fpm "

                     $php_fpm_BIN $php_opts $php_pid

                     if [ "$?" != 0 ] ; then

                             echo " failed"

                             exit 1

                     fi

                     wait_for_pid created $php_fpm_PID

                     if [ -n "$try" ] ; then

                             echo " failed"

                             exit 1

                     else

                             echo " done"

                     fi

             ;;

             stop)

                     echo -n "Gracefully shutting down php-fpm "

                     if [ ! -r $php_fpm_PID ] ; then

                             echo "warning, no pid file found - php-fpm is not running ?"

                             exit 1

                     fi

                     kill -QUIT `cat $php_fpm_PID`

                     wait_for_pid removed $php_fpm_PID

                     if [ -n "$try" ] ; then

                             echo " failed. Use force-exit"

                             exit 1

                     else

                             echo " done"

                     fi

                           ;;

             force-quit)

                     echo -n "Terminating php-fpm "

                     if [ ! -r $php_fpm_PID ] ; then

                             echo "warning, no pid file found - php-fpm is not running ?"

                             exit 1

                     fi

                     kill -TERM `cat $php_fpm_PID`

                     wait_for_pid removed $php_fpm_PID

                     if [ -n "$try" ] ; then

                             echo " failed"

                             exit 1

                     else

                             echo " done"

                     fi

             ;;

             restart)

                     $0 stop

                     $0 start

             ;;

             reload)

                     echo -n "Reload service php-fpm "

                     if [ ! -r $php_fpm_PID ] ; then

                             echo "warning, no pid file found - php-fpm is not running ?"

                             exit 1

                     fi

                     kill -USR2 `cat $php_fpm_PID`

                     echo " done"

             ;;

             *)

                     echo "Usage: $0 {start|stop|force-quit|restart|reload}"

                     exit 1

             ;;

     esac

   赋予脚本执行权限:


      cd /opt/oracle/php5/
 
etc/  


      cp php-fpm.conf.default php-fpm.conf


               
chmod +x /etc/init.d/php-fpm


   设置开机启动:
/sbin/chkconfig php-fpm on

   启动php-fpm: service php-fpm start


9、测试是否安装正确:

vi /opt/oracle/nginx/html/test.php (添加内容如下)

<?php

echo phpinfo();

?>

打开浏览器,访问:

http://192.168.63.199/test.php  

若能显示php信息,则安装正常,否则请检查防火墙是否关闭,关闭防火墙,并重启nginx和php-fpm.

10、安装php扩展模块: mcrypt  bcmath  zendguardloader  mysqli  memcached  redis

安装:mcrypt

首先安装libmcrypt

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz 


tar -zxvf libmcrypt-2.5.7.tar.gz 


cd libmcrypt-2.5.7 


./configure


make


make install 


 


其次安装mhash

wget http://120.52.73.46/nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

tar -zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure -prefix=/usr/local/mhash

make

make install

然后安装mcrypt

 wget http://120.52.73.47/nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

tar -zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/mhash/lib

export LDFLAGS="-L/usr/local/mhash/lib -I/usr/local/mhash/include/"

export CFLAGS="-I/usr/local/mhash/include/"

./configure --prefix=/usr/local/mcrypt   -with-libmcrypt-prefix=/usr/local/libmcrypt

make

make install

最后安装mcrypt扩展

cd  /root/php-5.4.33/ext/mcrypt

/opt/oracle/php5/bin/phpize

./configure --with-php-config=/opt/oracle/php5/bin/php-config

make

make install

安装:bcmath

cd  /root/php-5.4.33/ext/bcmath

/opt/oracle/php5/bin/phpize

 ./configure  --with-php-config=/opt/oracle/php5/bin/php-config

make

make install

echo 'extension=bcmath.so' >> /opt/oracle/php5/php.ini

安装:zendguardloader

wget http://blog.ich8.com/wp-content/uploads/2013/06/ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz

tar zxvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz

cp /root/ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so /opt/oracle/php5/lib/php/extensions/no-debug-non-zts-20100525/

修改php.ini

vi /opt/oracle/php5/php.ini

在文件结尾增加如下行:

[Zend.loader]                                 

zend_loader.enable=1                           

zend_loader.disable_licensing=0                

zend_loader.obfuscation_level_support=3        

;zend_loader.license_path= "/opt/oracle/nginx/html/billstore/config/developer.zl" 

zend_extension="/opt/oracle/php5/lib/php/extensions/no-debug-non-zts-20100525/ZendGuardLoader.so"

【注意zend_loader.license_path配置路径由项目码源路径决定,当前为注释状态】

安装:mysqli

 

wget http://120.52.72.38/cdn.mysql.com/c3pr90ntcsf0//archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz


tar zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

cd /usr/local/

mv mysql-5.6.12-linux-glibc2.5-x86_64 mysql

cd /root/php-5.4.33/ext/mysqli

/opt/oracle/php5/bin/phpize

./configure --with-php-config=/opt/oracle/php5/bin/php-config  --with-mysqli=/usr/local/mysql/bin/mysql_config

make & make install

 

安装:memcached

首先安装libevent

wget https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

tar -zxvf libevent-2.0.21-stable.tar.gz

cd libevent-2.0.21-stable/  

./configure --prefix=/usr/local/libevent/

make && make install
 

其次安装memcached

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz

 tar -zxvf memcached-1.4.15.tar.gz

cd memcached-1.4.15

./configure --prefix=/usr/local/memcache/ --with-libevent=/usr/local/libevent/ 

make && make install

然后安装libmemcache

wget http://launchpad.net/libmemcached/1.0/0.42/+download/libmemcached-0.42.tar.gz

tar -zxvf libmemcached-0.42.tar.gz

cd libmemcached-0.42

./configure --prefix=/usr/local/libmemcached  --with-memcached

make && make install

最后安装memcached扩展

wget http://120.52.72.37/pecl.php.net/c3pr90ntcsf0/get/memcached-2.2.0.tgz

 tar -zxvf memcached-2.2.0.tgz

cd memcached-2.2.0

/opt/oracle/php5/bin/phpize

./configure --with-php-config=/opt/oracle/php5/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached

make && make install

修改php.ini

vi /opt/oracle/php5/php.ini

在文件结尾增加如下行:

extension="/opt/oracle/php5/lib/php/extensions/no-debug-non-zts-20100525/memcached.so"

安装:redis

 wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

tar -zxvf 2.2.4.tar.gz

cd phpredis-2.2.4/

/opt/oracle/php5/bin/phpize

./configure --with-php-config=/opt/oracle/php5/bin/php-config

make && make install

修改php.ini

vi /opt/oracle/php5/php.ini

在文件结尾增加如下行:

extension="/opt/oracle/php5/lib/php/extensions/no-debug-non-zts-20100525/redis.so"

11、重启nginx和php

service nginx restart

service php-fpm restart

打开http://192.168.63.199/test.php,检查各个模块安装是否成功 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息