3

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!

ringmaster
  • 2,879
  • 3
  • 28
  • 31
  • Google didn't give you this article? http://www.dreamincode.net/forums/topic/179933-can-mod-python-and-php-run-on-the-same-server/ – Matt Aug 03 '12 at 13:09
  • The referenced article doesn't discuss mod_vhost_alias at all. I know Python and PHP can run on the same server, what I don't know is whether I must reconfigure Apache to have separate vhost configs for every domain already on it just to enable Python. I'd prefer not to, and actual advice on getting this done how I prefer is the most helpful. – ringmaster Aug 03 '12 at 14:42

2 Answers2

1

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

WebChemist
  • 4,393
  • 6
  • 28
  • 37
  • I recently found this, hope it's helpful to you or anyone reading this: http://www.electricmonk.nl/docs/apache_fastcgi_python/apache_fastcgi_python.html – WebChemist Oct 09 '12 at 07:12
0

Even I faced the same situation, and initially I was wondering in google but later realised and fixed it, I'm using EC2 service in aws with ubuntu and I created alias to php and python individually and now I can access both.

  • Hello can you show something how to make it possible, How can i run python on another server like node js on another port with PM2. – Prashant Barve May 11 '17 at 07:14