WHM/cPanel Server uses Python for Mailman, yum etc. This means cPanel relies on the older Python 2.x installations for its working and replacing that may cause serious issues.
CentOS/RHEL 6 and 7 ships with Python 2.x. The latest version of Python available in CentOS/RHEL 6 is 2.6.6 and CentOS/RHEL 7 is 2.7.5. However the latest version of Python available is 3.x.x and most of the tools used now requires higher Python 3.x.x versions.
In this tutorial, we will see how to install Python 3.x.x version in a cPanel server without disturbing the base python installation.
Make sure the system is up to date.
# yum update
This version of python is installed from source. So we need to install compilers and related development tools.
# yum groupinstall -y "development tools"
After installing the development tools, install the libraries that are essential for the full functioning of Python. Some of the packages may be already available. To avoid compilation and runtime errors, follow the below steps to install the required packages.
# yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
https://www.python.org/ftp/python/ and choose the version of python as per your requirement and find the
tar.gz file. We will choose Python version
3.6.3 in this example.
# cd /usr/local/src
# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
Extract the TAR file
# tar xzf Python-3.6.3.tgz
# cd Python-3.6.3
In this example, we will install python to
“/usr/local/python3.6”. So this should be passed to the configure command with
--enable-shared flag to the configure command will enable python to be compiled as a shared library. This would be an advantage if multiple python processes are running for different dependent tools.
LDFLAGS="-Wl,-rpath /usr/local/lib" flag will help the executable to find its shared library.
Compile python using the following command.
# ./configure --prefix=/usr/local/python3.6 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
Wait for the process to complete and issue the make command.
make command should complete without errors, if everything you do is correct. Be sure that you use
make altinstall rather than
‘make install’. The
‘make install’ command will mess up with the already existing python. So install using the command,
# make altinstall
This will install python to the said directory,
Add the lib folder to the library path and update our global PATH so that
python3.6 is available globally upon login.
Add the following text to
/etc/profile.d/python3.6.sh with a text editor.
Similarly, create a file
/etc/ld.so.conf.d/opt-python3.6.conf and add the following content to it.
Update the current session and the servers library cache by issuing the following commands in shell,
# source /etc/profile.d/python3.6.sh
This will complete the
python 3.x.x setup on a WHM/cPanel server without changing the base installation. The python installed just now can be called by typing in
python3.6 in shell. The base python can be used by just python command.
pip which is essential to install python packages is also installed along with this.