CentOS 5.5 is dependant on
Python 2.4. Everything will break if you change it, so we must install a newer version of
Python in a different place.
Surprisingly my
1&1 CentOS didn’t come with
gcc installed so I had to install it myself.
yum -y install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make
Important: Before you go any further please read
Upgrading Plesk from PSA_10.2.0 to PSA_10.3.0
I’m going to need the
MySQL development libraries so install them next:
yum -y install mysql-devel
The big surprise here was that it installed
PHP 5.3 as a dependency! which I was
not expecting, but everything still seems to be working!
Now that we have the platform set up, we’ll download all the sources we need and unpack them.
- Create a folder for us to work in:
mkdir /home/mrn/dev/python
cd /home/mrn/dev/python
- Go to the Python download page:
http://www.python.org/download/releases/
- Download and uncompress:
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tar.bz2
tar -xjvf Python-2.7.1.tar.bz2
- Go to the Python MySQL module page:
http://sourceforge.net/projects/mysql-python/
- Download and uncompress:
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
tar -xzvf MySQL-python-1.2.3.tar.gz
- Download the Easy Installer set up:
wget http://peak.telecommunity.com/dist/ez_setup.py
Build Python
- Go to Python folder:
cd Python-2.7.1
- Check there is nothing already living in
/usr/local/python27
because that is where we are going to install out copy of Python.
- Run the source configuration program:
./configure –prefix=/usr/local/python27
- Start the build:
make
- Install (as root):
make install
If you don’t have root privileges then you can change the −−prefix to a location where you can write.
Ok, to test it we’ll try to start the interactive prompt:
# /usr/local/python27/bin/python
Python 2.7.1 (r271:86832, Jun 2 2011, 16:02:46)
[GCC x.x.x xxxxxxxxx (xxxxx x.x.x-xx)] on xxxxx
Type “help", “copyright", “credits” or “license” for more information.
We must add python to our
PATH
so that the next part will pick up our new python and not the old one.
# export PATH=/usr/local/python27/bin:$PATH
As a prerequisite for the Python MySQL’s module we need to install
setuptools
. There is a really handy video on
ShowMeDo here on how to do it. Don’t forget to run this as root (if you installed it as root) because it will modify the Python installation directory. The
import
should return without an error.
# cd ..
# python ez_setup.py
To test it, try to import setuptools.
# /usr/local/python27/bin/python
Python 2.7.1 (r271:86832, Jun 2 2011, 16:02:46)
[GCC x.x.x xxxxxxxxx (xxxxx x.x.x-xx)] on xxxxx
Type “help", “copyright", “credits” or “license” for more information.
>>> import setuptools
>>>
Compile the MySQL module
Now that we have sorted out the Python installation go to the MySQL Python directory. The
site.py
default file doesn’t need changing so we can use it as is. There is the option to change the MySQL Python module name from
_mysql
to something else but there’s not much point because every example you’ll find on the Internet has it as the default; you’ll spend the rest of your life searching and replacing! Again you’ll have to run this as root if you did earlier.
# cd MySQL-python-1.2.3
# python setup.py build
# python setup.py install
To test it, try to import _mysql, it should return without an error.
# /usr/local/python27/bin/python
Python 2.7.1 (r271:86832, Jun 2 2011, 16:02:46)
[GCC x.x.x xxxxxxxxx (xxxxx x.x.x-xx)] on xxxxx
Type “help", “copyright", “credits” or “license” for more information.
>>> import setuptools
>>>
The first time I did this I got the following error message, but after I’d logged out and logged back in again the error message went away and I couldn’t reproduce it.
/usr/local/python27/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/python27/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /home/djn/dev/python/MySQL-python-1.2.3 is being added to sys.path
The unexpected upgrade of
PHP from version 5.1 to 5.3 threw up the following error message on all my
.php
pages:
SYSTEM WARNING: date_default_timezone_get() [function.date-default-timezone-get]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/London’ for ‘BST/1.0/DST’ instead
Fixed it by adding the following line to
/etc/php.ini
and restarting the web server.
date.timezone = ‘Europe/London’