Use bottlepy and php in the same computer - apache2

I use ubuntu 12.04 with apache2 and mod_wsgi installed. I want to use bottlepy and php in my local computer.
I know such an issue is already asked by someone else as in Apache mod_wsgi and php in the same domain.
But someone suggest me to make a new question since my problem could be different.
I've change /etc/apache2/sites-available/default into this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /home/gofrendi/workspace/kokoropy
ServerName oraiso
WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
<Directory /home/gofrendi/workspace/kokoropy>
WSGIProcessGroup kokoropy
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
The first virtual host is for PHP, and the second one is for bottlepy.
I put my bottlepy application in /home/gofrendi/workspace/kokoropy. And I have kokoro.wsgi in the same directory which contains this script:
import os
sys.path = [os.path.dirname(__file__)] + sys.path
from kokoropy import kokoro_init
PWD = os.path.dirname(os.path.abspath(__file__))
APP_DIRECTORY = 'applications'
APPLICATION_PATH = os.path.join(PWD, APP_DIRECTORY)
application = kokoro_init(application_path = APPLICATION_PATH, run = False)
I've do enable the configuration by using
sudo a2ensite default
sudo service apache2 restart
My PHP scripts are still work as expected. But, whenever I don't know how to access my bottlepy script.
I've also try to remove the PHP part of /etc/apache2/sites-available/default, so that it only consists of
<VirtualHost *>
DocumentRoot /home/gofrendi/workspace/kokoropy
ServerName oraiso
WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
<Directory /home/gofrendi/workspace/kokoropy>
WSGIProcessGroup kokoropy
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
But I still can't get bottlepy work. It just simply show 404 not found.
Do anybody has the same experience? How to make it work?
Thanks.

The problem has been solved.
First I change httpd.conf setting (or in my case /etc/apache2/sites-available/default) nto this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
# THIS IS WHERE I START TO EDIT IT:
# It tells apache about wsgi existance
WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
<Directory /home/gofrendi/workspace/kokoropy>
WSGIProcessGroup kokoropy
WSGIApplicationGroup %{GLOBAL}
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
This configuration say that localhost/kokoropy should be handled by the wsgi.
My wsgi script is located at /home/gofrendi/workspace/kokoropy/kokoro.wsgi.
kokoro.wsgi content is as follow:
import os, sys
os.chdir(os.path.dirname(__file__))
sys.path = [os.path.dirname(__file__)] + sys.path
from bottle import default_app
#route('/')
def index():
return 'run with apache'
application = default_app()
If you found internal sever error, when accessing bottlepy, but find no error when accessing php, that is probably some mistake in you wsgi. Just open up the apache log (in my case it is here: /var/log/apache2/error.log)

Related

Ubuntu 12.10 virtualhost conflict

I have two sites on my server. One I access via my IP, x.x.x.x/site1. The other is a registered domain name, www.mysite.com.
Initially, I had only my /etc/apache/sites-available/default file available but when I tried loading either of the sites above I just got my /var/www/index.html output.
I included a new virtualhost for mysite.com with the following code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mysite
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/mysite>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Mysite.com only loads when default is disabled but then, x.x.x.x/site1 doesn't.
So, I enable the default virtualhost which has the following code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now, x.x.x.x/site1 works but mysite.com does not - instead it loads the /var/www/index.html page.
I'm confused about what the issue is.
In your vhost configuratin for mysite.com you need to add the ServerName directive:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.com
DocumentRoot /var/www/mysite
[…]

Install Web2py in virtual hosting

Install Web2py by a script setup-web2py-ubuntu.sh, previously adjusted the way for their virtual hosting.
But it works only on port 443, and the 80 th issue
It works!
How to fix?
#NameVirtualHost *:80
#NameVirtualHost *:443
# If the WSGIDaemonProcess directive is specified outside of all virtual
# host containers, any WSGI application can be delegated to be run within
# that daemon process group.
# If the WSGIDaemonProcess directive is specified
# within a virtual host container, only WSGI applications associated with
# virtual hosts with the same server name as that virtual host can be
# delegated to that set of daemon processes.
WSGIDaemonProcess demo2.host.ru user=web2 group=client1
<VirtualHost *:80>
WSGIProcessGroup demo2.host.ru
WSGIScriptAlias / /var/www/clients/client1/web2/web/web2py/wsgihandler.py
WSGIPassAuthorization On
<Directory /var/www/clients/client1/web2/web/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>
AliasMatch ^/([^/]+)/static/(.*) \
/var/www/clients/client1/web2/web/web2py/applications/$1/static/$2
<Directory /var/www/clients/client1/web2/web/web2py/applications/*/static/>
Options -Indexes
Order Allow,Deny
Allow from all
</Directory>
<Location /admin>
Deny from all
</Location>
<LocationMatch ^/([^/]+)/appadmin>
Deny from all
</LocationMatch>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /usr/local/ispconfig/interface/ssl/ispserver.crt
SSLCertificateKeyFile /usr/local/ispconfig/interface/ssl/ispserver.key
WSGIProcessGroup demo2.host.ru
WSGIScriptAlias / /var/www/clients/client1/web2/web/web2py/wsgihandler.py
WSGIPassAuthorization On
<Directory /var/www/clients/client1/web2/web/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>
AliasMatch ^/([^/]+)/static/(.*) \
/var/www/clients/client1/web2/web/web2py/applications/$1/static/$2
<Directory /var/www/clients/client1/web2/web/web2py/applications/*/static/>
Options -Indexes
ExpiresActive On
ExpiresDefault "access plus 1 hour"
Order Allow,Deny
Allow from all
</Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
Create files: parameters_443.py and parameters_80.py in folder web2py.
password="pbkdf2(1000,20,sha512)$851a015489"
Still not working...
Plz help! :'(

Why doesn't Apache redirect my IP address to the desired location on my server?

I made a simple page /home/david/mainSite/index.html. I then added a virtual host in Apache to redirect my IP address to this page.
<VirtualHost *:80>
ServerName 74.181.105.228
DocumentRoot /home/david/mainSite
</VirtualHost>
However, when I go to 74.181.105.228after restarting Apache, I get a page with this text instead of "index.html."
Welcome to mydomain.com!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
Why does Apache redirect to the default page instead of "/home/david/mainSite/index.html"?
Here is how my "/etc/apache2/sites-available/default" file looks like.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I discovered the answer! It was tricky.
In "apache2.conf", I originally had ServerName 74.181.105.228, which makes accessing 74.181.105.228 via a browser load the default page for my server.
Changing this value in "apache2.conf" to ServerName mydomain.com solves the problem since Apache no longer directs 74.181.105.228 to the default page of my server. In turn, I can direct 74.181.105.228 to load a page from a certain directory in my file system.
My virtual host block still remains
<VirtualHost *:80>
ServerName 74.181.105.228
DocumentRoot /home/david/mainSite
</VirtualHost

CakePHP and SSL

I just installed a SSL certificate on my website that uses CakePHP and now the site doesn't load anymore files from webroot (images, css files). Any ideas? I think SSL installation affected mod_rewrite, or something like this.
I just ran into this problem. Check your sites configuration for apache2. Make sure:
AllowOverride all
is set to allow .htaccess overrides under ssl. Here is my snippet of my config (on ubuntu).
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

subdomains w/o TLD

How do i set up a subdomain w/o a TLD? i have this set under my main config
<VirtualHost *:80>
ServerName bbs.67.777.777.777 #fake bc my server can easily be hacked ATM :(
DocumentRoot /var/www/phpBB
</VirtualHost>
when i goto bbs.serveripaddress i get a Address Not Found error. if i put that above my main config it still doesnt work however the entire site is pointing to /var/www/phpBB instead of /var/www (HUH!?!)
the main v host is
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I'm on a debian box using apache2 if that helps.
I don't think that server name (bbs.67.777.777.777 ) will get you anywhere - unless you have it added to your hosts file... Can you ping that address ok?
Why not just make your website the default... if you don't need a default?
You cannot have a subdomain with an IP address. The best way around this is to have a domain or a free subdomain (such as no-ip) to point at your IP address and create a ServerName for that. Remember to add the domain to your server DNS zones.
or make a domain in your host files and use that.

Resources