简体   繁体   中英

Can I run PHP and Python on the same Apache server using mod_vhost_alias and mod_wsgi?

I currently run my own server "in the cloud" with PHP using mod_fastcgi and mod_vhost_alias. My mod_vhost_alias config uses a VirtualDocumentRoot of /var/www/%0/htdocs so that I can serve any domain that routes to my server's IP address out of a directory with that name.

I'd like to begin writing and serving some Python projects from my server, but I'm unsure how to configure things so that each site has access to the appropriate script processor.

For example, for my blog, dead-parrot.com, I'm running a PHP blog platform (Habari, not WordPress). But I'd like to run an app I've written in Flask on not-dead-yet.com.

I would like to enable Python execution with as little disruption to my mod_vhost_alias configuration as possible, so that I can continue to host new domains on this server simply by adding an appropriate directory. I'm willing to alter the directory structure, if necessary, but would prefer not to add additional, specific vhost config files for every new Python-running domain, since apart from being less convenient than my current setup with just PHP, it seems kind of hacky to have to name these earlier alphabetically to get Apache to pick them up before the single mod_vhost_alias vhost config.

Do you know of a way that I can set this up to run Python and PHP side-by-side as conveniently as I do just PHP? Thanks!

Here is some info that might help getting python working (Despite the title it's not Ubuntu specific):

http://infobees.wordpress.com/2011/05/15/python-cgi/

I think you might be confused here, as you seem to have the impression that a particular domain can only be either PHP or Python and you have to specify which of the 2 to use in every case? Apache is just going to call the appropriate processor depending on whether the requested resource as a .php or .py extension, meaning that all domains could use PHP and Python if you specify AddHandler settings (and possibly needed python <directory> allow permissions) in a global place like httpd.conf.

Since the AddHandler directive can be used in .htaccess (assuming proper AllowOverride permissions in httpd or vhosts) you can just include that in htaccess files on only the domains you want to run python on

即使我遇到了同样的情况,最初我想在谷歌但后来意识到并修复它,我在使用ubuntu的aws中使用EC2服务并且我单独创建了php和python的别名,现在我可以访问它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM