首页 > 代码库 > 在centos搭建php和python的apns2环境
在centos搭建php和python的apns2环境
版本:
CentOS-6.5-x86_64
OpenSSL 1.0.2j
curl 7.50.3
php PHP 7.0.12
1.升级openssl
进入openssl源码文件
./config --prefix=/usr --shared
make
make depend
make install
注意:openssl.cnf这个文件要替换原来系统里面的
2.升级curl
curl 要先安装nghttp2
yum install libnghttp2
(线上环境可能不需要以下两步)
sudo yum groupinstall "Development Tools"
sudo yum install libev libev-devel zlib zlib-devel openssl openssl-devel git
进入curl源码文件
./configure --prefix=/usr/local/curl \
--with-nghttp2=/usr/local \
--with-ssl=/usr/local/ssl
make
make install
注意:curl-config这个文件要替换系统原来的
3.升级php
3.1(线上环境可能不需要以下几步)
重新安装libxml2和libxml2-devel包
yum install libxml2
yum install libxml2-devel -y
yum install -y bzip2 bzip2-devel
3.2
进入php源码文件
./configure --prefix=/usr/local/php \
--with-ssl=/usr/local/ssl \
--with-openssl \
--with-curl
make && make install
验证升级结果:
curl --version
openssl必须是新升级的版本,必须显示http2字样
phpinfo配置必须显示以下信息
cURL Information => 7.50.3
HTTP2 => Yes
SSL Version => OpenSSL/1.0.2j
在centos配置python环境
提前安转依赖包
sudo yum groupinstall "Development Tools"
sudo yum install libev libev-devel zlib zlib-devel openssl openssl-devel git
yum install libxml2
yum install libxml2-devel -y
yum install -y bzip2 bzip2-devel
yum install sqlite-devel
yum install openssl-devel.i686
yum install readline-devel
yum install bzip2-devel.i686
yum install gdbm-devel.i686
yum install libdbi-devel.i686
yum install ncurses-libs
yum install zlib-devel.i686
yum -y install gcc gcc-c++ 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 ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-server libstdc++.so.6 libnspr4.so libssl.so.6
---以上线上环境可能不需要再安装-----
sudo yum install gcc libffi-devel python-devel openssl-devel (必须)
(1)先把python2.6.6升级为2.7的版本
cd Python-2.7.12
vim Modules/Setup.dist
找到
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl#_ssl _ssl.c \
# -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
# -L$(SSL)/lib -lssl -lcrypto
把前面的 # 号去掉,修改为
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl #(这个修改线上为实际的路径)
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
安装
./configure
make all && make install && make clean && make distclean
5.查看版本信息
/usr/local/bin/python2.7 -V
6.建立软连接,使系统默认的 python指向 python2.7
mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python
7.重新检验Python 版本
python -V
8解决系统 Python 软链接指向 Python2.7 版本后,因为yum是不兼容 Python 2.7的,所以yum不能正常工作,我们需要指定 yum 的Python版本
vi /usr/bin/yum
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6
(2)然后升级pip
下载最新版的pip,然后安装
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
查找pip的位置
1
whereis pip
找到pip2.7的路径,为其创建软链作为系统默认的启动版本
1
ln -s /usr/local/bin/pip2.7 /usr/bin/pip
(3)安装依赖库
pip install cryptography
pip install pyOpenSSL
pip install hyper
检验环境搭建是否成功:
命令行输入python
import ssl
print ssl.OPENSSL_VERSION
(成功会出现最新安装的openssl的版本号)
ssl.HAS_ALPN
(成功会返回true)
在centos搭建php和python的apns2环境