You are not logged in.

#1 2008-08-18 15:54:16

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Apache2, mod_python, and phpBB == Trouble

Hi,

I have an Apache2 server setup and I also have phpBB in my document root. So, when I do:

http://my.domain/forum

My phpBB forum shows up. Lately, I've been wanting to use mod_python to script a web page. So, since I want this web page to be at the "root", did the following:

<Directory /srv/http>
     SetHandler mod_python
     PythonHandler mod_python.publisher
     PythonDebug On
</Directory>

/srv/http here is the absolute directory path to my document root. This Directory entry was already in my httpd.conf file, I simply added the internals you see above to it since that's what the mod_python tutorial suggested. While I can successfully visit "http://mydomain/" and see that it is executing my python scripts, I cannot visit my forum anymore. It says:

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

I'm not a big expert on apache or web development yet, I'm doing this to learn it. I looked up documentation on <Directory /> in apache, but it wasn't very helpful. I always thought those paths were relative to the document root directory, but I guess not. Anyone know what is going on? Help is appreciated.

Offline

#2 2008-08-18 16:33:00

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: Apache2, mod_python, and phpBB == Trouble

I think your problem is due to the directive you entered to make mod_python run under the directory where you have your php files.
If you state "SetHandler mod_python" then Apache will resort to mod_python to process requests in that directory and your PHP will brake.

Hope this helps.

R.

Offline

#3 2008-08-18 16:38:35

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

How can I explicitly specify that /srv/http/forum is to be handled by PHP? Perhaps this will override mod_python at the root. Or, perhaps I can instruct the SetHandler for mod_python to only apply that to files with a specific extension, like .py. How could I do this?

::EDIT::
Below is what I've done to try to restrict the mod_python to only files with the extension of .py, however it isn't working for some reason:

<Directory "/srv/http">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

    # mod_python configuration
    <FilesMatch "\.py$">
        SetHandler mod_python
        PythonHandler mod_python.publisher
        PythonDebug On
    </FilesMatch>
</Directory>

Last edited by void.pointer (2008-08-18 18:09:21)

Offline

#4 2008-08-18 23:00:37

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: Apache2, mod_python, and phpBB == Trouble

Try something like AddHandler mod_python .py so it goes on a file extension basis.

Offline

#5 2008-08-19 01:56:52

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: Apache2, mod_python, and phpBB == Trouble

I think that if I understand what you are doing you should have a directory with your php files (say that is your main web directory) and another directory with your mod_python files (say you call it 'modpy').
In the modpy directory you add an .htaccess file with the following directives:

# Set mod_python options
DirectoryIndex index.py
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug on

AddType text/html;qs=1.0 .py
AddType text/html;qs=0.9 .html
AddType text/plain;qs=0.8 .txt

<Files ~ "\.(gif|html|jpg|png|swf)$">
SetHandler default-handler
</Files>

Now when you go to your main directory php will handle the files but if you request files form your modpy the mod_python handler will take over.

That's what I have done myself and works just fine. I have been working with mod_python for awhile now and I love it !! I think it is far better that PHP once you get to understand it well.

Hope this helps.

R.

edit: BTW, you could also use the files directive (see my code above...) to specify PHP to be handled by its default handler, but then other things may become confusing if you are new to mod_python.

Last edited by ralvez (2008-08-19 02:05:46)

Offline

#6 2008-08-19 12:44:14

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

ralvez wrote:

I think that if I understand what you are doing you should have a directory with your php files (say that is your main web directory) and another directory with your mod_python files (say you call it 'modpy').
In the modpy directory you add an .htaccess file with the following directives:

# Set mod_python options
DirectoryIndex index.py
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug on

AddType text/html;qs=1.0 .py
AddType text/html;qs=0.9 .html
AddType text/plain;qs=0.8 .txt

<Files ~ "\.(gif|html|jpg|png|swf)$">
SetHandler default-handler
</Files>

Now when you go to your main directory php will handle the files but if you request files form your modpy the mod_python handler will take over.

That's what I have done myself and works just fine. I have been working with mod_python for awhile now and I love it !! I think it is far better that PHP once you get to understand it well.

Hope this helps.

R.

edit: BTW, you could also use the files directive (see my code above...) to specify PHP to be handled by its default handler, but then other things may become confusing if you are new to mod_python.

Thanks a lot for your response. I want to try this, but I have one final question. Right now the URL "http://my.domain/" maps to the physical directory "/srv/http" which is my document root. If I place my mod_python website in "/srv/http/modpy", how can I make the URL look different? For example, I want to access my mod_python website via "http://my.domain/" and not "http://my.domain/modpy". Help is appreciated.

Offline

#7 2008-08-19 19:52:46

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

In light of my previous question, I decided to restructure the document root back the way I had it and use .htaccess files. So, the original problem I posted about still exists. The problem should be easy to solve, I would think. The .htaccess file in my /srv/http/forum directory should basically force the ignoring of mod_python and use whatever was there by default to make phpBB (my forum) work. I'm not sure how I should configure that .htaccess file, though. I setup my document root (/srv/http) to use mod_python, but I do not want /srv/http/forum to inherit these traits.

The .htaccess file in /srv/http looks as follows:

Options All -Indexes

# Set mod_python options
DirectoryIndex index.py
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug on

AddType text/html;qs=1.0 .py
AddType text/html;qs=0.9 .html
AddType text/plain;qs=0.8 .txt

<Files ~ "\.(gif|html|jpg|png|swf)$">
    SetHandler default-handler
</Files>

The above code is basically what ralvez suggested. What would the .htaccess file need to look like in /srv/http/forum to make my phpBB forum work again? Thanks.

Offline

#8 2008-08-19 21:46:59

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: Apache2, mod_python, and phpBB == Trouble

Well ... if you are using that .htaccess I gave you just add php to the <files> section, like:

<Files ~ "\.(gif|html|jpg|png|swf|php)$">
    SetHandler default-handler
</Files>

Offline

#9 2008-08-19 21:53:03

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

ralvez wrote:

Well ... if you are using that .htaccess I gave you just add php to the <files> section, like:

<Files ~ "\.(gif|html|jpg|png|swf|php)$">
    SetHandler default-handler
</Files>

Did that, but now the PHP script is showing up as text when I visit the URL instead of the script being executed.

Offline

#10 2008-08-19 22:12:22

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: Apache2, mod_python, and phpBB == Trouble

OK. I just did a wild test and it works for me.
In my web root where I have all my php files I added a folder (python_test) and placed in there the .htaccess file I sent before and some other .py files) then I call any PHP file and it shows up just fine.
Then I jump to http://mywebserver/python_test/ and I get the python.index file requesting me to authenticate against my DB and if my password matches it goes just fine.

I'm not sure how you are setting up you server by the approach I suggest here should be working; unless, of course, there is some other configuration issue in your server.

Try to get things working with PHP first, then add the directory for Python and go from there.


R.

Offline

#11 2008-08-19 22:21:18

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

I apologize for the confusion. Allow me to explain myself a bit better.

First I will explain the scenario that works perfectly for me. First, note that my document root is at /srv/http.

SCENARIO 1
Create the following two directories:
/srv/http/forum
/srv/http/modpy

The former directory contains PHP scripts, and is basically the phpBB forum scripts. With no additional configuration or .htaccess files, it works fine right out of the box.
The latter directory contains the .htaccess that you suggested before as well as an index.py.

With the above setup, when I visit http://myserver/forum, I get my phpBB forum and it shows up correctly (Everything is normal). When I visit http://myserver/modpy, I see my web page scripted through mod_python (Everything is still normal).


SCENARIO 2
You have the following two directories:
/srv/http/forum
/srv/http

The former directory is still the same as in Scenario 1. It's the phpBB forum scripts (php).
The latter is my document root and contains exactly what /srv/http/modpy contained in scenario 1. I moved them up one directory because I wanted to change the URL used to visit my web page generated using mod_python.

In this case, visiting http://myserver/forum does NOT work, I'm guessing because the .htaccess in the document root (/srv/http) is using mod_python which is recursive and is preventing the php scripts from being executed. Visiting http://myserver *does* still display my web page generated with mod_python. I wanted to visit my web page using http://myserver and not http://myserver/modpy (like before), so this is why I moved the mod python scripts out of the modpy directory.

I hope you can see the real problem now. I believe the problem is that now I need to setup the .htaccess file in /srv/http/forum so that php is used to execute scripts in that directory and not mod_python. Let me know if I haven't explained myself very well. Thanks again for your help!

Offline

#12 2008-08-19 23:55:56

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: Apache2, mod_python, and phpBB == Trouble

Yes, I get it now.
I usually keep things separate for practical reasons. I'm sure it is a handler's conflict because now the root has mod_python as default.
I'll play a bit with my system to see if I can come up with a reasonable sound configuration for your particular case if I have some time.
Meanwhile, you should check your /etc/httpd/conf/httpd.conf file for conflicting directives between your httpd.conf and your .htaccess file in the root directory.

R.

Offline

#13 2008-08-22 21:01:22

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

ralvez wrote:

Yes, I get it now.
I usually keep things separate for practical reasons. I'm sure it is a handler's conflict because now the root has mod_python as default.
I'll play a bit with my system to see if I can come up with a reasonable sound configuration for your particular case if I have some time.
Meanwhile, you should check your /etc/httpd/conf/httpd.conf file for conflicting directives between your httpd.conf and your .htaccess file in the root directory.

R.

Thanks for all of your help. Just wondering if you've figured out anything yet. I've tried posting about this in several locations, however I've not received any solutions. I've done a lot of experimentation on my part, but I've still been unsuccessful.

Offline

#14 2008-08-22 22:42:32

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Re: Apache2, mod_python, and phpBB == Trouble

In all honesty I've been very busy lately. I develop software for educational institutions and here in Canada we are just about 10 days away from starting a new year, so I'm very busy.
If I have a chance to experiment a bit I'll post.

R.

Offline

#15 2008-08-22 22:46:11

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: Apache2, mod_python, and phpBB == Trouble

ralvez wrote:

In all honesty I've been very busy lately. I develop software for educational institutions and here in Canada we are just about 10 days away from starting a new year, so I'm very busy.
If I have a chance to experiment a bit I'll post.

R.

I apologize if it seems like I'm rushing. I wanted to just check up on things. I do appreciate you offering your free time to help me out. In the meantime, I will patiently wait to see if anyone else on the forum can offer their valuable help.

Thanks to everyone.

Offline

Board footer

Powered by FluxBB