• nginx整合php+lua+oracle环境搭建


     
    nginx整合php+lua+oracle环境搭建
    
    标签: nginxluaoraclephplinux
    2014-09-25 10:39 1473人阅读 评论(0) 收藏 举报
     分类:
     
    技术(70) 
    版权声明:本文为博主原创文章,未经博主允许不得转载。
    
    *执行 yum update   为了得到一个最新的系统
    
    *执行 rpm -ivh 
    
    oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm 
    
    oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm 
    
    oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
    
    安装oracle客户端
    
    *执行 echo "/usr/lib/oracle/12.1/client64/lib/" > /etc/ld.so.conf.d/oracle_client.conf  
    
    *执行 ldconfig  设置加载库并加载
    
    *执行 ldconfig -v | grep oracle  判定是否加载成功
    
     
    
    *执行 vim /etc/profile
    
    添加
    
    export ORACLE_HOME=/usr/lib/oracle/12.1/client64/
    
    export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/
    
    export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
    
    *执行  source /etc/profile  设置oracle环境变量 并生效
    
    *执行  echo $ORACLE_HOME  验证环境变量是否生效
    
     
    
    *执行 hostname
    
    *执行 vim /etc/hosts
    
     添加 127.0.0.1 hostname的结果
    
     
    
    *执行 sqlplus64 用户名/密码@远程位置/数据库  测试oracle客户端是否生效
    
     
    
     
    
    *执行 tar -zxvf libmcrypt-2.5.7.tar.gz
    
    *执行 cd libmcrypt-2.5.7
    
    *执行 ./configure
    
    *执行 make
    
    *执行 make install
    
     
    
    *执行 tar -zxvf redis-2.8.15.tar.gz
    
    *执行 mv redis-2.8.15 /usr/local/redis
    
    *执行 cd /usr/local/redis
    
    *执行 make
    
    *执行 vi /usr/local/redis/redis.conf
    
    打开配置文件
    
    daemonize yes
    
    unixsocket /tmp/redis.sock
    
    dir /opt/redis/
    
    *执行 mkdir /opt/redis
    
    *启动 /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
    
     
    
    *执行 tar -zxvf php-5.5.16.tar.gz 
    
    *执行 cd php-5.5.16
    
    *执行 ./configure --prefix=/usr/local/php --enable-fpm --with-openssl --with-zlib --with-curl --enable-exif --with-zlib-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt --enable-sysvshm --enable-soap --enable-sockets  --enable-opcache --enable-zip --enable-mysqlnd --with-xsl --with-pear
    
    *提示 configure: error: xml2-config not found. Please check your libxml2 installation.
    
    *执行 yum install libxml2-devel
    
    *提示 configure: error: Cannot find OpenSSL's <evp.h>
    
    yum install openssl-devel
    
    *提示 error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
    
    yum install libcurl-devel
    
    *提示 configure: error: jpeglib.h not found.
    
    yum install libjpeg-turbo-devel
    
    *提示 configure: error: png.h not found.
    
    yum install libpng-devel
    
    *提示 configure: error: freetype-config not found.
    
    yum install freetype-devel
    
    *提示 configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
    
    yum install libxslt-devel
    
    *执行 make
    
    *执行 make install
    
     
    
    *执行 cp php.ini-development /usr/local/php/lib/php.ini
    
    *执行 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    
    vim
    
    打开
    
    pid = run/php-fpm.pid
    
    error_log = log/php-fpm.log
    
    log_level = notice
    
    daemonize = yes
    
     
    
    *执行 cd 源码目录/ext/oci8/
    
    *执行 /usr/local/php/bin/phpize
    
    *执行 ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib  --with-php-config=/usr/local/php/bin/php-config
    
    *执行 make
    
    *执行 make install
    
     
    
    *执行 cd 源码目录/ext/pdo_oci/
    
    *执行 /usr/local/php/bin/phpize
    
    *执行 ./configure --with-pdo-oci=instantclient,/usr,12.1 --with-php-config=/usr/local/php/bin/php-config
    
    *执行 make
    
    *执行 make install
    
     
    
    *执行 unzip phpredis.zip
    
    *执行 cd phpredis-master
    
    *执行 ./configure --with-php-config=/usr/local/php/bin/php-config
    
    *执行 make
    
    *执行 make install
    
     
    
    vi /usr/local/php/lib/php.ini
    
    添加
    
    extension=redis.so
    
    extension=oci8.so
    
    extension=pdo_oci.so
    
    date.timezone = "Asia/Shanghai"
    
     
    
    *执行 /usr/local/php/bin/php -m | grep redis
    
    *执行 /usr/local/php/bin/php -m | grep oci8
    
    判断加载模块是否成功
    
    [php test.php]
    
    <?php
    
    $oracle_host= "";
    
    $oracle_dbname = "";
    
    $oracle_user = "";
    
    $oracle_pwd = "";
    
    $redis_host = "127.0.0.1";
    
    $redis_port = "6379";
    
    function oracle_connect()
    
    {
    
            global $oracle_host,$oracle_dbname, $oracle_user,$oracle_pwd;
    
            try{
    
                    $conn = new PDO("oci:dbname=//{$oracle_host}/{$oracle_dbname};charset=AL32UTF8",$oracle_user,$oracle_pwd);
    
            }catch(PDOException $e){
    
                    echo ($e->getMessage());
    
                    return false;
    
            }
    
            return $conn;
    
    }
    
    echo "oracle connect:";
    
    print_r(oracle_connect());
    
    echo "
    ";
    
    echo "redis connect:";
    
    $redis = new Redis();
    
    $redis->connect($redis_host, $redis_port);
    
    print_r($redis);
    
    ?>
    
    [/php]
    
     
    
    *执行 /usr/local/php/bin/php -f test.php  无报错表示成功
    
     
    
    *执行 tar -zxvf luarocks-2.1.2.tar.gz
    
    *执行 cd luarocks-2.1.2
    
    *执行 ./configure
    
    *执行 make build
    
    *执行 make install
    
    *执行 luarocks install  luasocket
    
     
    
    unzip luasocket-2.0.3-rc1.zip 
    
    cd luasocket-2.0.3
    
    vi config 
    
    修改
    
    INSTALL_TOP_SHARE=/usr/share/lua/5.1
    
    INSTALL_TOP_LIB=/usr/lib64/lua/5.1
    
    关闭
    
    #------
    
    # Compiler and linker settings
    
    # for Mac OS X
    
    #
    
    CC=gcc
    
    DEF= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN
    
    CFLAGS= $(LUAINC) $(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common
    
    LDFLAGS=-bundle -undefined dynamic_lookup
    
    LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
    
    打开
    
    #------
    
    # Compiler and linker settings
    
    # for Linux
    
    CC=gcc
    
    DEF=-DLUASOCKET_DEBUG 
    
    CFLAGS= $(LUAINC) $(DEF) -pedantic -Wall -O2 -fpic
    
    LDFLAGS=-O -shared -fpic
    
    LD=gcc 
    
    *执行 make
    
    *执行 make install
    
     
    
    *执行 unzip lua-nginx-module.zip
    
    *执行 unzip ngx_devel_kit.zip
    
    *执行 tar -zxvf nginx-1.6.2.tar.gz
    
    *执行 cd nginx-1.6.2
    
    *执行 ./configure --prefix=/usr/local/nginx --add-module=../ngx_devel_kit-master/ --add-module=../lua-nginx-module-master/ --with-pcre --with-debug --with-poll_module --with-file-aio --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_secure_link_module
    
    *提示 ./configure: error: ngx_http_lua_module requires the Lua library.
    
    yum install lua-devel
    
    *提示 ./configure: error: the HTTP rewrite module requires the PCRE library.
    
    yum install pcre-devel
    
    *执行 make
    
    *执行 make install
    
     
    
    编辑添加nginx 测试
    
    [nginx conf]
    
       server{
    
            listen 8080;
    
            location /lua/ {
    
                    default_type 'text/plain';
    
                    content_by_lua_file /usr/local/nginx/html/test.lua;
    
            }
    
            location /{
    
            }
    
            location ~ .php$ {
    
                    root           /usr/local/nginx/html/;
    
                    fastcgi_pass   127.0.0.1:9000;
    
                    fastcgi_index  test.php;
    
                    fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
    
                    include        fastcgi_params;
    
            }
    
        }
    
    [/nginx]
    
     
    
    *启动 /usr/local/php/sbin/php-fpm 
    
    *执行 ps aux |  grep php 确认启动成功
    
     
    
    *启动 /usr/local/nginx/sbin/nginx
    
    *执行 ps aux |  grep nginx 确认启动成功
    
     
    
    *启动 /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
    
    *执行 ps aux |  grep redis 确认启动成功
    
     
    
    vim /usr/local/nginx/html/test.php
    
    [php test.php]
    
    <?php
    
    $oracle_host= "";
    
    $oracle_dbname = "";
    
    $oracle_user = ";
    
    $oracle_pwd = "";
    
    $redis_host = "127.0.0.1";
    
    $redis_port = "6379";
    
    function oracle_connect()
    
    {
    
            global $oracle_host,$oracle_dbname, $oracle_user,$oracle_pwd;
    
            try{
    
                    $conn = new PDO("oci:dbname=//{$oracle_host}/{$oracle_dbname};charset=AL32UTF8",$oracle_user,$oracle_pwd);
    
            }catch(PDOException $e){
    
                    echo ($e->getMessage());
    
                    return false;
    
            }
    
            return $conn;
    
    }
    
    echo "oracle connect:";
    
    print_r(oracle_connect());
    
    echo "<br/>";
    
    echo "redis connect:";
    
    $redis = new Redis();
    
    $redis->connect($redis_host, $redis_port);
    
    print_r($redis);
    
    echo "<br/>";
    
    phpinfo();
    
    ?>
    
    [/php]
    
     
    
    *执行 unzip redis-lua-version-2.0.zip
    
    *执行 cd redis-lua-version-2.0
    
    *执行 cp src/redis.lua /usr/share/lua/5.1/
    
     
    
    *执行 unzip luautf8.zip
    
    *执行 cd luautf8-master/
    
    *执行 gcc -shared -O3 lutf8lib.c -o utf8.so -fPIC
    
    *执行 cp utf8.so /usr/lib64/lua/5.1/utf8.so
    
    [lua test.lua]
    
    utf8 = require("utf8")
    
    local inu_str = "11a我";
    
    local str_len = utf8.len(inu_str)
    
    print("utf8 test:")
    
    print(utf8.sub(inu_str,0,2))
    
    print("
    ")
    
     
    
    local redis = require("redis")
    
    local client = redis.connect('127.0.0.1', 6379)
    
    local response = client:ping()
    
    print("redis test:")
    
    print(response)
    
    print("
    ")
    
    [/lua]
    
     
    
    *执行 lua test.lua 测试模块有效性
    
     
    
    *执行 vim /usr/local/nginx/html/test.lua
    
    [lua test.lua]
    
    utf8 = require("utf8")
    
    local inu_str = "11a我";
    
    local str_len = utf8.len(inu_str)
    
    ngx.say("utf8 test:")
    
    ngx.say(utf8.sub(inu_str,0,2))
    
    ngx.say("<br/>")
    
     
    
    local redis = require("redis")
    
    local client = redis.connect('127.0.0.1', 6379)
    
    local response = client:ping()
    
    ngx.say("redis test:")
    
    ngx.say(response)
    
    ngx.say("
    ")
    
    [/lua]
    
    *执行 /usr/local/nginx/sbin/nginx -t  测试nginx跟lua整合
    
     
    
     
    
    *需要oralce完整安装包
    
    unzip luasql.zip
    
    cd luasql-master
    
    vi config
    
    核心配置
    
    DRIVER_LIBS= -L$(ORACLE_HOME)/lib -lz -lclntsh
    
    DRIVER_INCS= -I$(ORACLE_HOME)/rdbms/demo -I$(ORACLE_HOME)/rdbms/public
    
    make
    
    make install
    
     
    
    *提示 libclntsh.so 找不到
    
    *执行 echo "/opt/oracle/lib/" > /etc/ld.so.conf.d/oracle_client.conf
    
    *执行 ldconfig
    
     
    
    [lua test_oracle.lua]
    
    require "luasql.oci8"
    
    env = assert (luasql.oci8())
    
    con = assert (env:connect(库名,用户名,密码,连接地址,端口))
    
    [/lua]
  • 相关阅读:
    关于 php json float 出现很多位的问题
    做 Excel 的 XML schema.xsd
    笔记:Python 默认参数必须指向不变对象
    Bartender 使用 Excel xlsx 数据库时出现 0x800A0E7A
    Javascript 中 的 for ... in 和 for ... of 差别
    关于跨域资料收集 (2019-01-11)
    ThinkPHP3 和 ThinkPHP5 不是一个团队做的
    记录一下:给电推剪改锂电池
    为你的Web程序加个启动画面
    前端不为人知的一面--前端冷知识集锦 前端已经被玩儿坏了!像console.log()可以向控制台输出图片
  • 原文地址:https://www.cnblogs.com/archoncap/p/5252983.html
Copyright © 2020-2023  润新知