views:

378

answers:

5

Hi all, I have a simple PHP script that outputs a dir listing in XML format. I use it to let a flash slideshow know what files are available to show.

I've just added the flash to a website that's powered by Django and the PHP file is now served up as it is, not parsed.

It's in the directory with the images under my media directory.

The server I use runs plesk so I do my config for each domain in a vhost.conf file (which gets included into the main appache conf I think)

It looks like this:

WSGIScriptAlias / /var/www/vhosts/<domain>/conf/django.wsgi
Alias /media/ /var/www/vhosts/<domain>/httpdocs/media/

I thought this meant that requests for anything under / are passed django to handle.
Except when they are for /media/... then they are served by apache as normal from the specified dir.

That works for the images, but does not parse the PHP file.

What should I do?

+2  A: 

Maybe read this thread, and port your PHP script to Python:

http://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion

AJ
I've considered writing it into my django project, but it does not actually have an app of it's own. It's just running my CMS app imported from a shared source.I don't know how so serve up a python script to a URL other than through Django. I expected what I've done would work, if I could get it going it would be much simpler and would allow me to use the same script on Django and non-django sites.
Jake
+1  A: 

If you have not configured Apache so that it knows that .php files under the '/media' directory should be processed by PHP somehow, they will not be. So, the mod_wsgi configuration is fine, the problem is likely your PHP configuration.

How are you configuring PHP? Are you using mod_php, or PHP via fastcgi? How is Apache configured so that it knows to treat .php files as PHP and for what directories has that configuration been applied to?

Graham Dumpleton
If I remove the vhost.conf file it works, but Django does not. So I think PHP is setup fine.
Jake
PHP will work fine, but you have not configured Apache correctly (yet) in this case.
Ali A
Apache must be setup to treat .php files as PHP because it does in the absence of Django. The problem seems to be that apache is not handling the file as usual, it's running it through mod_wsgi. See Ignacio's answer.
Jake
Post the Directory block related to the media directory as followup in your question. You haven't gone and made the mistake that people do when they move from mod_python and put 'SetHandler None' in it have you. This will stop PHP from working. When using mod_wsgi, 'SetHandler None' should never be used.
Graham Dumpleton
Thanks for the suggestion. A likely mistake, but not one I've made.
Jake
+1  A: 

The WSGIScriptAlias directive there swallows up URLs meant for Alias. Swap the order.

Ignacio Vazquez-Abrams
Nope, still serving up the file without parsing it.Other files served under /media work with them in the original order, so I don't think it swallows.
Jake
If at some point the Django project had been set up for serving static files then it would still be in the way with the original order. Do other PHP files on the server get handled properly?
Ignacio Vazquez-Abrams
Good point. I have django setup files under /media when in debug mode for local dev. I've tested and found is in debug mode for some reason, I'll check my config. I also realised that I neglected to restart the server after reversing those 2 lines, restarting that causes a 500 error. I think I'm on the right track once I sort that out, so thanks. Will keep you posted when I get time to test it.
Jake
OK, so even without the WSGIScriptAlias, only a normal Alias it still serves the file without parsing it. It is caused by the alias, with my file at ...httpdocs/media/test.php and an Alias /media2/ ...httpdocs/media/ it is served interpreted from domain.com/media/test.php and as raw code from domain.com/media2/test.php. Anyone know how to change this behavior?
Jake
At this point try adding the following:`AddHandler php5-script .php``AddType text/html .php`
Ignacio Vazquez-Abrams
That has stopped my browser thinking the file is a download. It's now displaying the php code rather than giving me the file. But it's still not interpreting it. :(
Jake
Well then I am truly and rightly stumped...
Ignacio Vazquez-Abrams
Thanks for your help, your original answer helped anyway. I'll setup some proper tests to see just what works and doesn't then ask another question.
Jake
+1  A: 

So it turns out the problem was two things, making it hard to find.

Thanks Ignacio Vazquez-Abrams, I had my lines the wrong way around.

Once that was solved, PHP would not serve my file because it was in a dir that was symlinked from outside the allowed path(s). I resolved this by turning off open_basedir restrictions for this vhost. My new vhost.conf is below.

<Directory /var/www/vhosts/<domain>/httpdocs>
    php_admin_flag engine on
    php_admin_value open_basedir none
</Directory>

Alias /media/ /var/www/vhosts/<domain>/httpdocs/media/

WSGIScriptAlias / /var/www/vhosts/<domain>/conf/django.wsgi
Jake
A: 

It's a bit more secure to specify your open_basedir paths, rather than disabling open_basedir entirely.

Instead of:

php_admin_value open_basedir none

Use:

php_admin_value open_basedir "/var/www/vhosts/domain.com/httpdocs/:/tmp/:/path/to/django/app/"

You can add as many paths as you want - just separate with colons.

Shar