RHEL6.8编译安装Tengine+PHP categories: Linux


title: RHEL6.8编译安装Tengine+PHP
categories: Linux
tags:
- Tengine
- Nginx
- PHP
timezone: Asia/Shanghai
date: 2019-01-15

环境

[root@rehl6802 conf]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.8 (Santiago)

[root@rehl6802 conf]# /usr/local/nginx/sbin/nginx -v
Tengine version: Tengine/2.2.3 (nginx/1.8.1)

[root@rehl6802 conf]# php-fpm -v
PHP 5.6.40 (fpm-fcgi) (built: Jan 16 2019 05:55:21)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

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

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

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 groupinstall -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 && echo $?
make && make install && echo $?
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 && echo $?
make && make install && echo $?
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 && echo $? && echo $?

ln -s /usr/local/lib/libpcre.so.1 /lib64
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 && echo $?
make && make install && echo $?
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

第二步:安装PHP支持

1.安装支持
yum install -y cyrus-sasl-2.1.23-15.el6_6.2.x86_64.rpm \
                cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64.rpm \
                freetype-devel-2.3.11-17.el6.x86_64.rpm \
                libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64.rpm \
                libpng-1.2.49-2.el6_7.x86_64.rpm \
                libpng-devel-1.2.49-2.el6_7.x86_64.rpm \
                libxml2-2.7.6-21.el6.x86_64.rpm \
                libxml2-devel-2.7.6-21.el6.x86_64.rpm \
                openldap-2.4.40-16.el6.x86_64.rpm \
                openldap-devel-2.4.40-16.el6.x86_64.rpm \
                zlib-devel-1.2.3-29.el6.x86_64.rpm
2.下载并安装PHP5.6.40并安装
wget http://101.96.10.63/cn2.php.net/distributions/php-5.6.40.tar.gz
tar -vxf php-5.6.40.tar.gz
cp -frp /usr/lib64/libldap* /usr/lib/
cd php-5.6.40
./configure --enable-bcmath --enable-mbstring --enable-fpm --enable-mbstring \
    --enable-sockets --with-mysql --with-gettext \
    --with-ldap --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gd \
    && echo $?

make && make install && echo $?
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

附录:本文章所有用到离线包

参考:http://php.net/manual/en/install.unix.nginx.php

PHP-5.6.40:https://pan.baidu.com/s/1pCeQj63vei-8HQsj2rkPJQ

Tengine-2.2.3:https://pan.baidu.com/s/1sR-39mw5RJ9q5mCu-Loupg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值