Issues

Install Web2py on Mac OS X Mountain Lion Server

Paulo Silva : January 23, 2013 21:36 : Issues

Today a friend asked me for help, he needed to install Web2py on Mountain Lion Server, so I have performed some tests, and this is the result.

So, to install Web2py on Mountain Lion server you need to do the following steps:

1º Modify the original Mountain Lion server Apache configuration file:

File Name: httpd_server_app.conf
Location: /Library/Server/Web/Config/apache2 (Default Mountain Lion Server Installation)


#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#

#AddHandler cgi-script .cgi .pl .rb .py # Comment this line.
AddHandler cgi-script .cgi .pl .rb # Add this one.

Or rename the file /web2py/wsgihandler.py to /web2py/wsgihandler.wsgi (I haven’t performed this test).

2º Create the Apache2 config files for port 80 and port 443 (SSL):

Now you need to create two apache configuration files, one for the regular site and a second for the web2py administration site.

For the regular website, create a configuration file like this one:
File Name: httpd_0001_web2py_80.conf

 
WSGIScriptAlias / /PATH_TO_THE_WEB2PY_FOLDER/web2py/wsgihandler.py

<Directory /PATH_TO_THE_WEB2PY_FOLDER/WebApps/web2py>
	AllowOverride None
	Order Allow,Deny
	Deny from all
	<Files wsgihandler.py>
		Allow from all
	</Files>
</Directory>

AliasMatch ^/([^/]+)/static/(.*) \
          /PATH_TO_THE_WEB2PY_FOLDER/web2py/applications/$1/static/$2
<Directory /PATH_TO_THE_WEB2PY_FOLDER/web2py/applications/*/static/>
	Order Allow,Deny
	Allow from all
</Directory>

# Deny access to the global administration are.
<Location /admin>
	Deny from all
</Location>

# Deny access to the applications administration are.
<LocationMatch ^/([^/]+)/appadmin>
	Deny from all
</LocationMatch>
 

Now. for the administration website, create a configuration file like this one:
File Name: httpd_0001_web2py_443.conf

 
WSGIScriptAlias / /PATH_TO_THE_WEB2PY_FOLDER/web2py/wsgihandler.py

<Directory /PATH_TO_THE_WEB2PY_FOLDER/web2py>
	AllowOverride None
	Order Allow,Deny
	Deny from all
	<Files wsgihandler.py>
		Allow from all
	</Files>
</Directory>

AliasMatch ^/([^/]+)/static/(.*) \
       /PATH_TO_THE_WEB2PY_FOLDER/web2py/applications/$1/static/$2
<Directory /PATH_TO_THE_WEB2PY_FOLDER/web2py/applications/*/static/>
	Order Allow,Deny
	Allow from all
</Directory>
 

For more detail on Web2py and Apache2, see this chapter: http://web2py.com/book/default/chapter/13

Ok, we are almost done, but now you are asking:

Where is the VirtualHost declaration on the configurations files ?

Well, we don’t need it, because we are configuration WebApps for Mountain Lion Server, as you will see it in the next step.

3º Create the WebApps configurations file for Mountain Lion Server:

For the regular website “Mountain Lion Server Application”, create a configuration file like this one:
File Name: com.example.web2py_80.plist

 
<?xml version="1.0" encoding="UTF-7"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>com.example.web2py_80</string>
	<key>displayName</key>
	<string>Web2py port 80 app at / </string>
	<key>launchKeys</key>
	<array/>
	<key>proxies</key>
	<dict/>
	<key>installationIndicatorFilePath</key>
	<string>/PATH_TO_THE_WEB2PY_FOLDER/web2py/wsgihandler.py</string>
	<key>includeFiles</key>
	<array>
		<string>/PATH_TO_THE_CONFIG_FOLDER/httpd_0001_web2py_80.conf</string>
	</array>
	<key>requiredModuleNames</key>
	<array>
		<string>wsgi_module</string>
	</array>
</dict>
</plist>
 

Now, for the administration website “Mountain Lion Server Application”, create a configuration file like this one:
File Name: com.example.web2py_443.plist

 
<?xml version="1.0" encoding="UTF-7"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>com.example.web2py_443</string>
	<key>displayName</key>
	<string>Web2py port 443 app at / </string>
	<key>launchKeys</key>
	<array/>
	<key>proxies</key>
	<dict/>
	<key>installationIndicatorFilePath</key>
	<string>/PATH_TO_THE_WEB2PY_FOLDER/web2py/wsgihandler.py</string>
	<key>includeFiles</key>
	<array>
		<string>/PATH_TO_THE_CONFIG_FOLDER/httpd_0001_web2py_443.conf</string>
	</array>
	<key>requiredModuleNames</key>
	<array>
		<string>wsgi_module</string>
	</array>
</dict>
</plist>
 

4º Configurate Mountain Lion WebServer:

Ok, now that we have all necessary configuration files, we need to configure Mountain Lion Web Server, but before we do it, we need to put our *.plist files on the correct location for register the WebApps on Mountain Lion Server.

So now, we need to copy all *.plist files to the following path: /Library/Server/Web/Config/apache2/webapps (Default Mountain Lion Server Installation).

WebServer Global Configurations

Ok, now that we have copied the files, we need to open the “Server Application” and select the WebSites option on left panel, as you can see on the following image.

Now, enable python web applications option, so you can select the desire application from the application list, as you will see on this post.

WebServer Global Configurations Edit Site

Now select the site that you want to enable the Web2py Application (port 80 in this case). As you see on the image, I’m using the default one, to simplify this post, but you can use any of your websites.

So, after you have selected the website, press the “pen button” at the bottom of the window to show the next window where you can edit your website.

WebServer WebSite Configurations

Ok, now press the button “Edit Advanced Settings” so you can see the next screen.

WebServer WebSite WebApp Configurations

Now, on this screen select the python application that you want to enable, as you can see on the image.

Ok, now close all windows and open your favorite browser for test the Web2py site.

Now you have to repeat the step 4, so you can configure the https (port: 443) for the Web2py administration.

I hope this helps.

Leave a response »
« Page 1 »

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.