LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-22-2008, 08:07 AM   #1
Sambojambo
LQ Newbie
 
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Rep: Reputation: 0
Python, apache, php , mysql weirdness


Sorry about the rather obtuse title to this post but I can't really even describe this bug accurately.

I need to call a python script from php. It requires MySQLdb.

Code:
# pytest.py

print('1')
import MySQLdb
print('2')
PHP Code:
<?php
# apachetest.php

$cmd "/usr/local/bin/python2.5 /home/sam/www/pytest.py";

echo(
"The cmd :: $cmd \n");
echo(
"Output :: \n");

system("$cmd");
On my dev box (Ubuntu) it works fine. The strangeness happens on the production server (Redhat). I can run apachetest.php from the command line fine - '1' & '2' are printed. But if I call (http://localhost/apachetest.php ) from a webrowser it fails?

So when the apachetest.php gets called by apache it won't import MySQLdb in the python. '1' gets printed but *not* '2'?

I would have thought that the cmd being executed by system( ) would be completely independent of apache?

Anyway I've hit a brick wall - If anybody can shed any light on this for me, I would be very grateful.

Thanks in advance
 
Old 05-22-2008, 08:25 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Do you have all the Python stuff loaded, like the modules to let Python talk to MySQL? And is MySQL up and running?

Can you run the python script from the command line, outside of PHP?
 
Old 05-22-2008, 08:42 AM   #3
Sambojambo
LQ Newbie
 
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Original Poster
Rep: Reputation: 0
This is where it gets strange. I do have python-mysqldb installed, so when I run the apachetest.php from the command line as below there are no problems:

Code:
[dengmpo@fm-web-1 public_html]$ php apachetest.php
The cmd :: /usr/local/bin/python2.5 /home/dengmpo/public_html/pytest.py
Output
1
2
[dengmpo@fm-web-1 public_html]$
It's when apachetest.php is called from a web browser (http://productionserver.com/apachetest.php) it only reaches the first print line:

Code:
The cmd :: /usr/local/bin/python2.5 /home/dengmpo/public_html/pytest.py Output 1
Why would the php system( ) function effect the behaviour of python when executed by apache?

Last edited by Sambojambo; 05-22-2008 at 08:45 AM.
 
Old 05-22-2008, 08:55 AM   #4
Sambojambo
LQ Newbie
 
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Original Poster
Rep: Reputation: 0
Just a bit of extra info - php is running with SAFE_MODE off and both files are -rwxrwxrwx ...
 
Old 05-22-2008, 09:01 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Sounds to me like a permissions problem. On your production server, the user apache doesn't have rights to read mySQLdb. Anything run with the system() command runs as user apache so your python script fails.

Either that or there is a path issue and mySQLdb is not being found.
 
Old 05-22-2008, 09:31 AM   #6
Sambojambo
LQ Newbie
 
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Original Poster
Rep: Reputation: 0
Whoa - Dan the man who I work with cracked it. But when you know what to google for it's easy to find the answer - the problem was the same as this post which explains it more clearly than I'd be able to:
http://forum.webfaction.com/viewtopic.php?pid=2152

Solution:
Code:
import os
os.environ['PYTHON_EGG_CACHE'] = '/usr/local/lib/python2.5/eggs'
That was two days of head banging... It wasn't able to write the cache files.

Thanks for you help guys - I can now get three months of development up and running on the production server before the weekend.
 
Old 05-22-2008, 09:33 AM   #7
smal
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
I think - problem may be with SELinux, which running on default Red Hat Linux.
Try to disable SELinux and try again your script.
 
Old 05-22-2008, 12:20 PM   #8
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I guess I was right; permissions problem. I thought it was a read permission, when it was a write permission, but c'est la vie.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 02:07 AM
help apache+php+mysql linuxtm2005 Linux - General 3 01-01-2004 12:39 PM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 08:59 PM
php-nuke with apache php mysql c0c0deuz Linux - Software 0 03-30-2003 06:23 AM
RH/Apache/MySQL/PHP c0c0deuz Linux - Software 8 12-24-2001 07:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration