There is no one-size-fits-all answer to this question, as the best way to install Python on a WHM server will vary depending on the specific server configuration and software setup. However, some general tips on how to install Python on a WHM server include:
1. Check if Python is already installed on the server. Many WHM servers come with Python pre-installed, so it is worth checking if this is the case before proceeding with a new installation.
2. Choose the desired Python version. Python comes in two main versions, Python 2 and Python 3. While Python 2 is the older version, it is still widely used, so it is worth considering which version is best suited for your needs before proceeding with the installation.
I will suggest installing the latest version and to install it as an additional python version to not mess up the existing version because it could be used by some cpanel services.
How to install python using terminal
1. go to terminal and open folder:
cd /usr/local/src
2. Download the latest python version from https://www.python.org/ftp/python/ in my case it was Python-3.9.9.tgz:
wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz
3. Extract the file and go to that directory:
tar xzf Python-3.9.9.tgz
cd Python-3.9.9
4. Compile python:
./configure --prefix=/usr/local/python3.9 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
# when compilation finished run
./configure --enable-optimizations
5. Run make command:
make
If you get error like this:
be sure to install library libffi by using this command:
yum -y install libffi-devel
and then try again with make
command
6. Run make altinstall
make altinstall
7. add path "PATH=$PATH:/usr/local/python3.9/bin" to "/etc/profile.d/python3.9.sh"
# open file
nano /etc/profile.d/python3.9.sh
#and add path
PATH=$PATH:/usr/local/python3.9/bin
#save file and then run
export PATH
8. create file opt-python3.9.con and add /usr/local/python3.9/lib
nano /etc/ld.so.conf.d/opt-python3.9.conf
#add line
/usr/local/python3.6/lib
#save file
9. Update session
ldconfig
source /etc/profile.d/python3.9.sh