Webfaction Software Documentation: Release
Webfaction Software Documentation: Release
Webfaction Software Documentation: Release
Release
1 General Topics 3
1.1 Accessing Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Monitoring Memory Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Setting File Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 Scheduling Tasks with Cron . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 Bazaar 11
2.1 Installing Bazaar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Publishing Bazaar Repositories with Loggerhead . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Custom Applications 15
3.1 Creating a Custom Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Automatically Restarting a Custom Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 Django 17
4.1 Getting Started Screencast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Getting Started with Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 Restarting a Django Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.4 Upgrading your Django Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.5 Using the Latest Django Trunk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.6 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5 Drupal 25
5.1 Sending Email from Drupal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6 Git 27
6.1 Installing Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2 Pushing to Git Repositories over SSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.3 Publishing Git Repositories to the Web with Gitweb . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7 Joomla 31
7.1 Sending Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
8 Memcached 33
8.1 Setting Up Memcached . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
8.2 Shutting Down Memcached . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
9 Mercurial 35
9.1 Installing Mercurial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
i
9.2 Publishing Mercurial Repositories to the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
10 MongoDB 41
10.1 Installing MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
11 Perl 43
11.1 Installing CPAN Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
12 PHP 47
12.1 Sending Mail from a PHP Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
13 Plone 49
13.1 Configuring Plone to Send Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
13.2 Creating an Emergency Admin User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
13.3 Installing a Python Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
14 Python 51
14.1 Installing Python Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
14.2 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
15 Ruby on Rails 57
15.1 Installing Ruby on Rails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
15.2 Installing Gems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
15.3 Deploying a Ruby on Rails Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
15.4 Using a Database with a Ruby on Rails Application . . . . . . . . . . . . . . . . . . . . . . . . . . 58
16 Redmine 61
16.1 Installing Redmine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
16.2 Configuring Redmine to Send Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
18 Subversion 71
18.1 Send Email Notifications with a Post-Commit Hook . . . . . . . . . . . . . . . . . . . . . . . . . . 71
18.2 Reusing Usernames and Passwords Between Subversion and Trac . . . . . . . . . . . . . . . . . . . 72
19 WordPress 73
19.1 Getting Started Screencast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
19.2 Sending Email from WordPress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
ii
WebFaction Software Documentation, Release
Contents:
CONTENTS 1
WebFaction Software Documentation, Release
2 CONTENTS
CHAPTER
ONE
GENERAL TOPICS
~/logs/frontend stores logs associated with website entries and shared Apache. There are four types of logs
which appear in ~/logs/frontend:
• Website access logs – Logs of the filename form beginning ‘access_website_name.log’ record attempts
to access a website. Such logs record:
– originating IP address,
– date and time,
– HTTP method used,
– the specific URL accessed,
– and the user-agent which made the request.
• Website error logs – Logs of the filename form beginning ‘error_website_name.log’ record error
events associated with websites. Such logs record a date and time and an error message.
• Shared Apache access logs – Logs of the filename form beginning ‘access_website_name_php.log’
record access attempts for all shared Apache-based applications reached through website_name. This in-
cludes all shared Apache-based applications, such as Trac, Subversion, and Static/CGI/PHP applications. Such
logs record:
– originating IP address,
– date and time,
– HTTP method used,
– the specific URL accessed,
– and the user-agent which made the request.
3
WebFaction Software Documentation, Release
• Shared Apache error logs – Logs of the filename form beginning ‘error_website_name_php.log’
record error events for all shared Apache-based applications reached through website_name. This includes
all shared Apache-based applications, such as Trac, Subversion, and Static/CGI/PHP applications. Such logs
record a date and time and an error message.
For example, suppose you have a Website entry with this configuration:
mysite
/ --> htdocs (Static/CGI/PHP)
/blog/ --> wp (WordPress)
/testing/ --> fancyapp (Django)
mysite‘s access logs are stored in files beginning with access_mysite.log, while mysite‘s error logs are
stored in files beginning with error_mysite.log. ‘access_mysite_php.log’ records htdocs and wp‘s
errors but not fancyapp‘s errors. fancyapp‘s error logs are stored elsewhere; see User Logs for details.
~/logs/user stores logs associated with many applications, including popular applications such as Django. There
are two types of logs which appear in ~/logs/user:
• Access logs – Logs of the filename form ‘access_app_name_log’ record attempts to access the named
application. The format of such logs vary with the type of long-running server process associated with the
application, but typically these logs record originating IP address, date and time, and other details.
• Error logs – Logs of the filename form ‘error_app_name_log’ record error events associated with the
named application. Typically, these logs record error messages and their date and time.
Note: Some older installed applications may not store their logs in ~/logs/user. If you cannot find a particular
application’s logs in ~/logs, look in the application’s directory (~/webapps/app_name). For example:
• Django: ~/webapps/app_name/apache2/logs
• Rails: ~/webapps/app_name/logs/
• Zope: ~/webapps/app_name/Zope/var, ~/webapps/app_name/zinstance/var/log
RSS COMMAND
RSS stands for resident set size. RSS is the physical memory used by the process in kilobytes (kB). COMMAND is
the process’s command along with any arguments used to start it.
The next four rows show a Rails application running with Passenger and nginx:
The PassengerNginxHelperServer and Passenger processes are the passenger component of the applica-
tion that handles, for example, executing Ruby code. The two nginx processes are the web server component of the
application, which respond to the incoming HTTP requests. Altogether these processes are consuming 10,704KB or
just over 10 megabytes (MB).
The next row is the ps process itself:
Although there are three processes, this is just one ordinary Django application. These are the Apache processes used
to respond to HTTP requests and to run Django itself. Together these processes are consuming 18,668KB or just over
18MB of memory.
Finally, the last two lines show us johndoe’s connection to the server:
These processes are the SSH service and the Bash prompt, which allow johndoe to interact with the server from afar.
They use relatively little memory, 3,060KB or just under 3MB.
In total, johndoe is using less than 32MB of memory, which is well under the limit for his Shared 1 plan, so he’s not
at risk of having his processes terminated and having to find ways to reduce his memory consumption.
If johndoe’s processes had exceeded his plan limits, he would first receive a warning. If his processes continued—by
duration or by total memory consumption—to exceed the plan limits, some of his processes would be terminated and
additional notifications sent.
We recommend that you use the getfacl and setfacl command line tools to manage file permissions. These tools allow
you to set file permissions with much greater security and granularity than chmod, chown, and chgrp.
getfacl and setfacl allow you to manage file ACL S (Access Control Lists). Using ACLs to manage permissions lets
you grant permissions to other users without granting those permissions to all other users, which is a critical security
concern in a shared hosting environment.
The most common use case for granting permissions to another user is to grant permissions to the apache user or
another SSH/SFTP user created with the control panel.
Note: getfacl and setfacl Documentation
You can view complete documentation for getfacl or setfacl by entering man getfacl or man setfacl, respec-
tively, during an interactive SSH session.
To review the permissions granted to a given file or directory, enter ‘getfacl path’ where path is the path from
the current directory to the desired file or directory.
For example, getfacl ran in demo‘s home directory returns:
# file: .
# owner: demo
# group: demo
user::rwx
user:apache:r-x
user:nginx:r-x
group::--x
mask::r-x
other::---
If path is a directory, you can review permissions recursively by adding -R immediately after getfacl.
To prohibit read, write, and execute access for all other users (users which are neither yourself or otherwise specified
in the ACL) enter ‘setfacl -m o::---,default:o::--- path’ where path is the path to a file.
If path is a directory, you can set permissions recursively by adding -R immediately after setfacl.
To grant specific users read, write, and execute access, enter ‘setfacl -m u:username:permissions
path’ where
You can use Cron to automatically run commands and scripts at specific times.
To review the contents of your crontab:
1. Open an SSH session.
2. Enter crontab -l and press Enter.
To edit your crontab:
1. Open an SSH session.
2. Enter crontab -e and press Enter. Your crontab will open in your default text editor (as specified by the
EDITOR environment variable).
3. Make any desired changes to your cron schedule.
Note: WebFaction web servers are not configured to send mail; the MAILTO cron directive will not work. If
you want to store the output from a cron job, redirect it to a log file.
For example, this cron job would record cron is running every 20 minutes to ~/cron.log:
1.5 Troubleshooting
Unfortunately, things don’t always work as planned. Here you will find troubleshooting hints for general errors and
problems sometimes seen among WebFaction users.
See Also:
WebFaction Blog: Debugging tips for your CGI scripts
The error Site not configured has four common causes and solutions:
• Cause: You recently created a new website record in the control panel.
Solution: Wait up to five minutes for your website record to be fully configured.
• Cause: You created a new domain entry in the control panel, but did not create a corresponding site website
record.
Solution: Create a site record which references your newly created domain entry.
• Cause: You accessed a website with the wrong protocol—in other words, a protocol other than the one config-
ured in the website entry. For example, you accessed a website configured for HTTPS via HTTP or vice-versa.
Resolution: Reenter the URL with the HTTP or HTTPS as the protocol or modify the website record to use the
intended protocol.
See Also:
WebFaction User Guide > Secure Sites (HTTPS)
• Cause: You attempted to access the site by the website’s IP address.
Resolution: Accessing websites by IP addresses is not supported. Please use the URL with the domain name
selected in the control panel, typically one you supply or of the form ‘username.webfactional.com’.
1.5.2 Errors: 503 Service Temporarily Unavailable and 502 Bad Gateway
If an application’s process is down, the front-end web server will report either a 503 Service Temporarily Unavailable
(on Apache servers web1 through web56) or 502 Bad Gateway error (on nginx servers web57 and up). Some reasons
your process may be down include:
• the application took too long to respond to the front-end web server;
• a bug in the application code caused the application to crash;
• the application consumed too much memory and it was terminated (in which case you will also receive an email
notification);
• or the server was rebooted and your application has not yet restarted.
In most cases these errors can be fixed immediately by manually restarting the process for that application. For more
information on restarting your application, please see the documentation for your application type.
1.5. Troubleshooting 9
WebFaction Software Documentation, Release
TWO
BAZAAR
To install Bazaar:
1. Open an SSH session to your account.
2. Install Bazaar. Enter easy_install bzr and press Enter.
Note: You can specify which Python version to use to install Bazaar by entering ‘easy_install-X.Y
bzr’ where X.Y is a Python version number. For example, to use Python 2.5, enter easy_install-2.5
bzr.
3. Configure the default name and email address to appear by default in commits made from your Bazaar installa-
tion. Enter ‘bzr whoami "name <email_address>"’.
You can now use the command line tool bzr to work with Bazaar repositories. Enter bzr help and press Enter
for a list of commands. To learn more about using Bazaar, see Bazaar in five minutes and the Bazaar User Guide.
You can create an application to serve the Loggerhead server on the web.
The first step in publishing Bazaar repositories on the web is to create a Custom app.
1. Log in to the WebFaction control panel.
2. Click > Domains / websites → Applications. The Apps list appears.
11
WebFaction Software Documentation, Release
6. Click the Create button. The app will be created and the View page appears.
7. Make a note of the number provided by the Port field. This number is needed later in the setup process.
Next, create a website entry to direct requests from a domain name to your Custom app.
1. Log in to the WebFaction control panel.
2. Click > Domains / websites → Websites. The Sites page appears.
6. Click the Add new button ( ). An additional row in the Site apps table appears.
7. Click to select your Custom app from the App menu.
8. Enter a URL path in the URL path field.
9. Click the Create button. The View page appears.
Next, a directory needs to be created where the repositories themselves will be stored. Typically, this will be a directory
outside of the Static/CGI/PHP application’s directory.
1. Open an SSH session to your account.
2. Create the repository directory. Enter ‘mkdir ~/directory_name’ and press Enter. For example, enter
mkdir ~/bzr and press Enter.
Next, install Loggerhead’s dependencies. Loggerhead requires SimpleTAL, simplejson, and Paste.
1. Install the latest version of SimpleTAL for Python 2. You can find a link to the latest ver-
sion from Download SimpleTAL for Python 2. For example, enter ‘easy_install-2.5
http://www.owlfish.com/software/simpleTAL/downloads/SimpleTAL-4.2.tar.gz’
and press Enter.
2. Install simplejson. Enter easy_install-2.5 simplejson and press Enter.
3. Install Paste. Enter easy_install-2.5 Paste and press Enter.
The next step is to download Loggerhead and configure it to use the right version of Python.
1. Open an SSH session into your account.
2. Switch to the Custom app directory. Enter ‘cd ~/webapps/custom_app_name’.
12 Chapter 2. Bazaar
WebFaction Software Documentation, Release
3. Download the latest version of Loggerhead. You can find a link to the lat-
est version from the Loggerhead download page. For example, enter ‘wget
http://launchpad.net/loggerhead/1.17/1.17/+download/loggerhead-1.17.tar.gz’
and press Enter. An archive is created in the current directory.
4. Decompress the Loggerhead archive. Enter ‘tar -xvf loggerhead-version_number.tar.gz’ and
press Enter. A directory called loggerhead is created.
5. Switch to the loggerhead directory. Enter cd loggerhead and press Enter.
6. Open serve-branches in a text editor.
7. Edit the first line of the file from this:
#!/usr/bin/env python
to this:
#!/usr/bin/env python2.5
where
• <username> is your username,
• <custom_app_name> is the name of your Custom app,
• <number> is the port number assigned to your Custom app,
• and <bzr_directory> is the full path to the directory you created to store repositories (e.g.
/home/username/bzr).
4. Save and close the file.
Now, every twenty minutes your Loggerhead installation will be automatically restarted. Once the Loggerhead process
starts, you can access your repositories on the web at the domain and path you specified previously.
14 Chapter 2. Bazaar
CHAPTER
THREE
CUSTOM APPLICATIONS
If there is software you want to run which does not have a provided one-click installer but can respond to HTTP
requests by listening to a specific port, you can use a Custom app (listening on port) application.
A Custom app (listening on port) application assigns a specific port number and creates a subdirectory in ~/webapps
for your use. To create a custom application:
1. Log in to the control panel.
2. Click Domains / websites → Applications. The Apps list appears.
On occasion, your custom application may stop running. There are a number of potential causes for this, such as:
• a bug in your application has caused it to crash,
• your application consumed too much memory and was terminated,
• the server was restarted.
Since you probably won’t be watching the application constantly, it’s advisable to set up a cron job which will auto-
matically restart your application if it is no longer running.
While some applications may gracefully restart by simply running the same command used to launch the program in
the first place, others may have unexpected or unpleasant side-effects, such as starting numerous copies of the same
program, quickly consuming your memory allotment. For such applications, we recommend wrapping your command
in a script which verifies the application is not already running beforehand.
15
WebFaction Software Documentation, Release
FOUR
DJANGO
Django is an open source Python web development framework. It enables Python developers to build web applications
with a minimum of time, effort, and code. You can learn more about Django and see the official documentation at the
Django website.
WebFaction has prepared a screencast which will help you get up and running with Django quickly. You can watch it
on YouTube.
You can also download the zip file containing the paste app demonstrated in the video.
In the screencast, we mentioned some useful resources. Here’s a handy list of hyperlinks from the screencast:
• [0:25] Django
• [1:08] Pastebin
• [8:43] Dive Into Python
• [8:46] Django Documentation
• [8:53] Webfaction Django Forums
It’s easy to setup a Django application. In the following sections, you will learn how to create a Django application,
create the database, setup applications to serve static media, configure Django, and make sure everything is working
smoothly.
17
WebFaction Software Documentation, Release
To reduce memory consumption and improve responsiveness, create a static application to serve static media directly
by the server (instead of the Django process).
1. Click the Add new button. The Add page appears.
2. Enter a name for the application in the Name field.
3. Click to select Static only (no .htaccess) from the App type menu.
4. Click the Create button. Your application is created and the confirmation page displayed.
The admin site media is static media and you should avoid serving it with Django; instead, you should let the server-
wide nginx or Apache process take care of serving admin media. This will increase responsiveness and reduce memory
consumption.
To serve the admin site media with the nginx or Apache process on the server, create a symbolic link application to
serve the media:
1. Click the Add new button. The Add page appears.
2. Enter a name for the application in the Name field.
3. Click to select Symbolic link from the App type menu.
4. Enter the path to the Django admin site media in the Extra info field. Typically, the path is
home_directory/webapps/django_application/lib/python2.5/django/contrib/admin/media.
5. Click the Create button. The confirmation page is displayed.
Note: Do you already have a Django project up and running and just want to change how the admin site media is
served? Complete the directions above, then:
1. Click Domains / websites → Websites.
2. Click the Edit button for the website entry which hosts your Django application. The Edit page appears.
3. Click the Add new ( ) button. An additional row appears in the Site apps table.
4. Click to select your symbolic link application from the App menu.
5. Enter your existing static media URL path and /admin in the URL path field. For example, if the existing
static media path is /media, then the new URL path entry would be /media/admin.
6. Click the Update button.
The admin site media will now be served by the web server instead of the Django process.
18 Chapter 4. Django
WebFaction Software Documentation, Release
The next step is to configure the WebFaction control panel to proxy requests to the Django application, static media
application, and admin media symbolic link application.
1. Click Domains / websites → Websites. The Sites page appears.
5. Click the Add new ( ) button. A row is added to the Site apps table.
6. Click to select the Django application from the App menu.
7. Enter / in the URL path field.
8. Click the Add new ( ) button. A row is added to the Site apps table.
9. Click to select the static media application from the App menu.
10. Enter /media in the URL path field.
11. Click the Add new ( ) button. A row is added to the Site apps table.
12. Click to select the admin media symbolic link application from the App menu.
13. Enter /media/admin in the URL path field.
14. Click the Create button.
Now, configure the Django application to use your new media applications, send email, and connect to your database.
Note: Do you have your own project ready to go or would rather start a project with a different name?
To substitute myproject by creating a new project or uploading your own:
1. Open an SSH session.
2. Enter ‘cd ~/webapps/django_application’ and press Enter.
20 Chapter 4. Django
WebFaction Software Documentation, Release
Note: The email addresses entered for SERVER_EMAIL and DEFAULT_FROM_EMAIL must be set up in the control
panel.
The final stage of the process is to synchronize the database with manage.py and restart Apache.
1. Change to the project directory (typically found at ‘home_directory/webapps/django_application/myproject’).
2. Run ‘python2.5 manage.py syncdb’. The database will be updated. You may be prompted to create a
superuser; if so, create one now.
3. Change to Apache’s bin directory, found at ‘home_directory/webapps/django_application/apache2/bin’.
4. Run ./restart.
You can now open ‘http://domain/admin’ and admire your admin site.
You can restart your Django application’s Apache server at any time. To restart the Apache instance and Django:
1. Open an SSH session.
2. Switch to the Django application’s directory. Enter ‘cd ~/webapps/django_app’ where django_app is
the name of the Django application as it appears in the control panel, and press Enter.
3. Run the restart script. Enter ./apache2/bin/restart and press Enter. Your Django application restarts
over a few seconds.
Note: Alternatively, you may manually start and stop the Apache instance. To stop the server, enter
./apache2/bin/stop and press Enter. To start the server, enter ./apache2/bin/start and press
Enter.
2. Go to your Django application directory. Enter ‘cd ~/webapps/app_name’ where app_name is the name
of the Django app that you are upgrading.
3. Download the Django source package. Enter ‘wget http://www.djangoproject.com/download/version_numbe
where version_number is the version number of the latest Django release (see the Django download page for
the latest version and relase notes) and press Enter. An archive file is created in the current directory.
4. Decompress the archive. Enter ‘tar -xvf Django-version_number.tar.gz’ and press Enter. A
directory containing the contents of the archive is created.
5. Rename your old Django libraries to move them out of the way. Enter ‘mv lib/python2.5/django
lib/python2.5/django.old’ and press Enter.
6. Copy the new libraries into your Python library directory. Enter ‘cp -R
Django-version_number/django lib/python2.5/’ and press Enter.
7. Make any necessary adjustments to your project code as directed by the release notes for the version of Django
to which you are upgrading.
8. Restart Apache. Enter ‘apache2/bin/restart’ and press Enter.
9. Delete the Django source archive and directory. Enter ‘rm -rf Django-version_number*’ and press
Enter.
10. Delete your old Django libraries. Enter ‘rm -rf lib/python2.5/django.old’ and press Enter.
Note: This will not change the Django version number shown in our control panel. The control panel only records
the original version.
The WebFaction control panel includes installers for the latest trunk versions of Django, in both mod_python and
WSGI configurations. These installers use a nightly export of the trunk from the official Django subversion repository.
These installers allow you to run a recent version of Django quickly and easily.
That said, the installers provide exports of the Django trunk, not Subversion working copies of a Django checkout. To
replace installed Django libraries with a Subversion checkout:
1. Open an SSH session to your account.
2. Switch to the Python library directory for your Django application. Enter ‘cd
~/webapps/django_application/lib/python2.X’, where django_application is the name of
the application and X is the minor version number of Python used in this application, and press Enter.
Note: For Django applications created prior to 1 May 2008, the Django source code is found in
‘~/lib/python2.X’. Instead, enter ‘cd ~/lib/python2.X’, where X is the minor version number of
Python used for this application, and press Enter.
3. Remove the existing Django directory. Enter rm -rf ./django and press Enter.
4. Checkout the Django trunk. Enter svn checkout http://code.djangoproject.com/svn/django/trunk/djan
and press Enter. Subversion downloads the latest trunk to ./django.
5. Stop the Apache server. Enter ‘~/webapps/django_application/apache2/bin/stop’ and press
Enter.
6. Restart the Apache server. Enter ‘~/webapps/django_application/apache2/bin/start’ and
press Enter.
Now you can use svn update and other Subversion commands with your Django installation.
22 Chapter 4. Django
WebFaction Software Documentation, Release
4.6 Troubleshooting
Python will raise an ImportError exception whenever it cannot find a particular package or module in an import
statement. This is typically caused by the named module not appearing in Python’s PYTHONPATH environment
variable.
For example, this error sometimes happens while attempting to run manage.py.
To correct the problem, the offending module needs to be added to the PYTHONPATH environment variable. In
the case of Django module errors, you will need to add ~/webapps/django_app_name/lib/python2.5 to
PYTHONPATH. To learn more about making changes to PYTHONPATH, see Fixing ImportError Exceptions.
Django will return an HTTP status code of 500, an Internal Server Error, when Django encounters runtime errors in a
view, such as a syntax error or a view failing to return an object that Django expects.
Closely related to errors in view logic is that Django itself will raise the TemplateDoesNotExist exception when an
error is encountered in a view, the DEBUG setting is set to False and a 500.html template is not available.
The following two sections will help your resolve errors in your views and fix Django’s TemplateDoesNotExist excep-
tion for Internal Server Errors.
When you encounter an Internal Server Error in your Django application, your foremost concern should be to fix your
application so that it does not return an HTTP status code of 500. The best web applications respond to problems
gracefully, without dumping an ugly error on the user.
The first step in fixing a view error is to identify the cause of the problem. A stack trace of the error will automatically
be written to your Django application’s error log.
If the stack trace doesn’t provide you with the information you need to solve the problem, you can set DEBUG to True
in your settings.py file. When DEBUG is True, a stack trace and detailed configuration information is output to
the browser when the error occurs. However, be sure to set DEBUG to False when you are finished debugging: the
debug output contains sensitive information (like file paths and configuration options) and SQL queries are retained in
memory, vastly increasing your application’s memory consumption.
Finally, once you’ve found the source of the error in your view, be sure to update your Django application’s suite of
tests to keep the error from creeping back into your code.
See Also:
Django Documentation > The 500 (server error) view, Django Debug Toolbar
Many Django installations raise an additional exception, TemplateDoesNotExist, when an error is encountered. Typi-
cally this happens when an error occurs while processing a view, no 500.html template is found, and the DEBUG
setting is set to False.
The default error page (provided by Apache) contains this text:
4.6. Troubleshooting 23
WebFaction Software Documentation, Release
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occ
While the error is not described in detail on the page, the error log for the application will look something like this:
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] mod_wsgi (pid=11586): Exception occurred proces
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] File "/home/username/webapps/django/lib/pytho
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] response = self.get_response(request)
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] File "/home/username/webapps/django/lib/pytho
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] return self.handle_uncaught_exception(reque
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] File "/home/username/webapps/django/lib/pytho
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] return callback(request, **param_dict)
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] File "/home/username/webapps/django/lib/pytho
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] t = loader.get_template(template_name) # Yo
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] File "/home/username/webapps/django/lib/pytho
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] source, origin = find_template_source(templ
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] File "/home/username/webapps/django/lib/pytho
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] raise TemplateDoesNotExist, name
[Fri Nov 13 14:04:35 2009] [error] [client 127.0.0.1] TemplateDoesNotExist: 500.html
To resolve this problem, create a new template named 500.html in your templates directory. To see what directories
are currently configured as template directories:
1. Open an SSH session.
2. Enter ‘cd ~/webapps/django_application/myproject’, where django_application is the name of
your Django application as it appears in the control panel and press Enter.
3. Enter ‘python -c "import settings; print settings.TEMPLATE_DIRS"’ and press
Enter.
Then, in one of the template directories, create a new file named 500.html. The file can be as simple as this sample
500.html:
<html>
<head>
<title>Server Error</title>
</head>
<body>
<h1>Sorry!</h1>
<p>Sorry, the server has encountered an error.</p>
</body>
</html>
though it’s recommended that you add contact information to your server error page, so your users can reach you in
the event of a problem.
24 Chapter 4. Django
CHAPTER
FIVE
DRUPAL
Drupal is an open source content management system which can be used to build blogs, portals, and other web sites.
WebFaction provides a control panel installer to make it quick and easy to setup a Drupal site on our servers.
When Drupal is installed with the WebFaction control panel, the SMTP module is automatically included in the final
installation. The SMTP module allows Drupal to use an external SMTP server, such as smtp.webfaction.com.
To configure the SMTP module:
1. Log in to your Drupal web site.
2. In the admin menu, click Administer . The Administer page appears.
3. In the admin menu, click Site configuration. The Site configuration page appears.
4. In the admin menu, click Site information. The Site information page appears.
5. In the E-mail address field, enter an email address which has been created in the WebFaction control panel.
6. Click the Save configuration button. The page reloads with a confirmation message prepended to the top of the
page.
7. In the admin menu, click Site building . The Site building page appears.
8. Click Modules. The Modules page appears.
9. In the Mail section, click to select SMTP Authentication Support.
10. Click the Save configuration button. The page reloads with a confirmation message prepended to the top of the
page.
11. In the admin menu, click Site configuration. The Site configuration pages appears.
12. Click SMTP Authentication Support. The SMTP Authentication Support page appears.
13. Click to select On.
14. In the SMTP server field, enter smtp.webfaction.com.
15. In the SMTP port field, enter 465.
16. Click to select Use SSL from the Use encrypted protocol menu.
17. Enter the WebFaction mailbox name in the Username field.
18. Enter the WebFaction mailbox password in the Password field.
25
WebFaction Software Documentation, Release
19. Enter an email address which has been created in the WebFaction control panel in the E-mail from address
field.
20. Click the Save configuration button. The page will will reload with a confirmation message prepended to the
top of the page.
Now, all future notification email messages and other email sent using PHP’s mail() function will be sent using the
SMTP module.
26 Chapter 5. Drupal
CHAPTER
SIX
GIT
If Git is installed in your home directory, you can push to repositories stored there.
27
WebFaction Software Documentation, Release
You can create an application to serve gitweb.cgi, which makes it possible to browse and clone repositories over
HTTP.
Note: These directions assume you already have Git installed. If you have not yet installed Git, please see Installing
Git.
The first step in publishing Git repositories on the web is to create an application to serve the CGI script.
1. Log in to the WebFaction control panel.
2. Click > Domains / websites → Applications. The Apps list appears.
Next, a directory needs to be created where the repositories themselves will be stored. Typically, this will be a directory
outside of the Static/CGI/PHP application’s directory.
1. Open an SSH session to your account.
2. Create the repository directory. Enter ‘mkdir ~/directory_name’ and press Enter. For example, enter
mkdir ~/git and press Enter.
28 Chapter 6. Git
WebFaction Software Documentation, Release
Now, download the Git sources, build the CGI script, and copy it to the correct location.
1. Open an SSH session to your account.
2. Change to the Static/CGI/PHP application’s directory. Enter ‘cd
~/webapps/static_cgi_php_app_name/’ and press Enter.
3. Remove the existing index.html. Enter rm index.html and press Enter.
4. Download the Git source package. Enter ‘wget http://kernel.org/pub/software/scm/git/git-version_num
where version_number is the version number of the latest Git release (see Git’s homepage for the latest version
and release notes) and press Enter. An archive file is created in the current directory.
5. Decompress the archive. Enter ‘tar -xvf git-version_number.tar.bz2’ and press Enter. A
directory containing the contents of the archive is created.
6. Switch to the archive directory. Enter ‘cd git-version_number’ and press Enter.
7. Build gitweb.cgi. Enter ‘make GITWEB_PROJECTROOT="path_to_repositories"
bindir=path_to_git gitweb/gitweb.cgi’ where path_to_repositories is the directory cre-
ated to store your repositories (for example, /home/username/git) and path_to_git is the directory where
you installed the Git executables (typically, ~/bin). The script will be compiled in the gitweb subdirectory.
8. Copy the CGI script and supporting files to the Static/CGI/PHP directory. Enter ‘cp ./gitweb/git-*
./gitweb/gitweb.css ./gitweb/gitweb.cgi ~/webapps/application_name’ and press
Enter.
9. Return to the parent directory. Enter cd .. and press Enter.
10. Remove the installation directory. Enter ‘rm -r git-version_number’.
11. Remove the installation archive. Enter ‘rm git-version_number.tar.bz2’.
The next step is to instruct apache to use gitweb.cgi to respond to requests made to the Static/CGI/PHP application.
1. Open an SSH session to your account.
2. Change to the Static/CGI/PHP application’s directory. Enter ‘cd
~/webapps/static_cgi_php_app_name/’ and press Enter.
3. Open a new file named .htaccess.
4. Edit the file so that it looks like the following:
DirectoryIndex gitweb.cgi
RewriteEngine on
RewriteRule ^[a-zA-Z0-9_\-]+\.git/?(\?.*)?$ gitweb.cgi%{REQUEST_URI} [L,PT]
See Also:
To password protect the Gitweb site, you can modify the .htaccess file as described in Password Protecting
a Directory with a Static/CGI/PHP App. It may be convenient to make these changes now, while the file is
already open.
5. Save and close the file.
Finally, it’s time to create a website entry so that requests can be proxied from a URL to gitweb.cgi‘s application.
1. Log in to the WebFaction control panel.
2. Click > Domains / websites → Websites. The Sites page appears.
6. Click the Add new button ( ). An additional row in the Site apps table appears.
7. Click to select your Static/CGI/PHP application from the App menu.
8. Enter a URL path in the URL path field.
9. Click the Create button. The View page appears.
You can now visit the domain and path specified in the website entry to see your Git repositories. The listing is
probably empty now, however; create new repositories with ‘git init repository_name’ in your repository
directory to populate the list.
30 Chapter 6. Git
CHAPTER
SEVEN
JOOMLA
31
WebFaction Software Documentation, Release
32 Chapter 7. Joomla
CHAPTER
EIGHT
MEMCACHED
33
WebFaction Software Documentation, Release
34 Chapter 8. Memcached
CHAPTER
NINE
MERCURIAL
Mercurial, commonly referred to as Hg (the symbol for the element Mercury), is an open source distributed version
control system.
See Also:
Bazaar, Git
[ui]
username = name <your_email_address>
subtituting name and your_email_address with the name and email address you would like to have appear by
default in commits made from your Mercurial installation.
5. Save and close the file.
You can now use the command line tool hg to work with Mercurial repositories. Enter hg help and press Enter
for a complete list of commands. To learn more about using Mercurial, check out the official Quick Start guide and
the Mercurial book.
You can create an application to serve hgwebdir.cgi (also known as HgWeb), which makes it easy to view repos-
itories with a web browser, as well as push and pull changes over HTTPS.
Note: These directions assume you already have Mercurial installed. If you have not already installed Mercurial,
please see Installing Mercurial.
35
WebFaction Software Documentation, Release
The first step in serving Mercurial repositories is to create an application to serve the CGI script.
1. Log in to the WebFaction control panel.
2. Click > Domains / websites → Applications. The Apps list appears.
Next, a directory needs to be created where the repositories themselves will be stored. Typically, this will be a directory
outside of the Static/CGI/PHP application’s directory.
1. Open an SSH session to your account.
2. Create the repository directory. Enter ‘mkdir ~/directory_name’ and press Enter. For example, enter
mkdir ~/hg and press Enter.
Now, download the Mercurial sources, which contain a CGI script which will make repositories available on the Web.
1. Open an SSH session to your account.
2. Change to the Static/CGI/PHP application’s directory. Enter ‘cd
~/webapps/static_cgi_php_app_name/’ and press Enter.
3. Remove the existing index.html. Enter rm index.html and press Enter.
4. Download the Mercurial sources. Enter wget http://selenic.com/repo/hg-stable/archive/tip.tar.bz2
and press Enter. An archive named tip.tar.bz2 is created in the current directory.
5. Decompress the archive. Enter ‘tar -xvf tip.tar.bz2’ and press Enter. A new directory named
Mercurial-stable-branch--hexadecimal_number is created in the current directory containing
the contents of the archive.
6. Copy Mercurial-stable-branch--hexadecimal_number/hgwebdir.cgi to the current direc-
tory. Enter ‘cp Mercurial-stable-branch--hexadecimal_number/hgwebdir.cgi .’ and
press Enter.
7. Remove the archive directory. Enter ‘rm -r Mercurial-stable-branch--hexadecimal_number’
and press Enter.
8. Remove the archive. Enter ‘rm Mercurial-stable-branch--hexadecimal_number.tar.bz2’
and press Enter.
Now, configure hgwebdir.cgi so it knows where to look for your Mercurial installation and repositories.
1. Open an SSH session to your account.
36 Chapter 9. Mercurial
WebFaction Software Documentation, Release
#!/usr/bin/env python
by replacing python with ‘pythonX.Y’, where X and Y are the major and minor version numbers of Python,
respectively.
6. Uncomment these lines:
#import sys
#sys.path.insert(0, "/path/to/python/lib")
and replace "/path/to/python/lib" with the path to the directory where you installed Mercurial. If you
used the default easy_install, this directory will be /home/username/lib/python2.4.
7. Save and close the file.
8. Open a new file named hgweb.config.
9. Edit the file so that it looks like the following:
[paths]
/ = /path/to/repositories/**
where /path/to/repositories is the path to your Mercurial repositories (for example, ‘/home/username/hg’).
Note: The asterisks (*) are required for hgwebdir.cgi to find your repositories; they permit hgwebdir.cgi
to find Mercurial repositories which are in a subdirectory of the path specified.
10. Save and close the file.
The next step in publishing your Mercurial repositories is to instruct Apache to use hgwebdir.cgi to respond to
requests.
1. Open an SSH session to your account.
2. Change to the Static/CGI/PHP application’s directory. Enter ‘cd
~/webapps/static_cgi_php_app_name/’ and press Enter.
3. Open a new file named .htaccess.
4. Edit the file so that it looks like the following:
Options +ExecCGI
RewriteEngine On
# / for root directory; specify a complete path from / for others
RewriteBase /
RewriteRule ^$ hgwebdir.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]
Note: If you will not be hosting your repositories from the root URL path, replace RewriteBase /
with ‘RewriteBase /path/to/directory’. For example, if you were to host your repositories at
http://www.example.tld/hg you would substitute RewriteBase / with RewriteBase /hg.
5. Save and close the file.
Finally, it’s time to create a website entry so that requests can be proxied from a URL to hgwebdir.cgi‘s applica-
tion.
1. Log in to the WebFaction control panel.
2. Click > Domains / websites → Websites. The Sites page appears.
7. Click the Add new button ( ). An additional row in the Site apps table appears.
8. Click to select your Static/CGI/PHP application from the App menu.
9. Enter a URL path in the URL path field. If you did not change the contents of .htaccess from the version
suggested in Configure Apache to Use hgwebdir.cgi, enter /.
10. Click the Create button. The View page appears.
You can now visit the domain and path specified in the website entry to see your Mercurial repositories. The listing
is probably empty now, however; create new repositories with hg init in your repository directory to populate the
list.
Now that you have a working repository browser, you can enable pushing to those repositories over HTTPS for
authenticated users.
1. Open an SSH session to your account.
2. Change to the Static/CGI/PHP application’s directory. Enter ‘cd
~/webapps/static_cgi_php_app_name/’ and press Enter.
3. Open .htaccess in a text editor.
4. Add the following lines to the bottom of .htaccess to permit pushes only by authenticated users:
AuthType Basic
AuthName MyHgWebDir
AuthUserFile /home/<username>/webapps/<static_cgi_php_app>/.htpasswd
<Limit POST PUT>
Require valid-user
</Limit>
<Files ~ "^\.ht">
Order allow,deny
38 Chapter 9. Mercurial
WebFaction Software Documentation, Release
AuthType Basic
AuthName MyHgWebDir
AuthUserFile /home/<username>/webapps/<static_cgi_php_app>/.htpasswd
Require valid-user
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
[web]
allow_push = *
Note: Alternatively, you can replace * with a comma separated list of users authorized to push. Or, for
more finely grained control, you can add these lines on a repository-by-repository basis in the repositories’
.hg/hgrc file.
7. Save and close the file.
You can now push to the repositories as an authenticated user.
40 Chapter 9. Mercurial
CHAPTER
TEN
MONGODB
Warning: WebFaction servers only support the 32 bit version of MongoDB, which is limited to storing approx-
imately 2.5GB of data. For more information on this limitation, please see the MongoDB blog article “32 bit
limitations.”
41
WebFaction Software Documentation, Release
To learn more about using MongoDB, please see the official MongoDB tutorial. To learn more about using your
preferred programming language with MongoDB, please see the MongoDB drivers documentation.
ELEVEN
PERL
The Perl interpreter is installed on all WebFaction machines. The currently installed version is 5.8.8. You can run the
Perl interpreter by executing perl or perl5.8.8.
CPAN is the Comprehensive Perl Archive Network, a mirrored archive of Perl modules. You can use the cpan tool to
easily download and install Perl modules from CPAN.
To use cpan and access CPAN, you must first configure the command line tool. To configure cpan:
1. Log into your SSH account.
2. Enter the following commands, pressing Enter after each line:
mkdir -p ~/lib/perl5
echo ’
export PERL5LIB=${PERL5LIB}:~/lib/perl5:~/lib/perl5/lib:~/lib/perl5/lib/i386-linux-thread-multi/
source ~/.bashrc
3. Enter perl -MCPAN -e shell and press Enter. The following prompt will appear:
If you do not want to enter a dialog now, you can answer ’no’ to this
question and I’ll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing ’o conf init’ at the cpan prompt.)
4. Repeatedly press Enter to continue, accepting each default setting through the following prompts:
• Are you ready for manual configuration? [yes]
• ‘CPAN build and cache directory? [/home/username/.cpan]’
• Cache size for build directory (in MB)? [10]
• Perform cache scanning (atstart or never)? [atstart]
• Cache metadata (yes/no)? [yes]
43
WebFaction Software Documentation, Release
Your choice: []
Now we need to know where your favorite CPAN sites are located. Push
a few sites onto the array (just in case the first on the array won’t
work). If you are mirroring CPAN to your local workstation, specify a
file: URL.
First, pick a nearby continent and country (you can pick several of
each, separated by spaces, or none if you just want to keep your
existing selections). Then, you will be presented with a list of URLs
of CPAN mirrors in the countries you selected, along with previously
selected URLs. Select some of those URLs, or just keep the old list.
Finally, you will be prompted for any extra URLs -- file:, ftp:, or
(1) Africa
(2) Asia
(3) Australasia
(4) Central America
(5) Europe
(6) North America
(7) Oceania
(8) South America
Select your continent (or several nearby continents) []
8. Since WebFaction’s servers are located in the United States, enter 6 and press Enter. The following prompt
appears:
Sorry! since you don’t have any existing picks, you must make a
geographic selection.
(1) Bahamas
(2) Canada
(3) Mexico
(4) United States
Select your country (or several nearby countries) []
9. Enter 4 and press Enter. Another prompt, listing available CPAN mirrors appears.
10. Enter 1 2 3 4 5 6 7 8 9 10 and press Enter.
11. Press Enter to quit the configuration process. The cpan> prompt appears.
12. Press Ctrl + D to exit.
You can now install CPAN modules. To install a module with cpan, enter ‘cpan install module_name’. For
example, cpan install Locale::gettext.
TWELVE
PHP
The PHP interpreter is installed on all WebFaction machines. The currently installed PHP interpreter is 5.2.6 and it
can be run by executing php.
WebFaction runs web servers separate from mail servers. As a result, our web servers are not equipped with sendmail,
upon which PHP’s built-in mail() function relies.
To send mail from a PHP script, the script must connect to and send mail from an SMTP server. There are several
packages available which simplify this method of sending mail:
• Swift Mailer
• PEAR’s Mail package
• Zend Framework’s Zend_Mail
For example, this PHP script uses the PEAR Mail package to send an email:
<?php
require_once "Mail.php";
For this script to work, the values for from_addr, my_mailbox_name, and password1 would be changed to an address
registered in the control panel, a valid WebFaction mailbox name, and a valid mailbox password, respectively.
See Also:
47
WebFaction Software Documentation, Release
THIRTEEN
PLONE
Plone is an open source content management system built on top of Zope. Zope is an open source web application
server.
If you have lost or forgotten the admin password for the Zope Management Interface (ZMI), you can create an emer-
gency user with zpasswd.py. To create an emergency admin user:
1. Open an SSH session to your account.
2. Switch to the directory where zpasswd.py is located. Enter ‘cd
~/webapps/plone_app/zinstance/parts/zope2/utilities/’ where plone_app is the
name of the application as it appears in the control panel, and press Enter.
3. Enter ‘./zpasswd.py -u username access’ where username is the name of the new emergency ac-
count, and press Enter.
4. When the password prompt appears, enter a password for the emergency account and press Enter.
5. When the verify password prompt appears, reenter the password for the emergency account and press Enter.
49
WebFaction Software Documentation, Release
Many Plone packages are distributed as Python eggs through the Python Package Index. To install such packages into
a Plone application:
1. Open an SSH session.
2. Switch to the Plone application’s zinstance directory. Enter ‘cd
~/webapps/plone_application/zinstance’, where plone_application is the name of the Plone
application as it appears in the control panel, and press Enter.
3. Open buildout.cfg.
4. In this portion of the file:
enter the name of the package to be installed as it appears on the Python Package Index on a new line beneath
eggs =, indenting four spaces.
For example, suppose new.package were to be installed. buildout.cfg would be edited to contain:
FOURTEEN
PYTHON
The Python interpreter is installed on all WebFaction machines. For your convenience, several different Python ver-
sions are available. All of our machines have the following versions installed:
• Python 2.4
• Python 2.5
• Python 2.6
• Python 3.0
• Python 3.1
Some machines also have Python 2.3 installed. For a listing of Python installations on your machine, enter ls
/usr/local/bin/ | grep python in an SSH session. To identify the default Python version, enter python
--version.
To specify a Python version, use pythonX.Y where X is the major version number and Y is the minor version number.
For example, to use Python 2.6, enter python2.6.
Additionally, ~/lib/pythonX.Y is automatically added to your PYTHONPATH for each version of Python you
use. You can see the contents of your PYTHONPATH by entering ‘pythonX.Y -c "import sys; print
sys.path"’.
Many common Python packages can be automatically installed with easy_install. easy_install will look up informa-
tion about the module from the Python Package Index (also known as the “Cheeseshop”), download, and install the
module automatically.
51
WebFaction Software Documentation, Release
Some packages are distributed as Python Eggs. These are single files which contain an entire Python package and
typically have the .egg file extension. Eggs are installed using easy_install.
To install an egg, enter easy_install path_to_egg.
To specify a different Python version, substitute easy_install with easy_install-X.Y, where X is the major version
number and Y is the minor version number. For example, to use Python 2.5, enter easy_install-2.5.
To specify a specific web application which makes use of the Python interpreter, enter
‘easy_install-X.Y --install-dir=$HOME/webapps/app_name/lib/pythonX.Y
--script-dir=$HOME/webapps/app_name/bin path_to_egg’.
Many packages are distributed with a setup.py file created with the help of setuptools.
To install a package with setup.py:
1. Create a symbolic link from ~/lib/python to a specific Python version. Enter ln -s
~/lib/pythonX.Y ~/lib/python where X is the major version number and Y is the minor version
number.
2. In the same directory as setup.py, enter pythonX.Y setup.py install --home=$HOME.
3. Remove the symbolic link. Enter rm ~/lib/python.
To install a package with setup.py to a specific web application which
makes use of the Python interpreter, enter ‘pythonX.Y setup.py install
--install-lib=$HOME/webapps/app_name/lib/pythonX.Y/ --install-scripts=$HOME/webapps/app_nam
Note: To install a package with setup.py and the --install-lib and --install-scripts options, the
--install-lib directory must also be in PYTHONPATH.
If you have some Python source files, such as a version control checkout, you can install those files manually to
~/lib/pythonX.Y where X is the major version number and Y is the minor version number of a Python installa-
tion. Just copy to or symbolically link files in the desired directory.
Alternatively, you can install packages directly to a web application which makes use of the Python interpreter by
installing to ~/webapps/app_name/lib/pythonX.Y.
14.2 Troubleshooting
Python will raise an ImportError exception whenever it cannot find a particular package or module as requested
by an import statement. This is caused by the named module not appearing in any of the module search path
directories. The Python search path, represented in Python as the list sys.path, is constructed from Python defaults,
the PYTHONPATH environment variable, and direct manipulations to sys.path.
To see the contents of sys.path:
1. Run Python interactively. Enter ‘pythonX.Y’ and press Enter.
2. At the prompt, enter import sys and press Enter.
3. At the prompt, enter print sys.path and press Enter. The contents of sys.path will be displayed on
screen.
By default, Python searches in this order:
1. the directory where Python is executed;
2. if applicable, the ~/webapps/app_name/lib/pythonX.Y; directory where app_name is the name of an
application and X and Y are the Python major and minor version numbers, respectively.
3. the ~/lib/pythonX.Y directory;
4. directories specified by PYTHONPATH;
5. the Standard Library;
6. built-in components of Python.
There are several possible fixes for this problem:
• add the path of the module to PYTHONPATH in your ~/.bash_profile file,
• add the path to the module to PYTHONPATH from the command line before executing the Python program
which raises the exception,
• add the path to the module to sys.path before the import statement which raises the exception within the
offending program,
• add the path to the module to httpd.conf for applications using mod_python,
• add the path to the module to myproject.wsgi for applications using WSGI,
• or, install offending packages directly to a path where Python will find it.
See Also:
For more information on how Python loads modules, please see The Python Tutorial » 6. Modules.
Adding an entry to the end of the PYTHONPATH environment variable is an easy and persistent way to avoid
ImportError exceptions. Unfortunately, this approach can cause complications while debugging Python programs,
since the change to the PYTHONPATH environment variable happens silently, before you enter any commands at all.
This is especially apparent when using two or more versions of the same module.
To add the path to a Python module to the PYTHONPATH environment variable from the ~/.bash_profile file:
1. Open ~/.bash_profile with a text editor.
14.2. Troubleshooting 53
WebFaction Software Documentation, Release
You can add to the PYTHONPATH environment variable with each run of a Python program. This method is not
persistent, which makes it easy to switch between versions of a particular module. Unfortunately, it requires that you
include the PYTHONPATH changes on each run of the program. You can also use this method in conjunction with the
.bash_profile method.
To add the path to a Python module to the PYTHONPATH environment variable from the command line, run the
program like this:
‘PYTHONPATH=path_to_module:$PYTHONPATH python program_name’
You can add to Python’s module search path programmatically, within Python. It requires that you make changes to
each Python program for which you want to change the module search path.
To add to sys.path within Python, add the following statements before the import statement which raises the
ImportError exception:
import sys
sys.path.insert(0, "path_to_module")
For web applications running on mod_python, the Python module search path can be amended in the httpd.conf
file found in /home/username/webapps/appname/apache2/conf/. Typically, a httpd.conf contains
a line similar to this:
You can add additional paths by inserting paths as new items in the list following the PythonPath directive. Paths
added to that list will be included in Python’s search for modules.
For WSGI-based applications, sys.path can be modified in the myproject.wsgi file found in
/home/username/webapps/appname/. Typically, a myproject.wsgi contains a line similar to this:
You can add additional paths by inserting paths as new items in the list. Paths added to that list will be included in
Python’s search for modules.
Finally, for any application which makes use of the Python interpreter, you can also install or copy modules and
packages directly to a directory which is included in Python’s search path.
For example, you could install additional modules to the ~/webapps/app_name/lib/pythonX.Y directory,
which are included in the search path for the application by default.
For more information about installing Python packages and modules, see Installing Python Packages.
14.2. Troubleshooting 55
WebFaction Software Documentation, Release
FIFTEEN
RUBY ON RAILS
Ruby on Rails, also known as Rails or RoR, is an open source Ruby web development framework. It enables developers
to quickly design, develop, and deploy web applications. You can learn more about Ruby on Rails at the Rails website.
Tip: Add bin to PATH
While working with a Ruby on Rails application, you may find it easier to add the application’s bin directory to
the PATH environment variable and set the GEM_HOME environment variable while working with that application
instead of specifying complete paths to ~/webapps/ruby_app/bin and ~/webapps/ruby_app/gems.
To set the environment variables:
1. Switch to the directory of the Ruby application. Enter ~/webapps/{ruby_app} where ruby_app is the
name of the application as it appears in the WebFaction control panel.
2. Enter export PATH=$PWD/bin:$PATH and press Enter.
3. Enter export GEM_HOME=$PWD/gems and press Enter.
Now, programs like gem and rake will work as expected for that application.
To revert the changes to PATH and GEM_HOME (to work with a different Ruby on Rails application, for example),
just log out and log back in again.
WebFaction’s Ruby on Rails installer creates an nginx instance running Passenger and Ruby Enterprise Edition. To
install a Rails application:
1. Log in to the WebFaction control panel.
2. Click Domains / websites → Applications. The list of currently installed applications appears.
57
WebFaction Software Documentation, Release
It’s easy to configure a MySQL or PostgreSQL for use with a Ruby on Rails application.
1. Create a database. (a) Use the WebFaction control panel to create a MySQL or PostgreSQL database.
See Also:
For step-by-step directions, see Create a New Database with the Control Panel.
(b) Make a note of the database name and password.
2. Install the Ruby database adapter gem. (a) Open an SSH session.
(b) Switch to the directory of Ruby on Rails application. Enter ‘cd ~/webapps/application’,
where application is the name of the application as it appears in the WebFaction control panel, and
press Enter.
(c) Set the PATH environment variable for the Rails application. Enter export
PATH=$PWD/bin:$PATH and press Enter.
(d) Set the GEM_HOME environment variable for the Rails application. Enter export
GEM_HOME=$PWD/gems and press Enter.
(e) Install the database adapter gem. For MySQL, enter gem install mysql and press Enter. For
PostgreSQL, enter gem install postgres.
3. Configure the Ruby on Rails project to use the MySQL database. (a) Switch to the directory of the Ruby
on Rails project. Enter ‘cd project’, where project is the name of the project (for example,
hello_world), and press Enter.
(b) Open config/database.yml in a text editor.
(c) Edit the production section:
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
to this:
production:
adapter: adapter_type
database: database_name
host: localhost
username: database_name
password: database_password
such that
• adapter_type is either mysql for MySQL databases or postgresql for PostgreSQL databases,
• database_name is the name of the database as it appears in the WebFaction control panel,
• database_name is set to the name of the database as it appears in the WebFaction control panel
and,
• database_password is the database password.
The Rails application is now configured and ready to use the specified database.
SIXTEEN
REDMINE
To install Redmine:
1. Create a Redmine application. (a) Log in to the WebFaction control panel.
(b) Click Domains / websites → Applications. The Apps list appears.
(c) Click the Add new ( ) button. The Add page appears.
(d) In the Name field, enter a name for the Redmine application.
(e) In the App type menu, click to select Passenger 2.2.8 (ngingx 0.7.64/Ruby Enterprise Edition
1.8.7).
(f) Click the Create button. The View page appears with a confirmation message.
2. Create a website entry for the Redmine application. You may wish to add it to an existing website entry or create
a new entry.
See Also:
Create a Website with the Control Panel
3. Create a database for Redmine. (a) Click Databases → Create new database.
(b) In the Name field, enter a name for the database. The database name must be the account name or
prefixed by the account name and an underscore.
(c) Click the Create button. The View page appears with a confirmation message.
(d) The confirmation message contains the database password. Make a note of the password; it will be
needed later.
4. Install the MySQL gem. (a) Open an SSH session.
(b) Switch to the Redmine application directory. Enter ‘cd ~/webapps/redmine_application’
where redmine_application is the name of the Redmine application as it appears in the control panel,
and press Enter.
(c) Enter export GEM_HOME=$PWD/gems and press Enter.
(d) Enter export PATH=$PWD/bin:$PATH and press Enter.
(e) Enter gem install mysql and press Enter.
61
WebFaction Software Documentation, Release
5. Download and install Redmine. (a) Download the Redmine archive. Enter wget
http://rubyforge.org/frs/download.php/69449/redmine-0.9.3.tar.gz
and press Enter. The Redmine archive will be downloaded to the current directory.
Note: Other versions of Redmine can be found at Redmine’s RubyForge page.
(b) Extract the Redmine archive. Enter tar -xf redmine-0.9.3.tar.gz and press Enter. The
files in the archive are extracted to the redmine-0.9.3 directory.
6. Configure Redmine. (a) Switch to the Redmine directory. Enter cd redmine-0.9.3 and press Enter.
(b) Create a copy of the example database configuration file. Enter cp
config/database.yml.example config/database.yml and press Enter.
(c) Open config/database.yml in a text editor.
(d) In the production section of config/database.yml, edit database: redmine such that redmine
is replaced with the name of the Redmine database as it appears in the control panel.
(e) In the production section of config/database.yml, edit username: root such that root is re-
placed with the the name of the Redmine database as it appears in the control panel.
(f) In the production section of config/database.yml, append the database password to the line
containing password:.
(g) Save and close the file.
(h) Enter RAILS_ENV=production rake config/initializers/session_store.rb
and press Enter.
(i) Enter RAILS_ENV=production rake db:migrate and press Enter.
(j) Enter RAILS_ENV=production rake redmine:load_default_data and press Enter.
(k) A prompt appears to select a language. Press Enter for English; otherwise, enter the two-character
code for the language you prefer.
(l) Return to the parent directory. Enter cd .. and press Enter.
(m) Open nginx/conf/nginx.conf in a text editor.
(n) Replace hello_world with redmine-0.9.3.
(o) Save and close the file.
7. Restart the Passenger application. Enter ./bin/restart and press Enter.
The Redmine application may now be reached at the URL specified by the website entry created earlier in the process.
You can login into the Redmine site with the username admin and the password admin. It is recommended that you
change this password as soon as possible.
SEVENTEEN
Static applications host data which are served by the common Apache or nginx processes on the web server. These
applications are ideal for hosting style sheets, images, and other media.
17.1 Static-only
Static-only apps serve static files with the server’s nginx process. A Static-only app is exclusively static; PHP files, for
example, will not be interpreted in a Static-only app. We suggest Static-only apps when you need to serve static media
(and only static media) fast with low memory consumption.
Even if most of your site is served dynamically by Django, Rails, TurboGears, or Zope (just to name a few), you will
still have many static elements, such as style sheets, images, and videos. If these elements are served by your dynamic
process, they will consume unnecessary additional memory and time to serve. You can save memory and time by
serving static files with a Static-only application.
To serve static media with a Static-only application:
1. With the control panel, create a Static-only application.
2. With the control panel, modify or create a website entry which maps an unused path from your domain name
(e.g. ‘www.mydomain.com/media’) to your new Static-only application.
3. Wait up to two minutes for propagation of the new path and domain combination to complete.
4. Copy static media files to ~/webapps/static-only.
Now media served from the ‘/static/’ path of your website will be served by an nginx or Apache process, sparing
your dynamic application from serving those requests.
17.2 Static/CGI/PHP
Static/CGI/PHP apps, in addition to their role in serving static media, add the capacity to serve PHP pages, which are
processed by the PHP interpreter on the server. Static/CGI/PHP apps should only be used when you need to make use
of .htaccess files or PHP pages.
65
WebFaction Software Documentation, Release
By default, files such as .htaccess and .htpasswd are exposed to the web. If you want to hide these files, add
these lines to your .htaccess file:
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
You can password protect the contents of a Static/CGI/PHP application (or a subdirectory) by using a .htaccess file.
To enable password protection:
1. With the control panel, create a Static/CGI/PHP app or identify an existing Static/CGI/PHP app you would like
to use.
2. If necessary, create or modify a website entry which maps the Static/CGI/PHP app to a particular URL.
3. Open an SSH session into your account.
4. Switch to the ~/webapps/static_cgi_php_app/ directory.
5. Create a file named .htaccess with the following contents:
AuthUserFile /home/<your_username>/webapps/<webapp_name>/.htpasswd
AuthName EnterPassword
AuthType Basic
require valid-user
You can use a Static/CGI/PHP app to redirect one domain to another by using Apache’s URL rewriting feature. For
example, you can use a Static/CGI/PHP app to automatically redirect requests arriving at myolddomain.com to
www.mynewdomain.com.
To redirect from origin_domain to destination_domain:
1. With the control panel, create a Static/CGI/PHP app.
2. With the control panel, create a website entry which maps the root of the domain to be redirected (e.g.
‘http://origin_domain/’) to the Static/CGI/PHP app.
3. Open an SSH session.
4. Switch to the ~/webapps/static_app/ directory.
5. Create a file named .htaccess in the current directory.
6. Edit the file so that it contains the following:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^origin_domain$ [NC]
RewriteRule ^(.*)$ http://destination_domain/$1 [R=301,L]
Thus, the file to redirect myolddomain.com to www.mynewdomain.com would look like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myolddomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mynewdomain.com/$1 [R=301,L]
You can configure the maximum size of a file which may be uploaded by a PHP script. The configuration details vary
depending on which server your PHP script is running.
On servers web120 or greater or dweb62 or greater, you can impose an upload limit with a php.ini file. To create
or modify the file:
1. Oepn an SSH session.
2. Switch to your Static/CGI/PHP application directory. Enter cd ~/webapps/{application} where ap-
plication is the name of your application, and press Enter.
3. Open php.ini in a text editor. If it does not already exist, create it.
4. Add these lines to the end of the file:
upload_max_filesize = XM
post_max_size = XM
17.2. Static/CGI/PHP 67
WebFaction Software Documentation, Release
Other Servers
On servers web119 or less or dweb61 or less, you can impose an upload limit with an .htaccess directive. To add
the directive:
1. Open an SSH session.
2. Switch to your Static/CGI/PHP application directory. Enter ‘cd ~/webapps/application’ where appli-
cation is the name of your application, and press Enter.
3. Open .htaccess in a text editor. If it does not already exist, create it.
4. Edit the file to contain these lines:
<IfModule php5_module>
php_value upload_max_filesize XM
php_value post_max_size XM
</IfModule>
where X is the maximum number of megabytes you want to allow to be allowed to be uploaded.
5. Save and close the file.
If the DOCUMENT_ROOT needs to be set to a different value, the value may be changed with an .htaccess or
php.ini file, depending on which server is in use.
<?php
$_SERVER[’DOCUMENT_ROOT’] = ’/home/username/webapps/example_application’;
?>
where the string following the equal sign is the new value.
5. Save and close the file.
6. Open a new (or existing) php.ini file in the same directory.
7. Add a new line containing ‘auto_prepend_file = "/home/username/webapps/application/set_document_
8. Save and close the file.
Other Servers
<?php
$_SERVER[’DOCUMENT_ROOT’] = ’/home/username/webapps/example_application’;
?>
where the string following the equal sign is the new value.
5. Save and close the file.
6. Open a new (or existing) .htaccess file in the same directory.
7. Add these lines:
<IfModule php5_module>
php_value auto_prepend_file "/home/username/webapps/my_app/set_document_root.php"
</IfModule>
17.3 Troubleshooting
In some cases, files uploaded through PHP or WebDAV can become owned by the apache user and group. When files
are owned by apache, they cannot be modified in an SSH session or with SFTP.
To prevent this from happening, the setgid flag must be set on the directory where the files are being saved. This
will cause files saved in the directory to be owned by the same group as the directory itself—in other words, your
user—instead of apache‘s group.
To set the setgid flag for a directory:
1. Open an SSH session to your account.
2. Enter ‘chmod g+s directory’ where directory is the path to the directory where files are owned by apache,
and press Enter.
17.3. Troubleshooting 69
WebFaction Software Documentation, Release
EIGHTEEN
SUBVERSION
Subversion is a version control system. Like other version control systems, Subversion (also known as “svn”) allows
you to track changes to files over time, to make it easier to combine multiple authors’ changes to files and to maintain
a record of “known goood” revisions.
You can use Subversion’s post-commit hook to execute a script after a complete commit has taken place. In this
example, you can send a notification email after each commit to your Subversion repository.
To create a post-commit hook to send an email notification:
1. Create the following script as a file named post-commit in the ~/webapps/svn_app/hooks directory
such that
• from_addr is the address from which the notifications will be sent (this address must be created in the
control panel);
• dest_addrN are the destination addresses for the notification email;
• mailbox_name is the name of the WebFaction mailbox which will be used to send the email;
• mailbox_password is the password for the WebFaction mailbox which will be used to send the email.
#!/usr/local/bin/python2.5
# Settings
mail_server = ’smtp.webfaction.com’
from_email = ’from_addr’
to_email = [’dest_addr1’, ’dest_addr2’]
mailbox_name = ’mailbox_name’
mailbox_password = ’mailbox_password’
import os
import smtplib
import sys
server = smtplib.SMTP(mail_server)
server.login(mailbox_name, mailbox_password)
71
WebFaction Software Documentation, Release
diff = os.popen(cmd).read()
msg = (
"To: %(to_email)s\r\n"
"From: %(from_email)s\r\n"
"Subject: Subversion post-commit: r%(revision)s\r\n"
"Content-type: text/plain\r\n"
"\r\n"
"Repository: %(repository)s\r\n"
"Revision: %(revision)s\r\n"
"Diff:\r\n"
"%(diff)s\r\n"
)
Subversion and Trac use ~/webapps/application/.htpasswd, where application is the name of the applica-
tion, to store usernames and passwords for authorized users. To use the same usernames and passwords between the
two applications, create a symlink from one .htpasswd file to the other:
1. Open an SSH session to your account.
2. Delete one of the application’s (here called the secondary application) .htpasswd files. Enter ‘rm
~/webapps/secondary_application/.htpasswd’ and press Enter.
3. Create a symlink from the primary application‘s .htpasswd file to the secondary applica-
tion‘s .htpasswd location. Enter ‘ln -s ~/webapps/primary_application/.htpasswd
~/webapps/secondary_applicaiton/.htpasswd’.
NINETEEN
WORDPRESS
WebFaction has prepared a screencast to get you up and running with WordPress quickly.
You can watch it on YouTube.
In the screencast, we mentioned some useful resources. Here’s a handy list of hyperlinks from the screencast:
• [0:28] WordPress homepage
• [4:13] Pastebin
• [4:13] WebFaction User Guide > Databases
• [6:38] WordPress > Extend
• [6:43] Webfaction Forum
You can send email messages from WordPress by using the Configure SMTP plugin. To use the Configure SMTP
plugin:
Note: WebFaction includes the SMTP plugin by default with installations of WordPress create after October 2009. If
you’re using an older installation of WordPres, follow these steps to install the Configure SMTP plugin:
1. Open the WordPress site Log In page (for example, http://mydomain.com/wp-login.php) and log in
with the administrator account. The Dashboard page appears.
2. Click Plugins → Add New.
3. Enter smtp in the Search field.
4. Click the Search Plugins button.
5. Find the Configure SMTP plugin in the list that appears.
6. Click the Install link at the end of the row. A dialog with additional information appears.
73
WebFaction Software Documentation, Release
TWENTY
• Index
• Search Page
75