Tuesday 1 September 2015

Compile Python with Custom OpenSSL in CentOS/Redhat Linux [ Python 2.7.9 OpenSSL 1.0.1 TLS 1.2 ]


Step 1#
wget https://www.openssl.org/source/openssl-1.0.1p.tar.gz
tar xzvf openssl-1.0.1p.tar.gz
cd openssl-1.0.1p
./config shared --prefix=/usr/local/openssl_1_0_1p

make
make install


Step 2#
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz


tar xzvf Python-2.7.9.tgz
cd Python-2.7.9
 

vim Modules/Setup.dist

###Modify & Enable below Lines###

SSL=/usr/local/openssl_1_0_1p
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

:wq


./configure --prefix=/usr/local/python2.7.9 --enable-unicode=ucs4 --enable-shared
 

ln -s /usr/local/openssl_1_0_1p/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.0
ln -s /usr/local/openssl_1_0_1p/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.0
make
make install


Step 3#
#/usr/local/python2.7.9/bin/python
>import ssl 
>ssl.OPENSSL_VERSION 

The Result will show the above installed openSSL version


Extra Errors:

Action:
#cd setuptools-21
#/usr/local/python_2.7_10/bin/python setup.py install

Error:

No PyErr_ReplaceException File

Solution:

export PATH=/usr/local/python_2.7_10/bin/:$PATH
export LD_LIBRARY_PATH=/usr/local/python_2.7_10/lib/:$LD_LIBRARY_PATH

vim /usr/local/python_2.7_10/include/python2.7/pyerrors.h
##Disable below line##

PyAPI_FUNC(void) _PyErr_ReplaceException(PyObject *, PyObject *, PyObject *);

:wq

make
make install
#cd setuptools-21
#/usr/local/python_2.7_10/bin/python setup.py install