{"id":9,"date":"2011-09-04T06:23:00","date_gmt":"2011-09-04T06:23:00","guid":{"rendered":"http:\/\/sdkit.com\/?p=9"},"modified":"2014-06-19T03:00:38","modified_gmt":"2014-06-19T03:00:38","slug":"how-to-install-python-2-7-with-mod_wsgi-on-centos-5-6-with-cpanel","status":"publish","type":"post","link":"https:\/\/sdkit.com\/?p=9","title":{"rendered":"How To Install Python 2.7 with mod_wsgi on CentOS 5.6 with cPanel"},"content":{"rendered":"<p>This is a step by step tutorial which will help you install Python 2.7 with mod_wsgi onto CentOS 5.6 and cPanel.<\/p>\n<p>Prerequisites:<\/p>\n<ul>\t<\/p>\n<li>CentOS 5.6 32 or 64 bit with root access<\/li>\n<p>\t<\/p>\n<li>cPanel<\/li>\n<p><\/ul>\n<p><\/p>\n<div>Note: we are not using <a href=\"http:\/\/docs.cpanel.net\/twiki\/bin\/view\/EasyApache3\/CustomMods\">cPanel custom modules<\/a> guide because it only works with built-in Python 2.4.<\/div>\n<p><\/p>\n<div>\n<p>Creating Python folder<\/p>\n<\/div>\n<p><\/p>\n<div><\/p>\n<pre>mkdir \/usr\/src\/python2.7<br\/>cd \/usr\/src\/python2.7<\/pre>\n<p><\/div>\n<p><\/p>\n<div>\n<p>If required by your project, you can install SQLite<\/p>\n<pre>wget http:\/\/www.sqlite.org\/sqlite-autoconf-3070701.tar.gz<br\/>tar zxvf sqlite-autoconf-3070701.tar.gz<br\/>cd sqlite-autoconf-3070701<br\/>.\/configure<br\/>make<br\/>make install<\/pre>\n<p>Installing Python 2.7 into alternate location since we don&#8217;t want to break Centos 5.6 (yum) that uses Python 2.4<\/p>\n<pre>cd \/usr\/src\/python2.7\/<br\/>wget http:\/\/www.python.org\/ftp\/python\/2.7.2\/Python-2.7.2.tgz<br\/>tar zxvf Python-2.7.2.tgz<br\/>cd Python-2.7.2<br\/>.\/configure --prefix=\/opt\/python2.7 --with-threads --enable-shared<br\/>make<br\/>make install<\/pre>\n<p>Creating symbolic link to the alternate Python version<\/p>\n<pre>ln -s \/opt\/python2.7\/bin\/python \/usr\/bin\/python2.7<br\/>echo '\/opt\/python2.7\/lib'&gt;&gt; \/etc\/ld.so.conf.d\/opt-python2.7.conf<br\/>ldconfig<\/pre>\n<p>Let&#8217;s test if new Python version works<\/p>\n<pre>\/usr\/bin\/python2.7<\/pre>\n<p>If successful you will see something like this:<\/p>\n<pre>Python 2.7.2 (default, Sep\u00a0 3 2011, 18:28:42)[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2<\/pre>\n<p>press control+D to exit<\/p>\n<p>Now we need to install Python setup-tools<\/p>\n<pre>cd \/usr\/src\/python2.7\/<br\/>wget http:\/\/pypi.python.org\/packages\/2.7\/s\/setuptools\/setuptools-0.6c11-py2.7.egg<br\/>sh setuptools-0.6c11-py2.7.egg --prefix=\/opt\/python2.7<\/pre>\n<p>Installing virtualenv to our Python 2.7<\/p>\n<pre>cd \/opt\/python2.7\/bin\/<br\/>.\/easy_install virtualenv<\/pre>\n<p>Installing mod_wsgi (this module will work only with python 2.7)<\/p>\n<pre>cd \/opt\/python2.7\/lib\/python2.7\/config\/<br\/>ln -s ..\/..\/libpython2.7.so<br\/>cd \/usr\/src\/python2.7\/<br\/>wget http:\/\/modwsgi.googlecode.com\/files\/mod_wsgi-3.3.tar.gz<br\/>tar zxvf mod_wsgi-3.3.tar.gz<br\/>cd mod_wsgi-3.3<br\/>.\/configure --with-python=\/opt\/python2.7\/bin\/python<br\/>make<br\/>make install<\/pre>\n<p>We need to avoid cPanel&#8217;s easy_apache clearing up \/usr\/local\/apache\/modules folder<\/p>\n<pre>mkdir \/usr\/local\/apache\/extramodules<br\/>mv \/usr\/local\/apache\/modules\/mod_wsgi.so \/usr\/local\/apache\/extramodules\/<\/pre>\n<p>Include mod_wsgi into Apache configuration<\/p>\n<pre>nano \/usr\/local\/apache\/conf\/includes\/pre_virtualhost_global.conf<\/pre>\n<p>paste:<\/p>\n<pre>LoadModule wsgi_module \/usr\/local\/apache\/extramodules\/mod_wsgi.so<br\/>AddHandler wsgi-script .wsgi<\/pre>\n<p>Before we restart Apache, lets test if we have the correct configuration<\/p>\n<pre>service httpd configtest<\/pre>\n<p>You should get this answer:<\/p>\n<pre>Syntax OK<\/pre>\n<p>Now restart Apache<\/p>\n<pre>\/scripts\/restartsrv httpd<\/pre>\n<p><\/div>\n<p>Python 2.7 with mod_wsgi is now installed on your cPanel server.<\/p>\n<p>You can create a test.wsgi file to test Python scripts<\/p>\n<pre>def application(environ, start_response):<br\/>    \"\"\"Simplest possible application object\"\"\"<br\/>    output = \"Hello World\"<br\/>    status = '200 OK'<br\/>    response_headers = [('Content-type', 'text\/plain'),<br\/>                        ('Content-Length', str(len(output)))]<br\/>    start_response(status, response_headers)<br\/>    return [output]<\/pre>\n<p>Please post your questions and comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a step by step tutorial which will help you install Python 2.7 with mod_wsgi onto CentOS 5.6 and cPanel. Prerequisites: CentOS 5.6 32 or 64 bit with root access cPanel Note: we are not using cPanel custom modules guide because it only works with built-in Python 2.4. Creating Python folder mkdir \/usr\/src\/python2.7cd \/usr\/src\/python2.7 &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How To Install Python 2.7 with mod_wsgi on CentOS 5.6 with cPanel\" class=\"read-more button\" href=\"https:\/\/sdkit.com\/?p=9#more-9\" aria-label=\"Read more about How To Install Python 2.7 with mod_wsgi on CentOS 5.6 with cPanel\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18,27,14,19,35,3,34,2],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-centos","category-cpanel","category-how-to","category-linux","category-mod_wsgi","category-programming","category-python","category-tutorial","no-featured-image-padding"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/sdkit.com\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdkit.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdkit.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdkit.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sdkit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":0,"href":"https:\/\/sdkit.com\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdkit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdkit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdkit.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}