美文网首页
CentOS7下源码方式安装Tengine+PHP5.5.38

CentOS7下源码方式安装Tengine+PHP5.5.38

作者: 小六的昵称已被使用 | 来源:发表于2019-02-25 18:34 被阅读0次

    title: CentOS7下源码方式安装Tengine+PHP5.5.38
    categories: Linux
    tags:
    - Tengine
    - PHP
    timezone: Asia/Shanghai
    date: 2019-02-25


    环境

    [root@centos181001 ~]# cat /etc/centos-release
    CentOS Linux release 7.6.1810 (Core)
    
    [root@centos181001 ~]# /opt/tengine/sbin/nginx -v
    Tengine version: Tengine/2.2.2 (nginx/1.8.1)
    

    第一步:关闭系统默认防火墙

    setenforce 0
    sed -i -r "/^SELINUX=/c SELINUX=disabled" /etc/selinux/config
    which systemctl && systemctl stop firewalld
    which systemctl && systemctl disable firewalld
    which systemctl && systemctl stop iptables || service iptables stop
    which systemctl && systemctl disable iptables || chkconfig iptables off
    

    第二步:安装Tengine(在线yum安装和离线源码方式安装)

    安装方法1:离线安装

    1.配置本地yum并安装开发工具

    mkdir /mnt/cdrom
    mount /dev/cdrom /mnt/cdrom

    cat <<EOF >/etc/yum.repos.d/local.repo
    [local]
    name=local
    baseurl=file:///mnt/cdrom
    gpgcheck=0
    enabled=1
    EOF
    
    yum clean all       #清理本地缓存
    yum clean plugins   #清理插件缓存
    yum makecache       #构建缓存
    
    yum group install -y "Development Tools"
    

    2.下载安装PCRE

    curl -o /home/pcre-8.42.tar.gz https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
    tar vxzf pcre-8.42.tar.gz
    cd pcre-8.42
    ./configure
    make
    make install
    

    3.下载安装zlib

    wget http://www.zlib.net/zlib-1.2.11.tar.gz
    tar vxzf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure
    make
    make install
    

    4.下载安装OpenSSL

    wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
    tar vxzf openssl-1.1.1a.tar.gz
    cd openssl-1.1.1a
    ./config
    make
    make install
    
    ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
    ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
    
    openssl version
    

    5.下载并安装Tengine

    curl -o /home/tengine-2.2.3.tar.gz http://tengine.taobao.org/download/tengine-2.2.3.tar.gz
    tar -vxf tengine-2.2.3.tar.gz
    cd tengine-2.2.3
    ./configure --with-http_ssl_module
    make
    make install
    

    6.完成安装并启动

    默认安装路径:/usr/local/nginx

    # 启动Nginx
    /usr/local/nginx/sbin/nginx
    
    # 优雅的重启(重载配置文件,如果配置文件有错误的话,会继续使用之前配置运行)
    /usr/local/nginx/sbin/nginx -s reload
        -s stop     快速停止
        -s quit     优雅的退出
        -s reopen   重新打开日志文件
        -s reload   重新加载配置文
    
    # 测试配置文件是否正确
    /usr/local/nginx/sbin/nginx -t
    

    安装方法2:采用阿里云官方yum源方式安装

    1.设置Tengine官方YUM源:CentOS7

    curl -o /etc/yum.repos.d/opsx-centos7.repo https://mirrors.aliyun.com/opensource/149994924900000037/opsx/centos7/opsx-centos7.repo
    yum clean all       #清理本地缓存
    yum clean plugins   #清理插件缓存
    yum makecache       #构建缓存
    

    3.安装Tengine并启动

    yum install -y tengine
    /opt/tengine/sbin/nginx
    

    4.配置文件路径

    默认安装路径在:/opt/tengine

    # 测试配置文件是否正确
    /opt/tengine/sbin/nginx -t
    
    # 优雅的重启(重载配置文件,如果配置文件有错误的话,会继续使用之前配置运行)
    /opt/tengine/sbin/nginx -s reload
        -s stop     快速停止
        -s quit     优雅的退出
        -s reopen   重新打开日志文件
        -s reload   重新加载配置文
    

    注意:在CentOS7下只配置Tengine官方yum源可以安装成功,REHL7下提示缺少依赖,所以这里同时配置了163的yum源。

    cat <<EOF >/etc/yum.repos.d/163.repo
    [163]
    name=163
    baseurl=http://mirrors.163.com/centos/7/os/x86_64/
    gpgcheck=0
    enabled=1
    EOF
    

    第三步:安装PHP5.5.38

    1.安装支持

    yum install -y libxml2 \
                    libxml2-devel \
                    libjpeg-devel \
                    libpng-devel \
                    freetype-devel \
                    openldap \
                    openldap-devel
    
    cp -frp /usr/lib64/libldap* /usr/lib/
    

    2.下载安装PHP

    wget http://101.96.10.58/cn2.php.net/distributions/php-5.5.38.tar.gz
    tar -vxf php-5.5.38.tar.gz
    cd php-5.5.38
    ./configure --enable-mbstring \
                --enable-sockets --with-mysql --with-gettext \
                --with-ldap --with-png-dir --with-jpeg-dir \
                --with-freetype-dir --with-gd \
                && echo $?
    make
    make test
    make install && echo $?
    
    安装过程中可能遇到的错误:
    error adding symbols: DSO missing from command line
    
    解决方法:
    在PHP源码目录下打开 Makefile 找到 EXTRA_LIBS 行,在行末添加 -llber 保存退出再次make clean && make即可。
    
    https://segmentfault.com/a/1190000002462705
    

    3.获取配置文件并将其移动到正确的位置

    cp php.ini-development /usr/local/php/php.ini
    cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
    cp sapi/fpm/php-fpm /usr/local/bin
    
    4.修改配置文件防止脚本注入
    # It is important that we prevent Nginx from passing requests to the PHP-FPM backend if the file does not exists, 
    # 重要的是,如果文件不存在,我们阻止Nginx将请求传递给PHP-FPM后端
    # allowing us to prevent arbitrarily script injection.
    # 这样我们就可以防止任意脚本注入。
    # We can fix this by setting the cgi.fix_pathinfo directive to 0 within our php.ini file.
    # 我们可以通过在php.ini文件中将cgi.fix_pathinfo 指令设置为0来解决这个问题 。
    
    vim /usr/local/php/php.ini
    # 修改为:
    cgi.fix_pathinfo=0
    
    5.现在可以启动php-fpm服务
    /usr/local/bin/php-fpm
    
    6.修改Tengine配置文件
    vim /usr/local/nginx/conf/nginx.conf
    
    # 增加以下内容
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            #fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            include        fastcgi_params;
        }
    
    # 修改以下内容(增加index.php)
    location / {
            root   html;
            index  index.html index.htm;
        }
    
    7.重启Nginx服务并测试
    vim /usr/local/nginx/html/index.php
    
    <?php
            phpinfo();
    ?>
    
    /usr/local/nginx/sbin/nginx -s reload
    
    
    
    yum install curl curl-devel
    


    ./configure --enable-mbstring
    --enable-fpm
    --enable-sockets
    --with-gettext
    --with-ldap
    --with-png-dir
    --with-jpeg-dir
    --with-freetype-dir
    --with-gd
    --with-pdo-mysql
    --with-mysql-sock=/var/lib/mysql/mysql.sock
    --with-curl=/usr/local/lib/curl/
    --with-mysqli=/usr/bin/mysql_config

    extension=curl.so

    相关文章

      网友评论

          本文标题:CentOS7下源码方式安装Tengine+PHP5.5.38

          本文链接:https://www.haomeiwen.com/subject/dazgyqtx.html