Anda di halaman 1dari 79

WebFaction Software Documentation

Release

Swarma Limited - WebFaction is a service of Swarma


Limited

April 09, 2010


CONTENTS

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

17 Static Files, CGI Scripts, and PHP Pages 65


17.1 Static-only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
17.2 Static/CGI/PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
17.3 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

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

20 Indices and tables 75

ii
WebFaction Software Documentation, Release

Contents:

CONTENTS 1
WebFaction Software Documentation, Release

2 CONTENTS
CHAPTER

ONE

GENERAL TOPICS

1.1 Accessing Logs

Most logs can be found in ~/logs/frontend and ~/logs/user.


Note: To prevent log files from becoming too large, logs are rotated daily at 3:00 a.m. server time. Each
existing log is renamed by appending a number which indicates how many days old the log is. For example,
error_website_name.log is named error_website_name.log.1 initially. Each subsequent day the log
is incremented by one, until the log has aged seven days, upon which it is deleted.

1.1.1 Front-end Logs

~/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.

1.1.2 User Logs

~/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

1.2 Monitoring Memory Usage

To see a list of processes and how much memory they’re using:


1. Open an SSH session to your account.
2. Enter ‘ps -u username -o rss,command’, where username is your WebFaction account name and
press Enter.
The first column is the resident set size, the amount of memory in use by the process. The second column is the
process’s command along with any arguments used to start it.
Repeat these steps as needed for any additional SSH users you have created.

1.2.1 Example Memory Usage

For example, consider a user, johndoe, monitoring his memory usage.

4 Chapter 1. General Topics


WebFaction Software Documentation, Release

[johndoe@web100 ~]$ ps -u johndoe -o rss,comm


RSS COMMAND
1640 PassengerNginxHelperServer /home/johndoe/webapps/rails/gems/gems/passenger-2.2.8 /home/johndoe/
7676 Passenger spawn server
544 nginx: master process /home/johndoe/webapps/rails/nginx/sbin/nginx -p /home/johndoe/webapps/rai
844 nginx: worker process
896 ps -u johndoe -o rss,command
3564 /home/johndoe/webapps/django/apache2/bin/httpd -f /home/johndoe/webapps/django/apache2/conf/htt
12504 /home/johndoe/webapps/django/apache2/bin/httpd -f /home/johndoe/webapps/django/apache2/conf/htt
2600 /home/johndoe/webapps/django/apache2/bin/httpd -f /home/johndoe/webapps/django/apache2/conf/htt
23740 /usr/local/apache2-mpm-peruser/bin/httpd -k start
23132 /usr/local/apache2-mpm-peruser/bin/httpd -k start
1588 sshd: johndoe@pts/1
1472 -bash

The first row displays the column headers:

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:

1640 PassengerNginxHelperServer /home/johndoe/webapps/rails/gems/gems/passenger-2.2.8 /home/johndoe/w


7676 Passenger spawn server
544 nginx: master process /home/johndoe/webapps/rails/nginx/sbin/nginx -p /home/johndoe/webapps/rail
844 nginx: worker process

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:

896 ps -u johndoe -o rss,command

This is the command that’s checking how much memory is in use.


The next three rows represent a running Django application:

3564 /home/johndoe/webapps/django/apache2/bin/httpd -f /home/johndoe/webapps/django/apache2/conf/htt


12504 /home/johndoe/webapps/django/apache2/bin/httpd -f /home/johndoe/webapps/django/apache2/conf/htt
2600 /home/johndoe/webapps/django/apache2/bin/httpd -f /home/johndoe/webapps/django/apache2/conf/htt

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:

1588 sshd: johndoe@pts/1


1472 -bash

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.

1.2. Monitoring Memory Usage 5


WebFaction Software Documentation, Release

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.

1.3 Setting File Permissions

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.

1.3.1 Reviewing Permissions

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.

1.3.2 Removing Access to Others (Global Access)

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.

1.3.3 Granting Access to Specific Users

To grant specific users read, write, and execute access, enter ‘setfacl -m u:username:permissions
path’ where

6 Chapter 1. General Topics


WebFaction Software Documentation, Release

• username is the username of the user to grant permissions,


• permissions is a combination r, w, and, x for read, write, and execute,
• and path is the path from the current directory to the desired file.
Additionally, if u is prepended with default: or d: and path is a directory, any new files created by that or any
other user within path will default to those permissions.
For example, suppose you would like to grant one of your other SSH accounts access to an application in a subdirectory
of your ~/webapps directory. To grant the other user account access:
1. Log in to an SSH session with your account name (the username you use to log in to the control panel).
2. Enter ‘setfacl -m u:secondary_username:--x $HOME’, where secondary_username is the other
user account name, and press Enter. The command permits the other account to locate directories that it has
access to within your home directory.
3. Enter ‘setfacl -R -m u:secondary_username:--- $HOME/webapps/*’ and press Enter.
This command disallows the other account to access the applications in your ~/webapps directory.
Note: The above command only affects applications that are currently installed. If you create new applica-
tions, you will need to run that command again, or secure the application individually with ‘setfacl -R -m
u:secondary_username:--- $HOME/webapps/name_of_new_app’.
4. Enter ‘setfacl -R -m u:secondary_username:rwx $HOME/webapps/application’, where
application is the name of the application to which the other user is to have access, and press Enter. This
command grants the other user read, write, and execute access to all files and directories within the application.
5. Enter ‘setfacl -R -m d:u:secondary_username:rwx $HOME/webapps/application’ and
press Enter. This command makes all new files in the application directory and its subdirectories have the
same permissions by default.
6. Enter ‘chmod g+s $HOME/webapps/application’ and press Enter. This command makes new files
in the directory owned by the main account’s group.
Now the secondary user can read, write, and execute files within the web app’s directory. The secondary
user can add a convenient symlink to the directory in the secondary user’s home directory; enter ‘ln -s
/home/primary_username/webapps/application ~/application’, where primary_username is the
name of the account used to log in to the control panel, and press Enter.

1.4 Scheduling Tasks with Cron

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.

1.4. Scheduling Tasks with Cron 7


WebFaction Software Documentation, Release

For example, this cron job would record cron is running every 20 minutes to ~/cron.log:

*/20 * * * * echo "cron is running" > $HOME/cron.log 2>&1

Alternatively, you could create a script to send an email.


See Also:
Cron Help Guide from Linux Help
4. Save and close the file.

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

1.5.1 Error: Site not configured

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;

8 Chapter 1. General Topics


WebFaction Software Documentation, Release

• 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

10 Chapter 1. General Topics


CHAPTER

TWO

BAZAAR

Bazaar is an open source distributed version control system.


See Also:
Mercurial

2.1 Installing 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.

2.2 Publishing Bazaar Repositories with Loggerhead

You can create an application to serve the Loggerhead server on the web.

2.2.1 Create an Application for Loggerhead

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.

3. Click the Add new ( ) button. The Add page appears.


4. Enter a name for the application in the Name field.
5. From the App type menu, click to select Custom app (listening on port).

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.

2.2.2 Create a Website Entry for Loggerhead

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.

3. Click the Add new button ( ). The Add page appears.


4. Enter a name for the website entry in the Name field.
5. Click to select a domain from the Subdomains field.

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.

2.2.3 Create a Place to Store Bazaar Repositories

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.

2.2.4 Install Loggerhead’s Dependencies

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.

2.2.5 Download and Setup Loggerhead

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

8. Save and close the file

2.2.6 Create a Cron Job to Automatically Start Loggerhead

1. Open an SSH session into your account.


2. Edit your crontab. Enter crontab -e and press Enter. Your crontab file will open in your text editor.
3. Add this line to your crontab:

10,30,50 * * * * /home/<username>/webapps/<custom_app_name>/loggerhead/serve-branches --port=<nu

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.

2.2. Publishing Bazaar Repositories with Loggerhead 13


WebFaction Software Documentation, Release

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.

3.1 Creating a Custom 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.

3. Click the Add new ( ) button. The Add page appears.


4. In the Name field, enter a name for the application.
5. In the App type menu, click to select Custom app (listening on port).
6. Click the Create button. The View page appears with a confirmation message. The Port field will indicate the
port number assigned to your application.
Now, you can create a website entry which points to your custom application. Requests to that application’s URL will
be proxied by your server to the port number provided. Your application can then listen and respond to requests on
that port.

3.2 Automatically Restarting a Custom Application

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

16 Chapter 3. Custom Applications


CHAPTER

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.

4.1 Getting Started Screencast

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.

4.1.1 Screencast Resources

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

4.2 Getting Started with Django

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.

4.2.1 Create the Django Application

First, create a Django application.


Note: If you requested a Django application during sign up, you’ll find an application called django already
installed for you. If you see django in ~/webapps or on the Apps page (login required), you can skip this portion
of Getting Started with Django.

17
WebFaction Software Documentation, Release

1. Log in to the control panel.


2. Click Domains / websites → Applications. The Apps page appears.

3. Click the Add new ( ) button. The Add page appears.


4. Enter a name for the application in the Name field.
5. Click to select Django (1.1)/mod_wsgi (2.5)/Python (2.5) from the App type menu.
6. Click the Create button. Your application is created and the confirmation page displayed.

4.2.2 Serving Static Media

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.

4.2.3 Serving Admin Media

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

4.2.4 Creating the Database

Next, create a database.


1. Click Databases > Create new database. The Add page appears.
2. Click to select PostgreSql from the Type menu.
3. Enter a name for the database.
Note: The database name must either be your control panel username or begin with your username and an
underscore.
4. Click the Create button. The confirmation page appears.
5. Make a note of the database password provided; it is required to configure Django to connect to the database.

4.2.5 Creating a Website Entry

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.

2. Click the Add new ( ) button. The Add page appears.


3. Enter a name for the website entry in the Name field.
4. Click to select the domains to associate with the website record in the Subdomains list.

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.

4.2.6 Configuring Your Django Installation

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.

4.2. Getting Started with Django 19


WebFaction Software Documentation, Release

3. Enter rm -rf ./myproject and press Enter.


4. If applicable, upload your project directory to ~/webapps/django_application.
Otherwise, enter ‘./lib/python2.5/django/bin/django-admin.py startproject
project_name’.
5. Open ~/webapps/django_application/myproject.wsgi in a text editor.
6. Change os.environ[’DJANGO_SETTINGS_MODULE’] = ’myproject.settings’ to
‘os.environ[’DJANGO_SETTINGS_MODULE’] = ’project_name.settings’’.
7. Save your changes and close the file.
8. Enter ‘mv myproject.wsgi project_name.wsgi’ and press Enter.
9. Open ~/webapps/django_application/apache2/conf/httpd.conf in a text editor.
10. Change ‘WSGIScriptAlias / /home/username/webapps/django_application/myproject.wsgi’
to ‘WSGIScriptAlias / /home/username/webapps/django_application/project_name.wsgi’.
11. Save your changes and close the file.
Be sure to update your Django settings to use your new database and media applications.

Connecting Django to a Database

1. Open an SSH session.


2. Open home_directory/webapps/django_application/myproject/settings.py with a text
editor.
3. Add a tuple to ADMINS containing your name and your email address.
4. Set DATABASE_ENGINE to postgresql_psycopg2.
5. Set DATABASE_NAME and DATABASE_USER to the name you specified in Creating the Database.
6. Set DATABASE_PASSWORD to the database password provided by the control panel.

Configuring Django to Find Static Media and Admin Media

While continuing to edit home_directory/webapps/django_application/myproject/settings.py:


1. Set MEDIA_ROOT to ’home_directory/webapps/static_media_application/’.
2. Set MEDIA_URL to ‘’http://domain/media/’’.
3. Set ADMIN_MEDIA_PREFIX to ‘’http://domain/media/admin/’’.

Configuring Django to Send Email Messages

While continuing to edit home_directory/webapps/django_application/myproject/settings.py:


1. At the end of the file, add EMAIL_HOST = ’smtp.webfaction.com’.
2. At the end of the file, add ‘EMAIL_HOST_USER = ’mailbox_username’’.
3. At the end of the file, add ‘EMAIL_HOST_PASSWORD = ’mailbox_password’’.
4. At the end of the file, add ‘DEFAULT_FROM_EMAIL = ’valid_email_address’’.
5. At the end of the file, add ‘SERVER_EMAIL = ’valid_email_address’’.

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.

Enabling the Django Admin Site

While continuing to edit home_directory/webapps/django_application/myproject/settings.py:


1. Add ’django.contrib.admin’ to INSTALLED_APPS.
2. Save and close the file.
3. Open home_directory/webapps/django_application/myproject/urls.py with a text edi-
tor.
4. Uncomment from django.contrib import admin, admin.autodiscover(),
(r’^admin/doc/’, include(’django.contrib.admindocs.urls’)), and (r’^admin/’,
include(admin.site.urls)),.
5. Save and close the file.

4.2.7 Synchronizing the Database and Restarting Apache

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.

4.3 Restarting a Django Application

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.

4.4 Upgrading your Django Libraries

To upgrade the Django libraries used by your Django application:


1. Open a SSH session to your account.

4.3. Restarting a Django Application 21


WebFaction Software Documentation, Release

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.

4.5 Using the Latest Django Trunk

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

4.6.1 Fixing ImportError: No module named django.module.submodule


Exceptions

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.

4.6.2 Fixing Internal Server Errors

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.

Fixing View 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

Fixing TemplateDoesNotExist for Internal Server Errors

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

Internal Server Error

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.

5.1 Sending Email from Drupal

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

Git is an open source distributed version control tool.


See Also:
Bazaar, Mercurial

6.1 Installing Git

To install Git to your home directory:


1. Open an SSH session to your account.
2. 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.
3. Decompress the archive. Enter ‘tar --extract --bzip2 --file
git-version_number.tar.bz2’ and press Enter. A directory containing the contents of the
archive is created.
4. Switch to the archive directory. Enter ‘cd git-version_number’ and press Enter.
5. Compile Git. Enter make and press Enter.
Note: This step make take several minutes to complete.
6. Install Git. Enter make install and press Enter. git and a few other related tools will be installed to
~/bin.
7. Switch to your home directory. Enter cd and press Enter.
8. Remove the installation directory. Enter ‘rm -r git-version_number’.
9. Remove the installation archive. Enter ‘rm git-version_number.tar.bz2’.
You can now use the command line tool git to work with Git repositories. Enter git help and press Enter for a list
of commands. You can also enter ‘git help command’ to see detailed documentation for a particular command.
To learn more about using Git, check out the official documentation list and the Git Community Book.

6.2 Pushing to Git Repositories over SSH

If Git is installed in your home directory, you can push to repositories stored there.

27
WebFaction Software Documentation, Release

First, you must add Git to your .bashrc file’s PATH:


1. Open an SSH session to your account.
2. Open ~/.bashrc in a text editor.
3. Add export PATH=${PATH}:~/bin to the end of the file.
4. Save and close the file.
To push a repository stored in your home directory:
1. Switch to the path of your local Git repository. For example, at the command prompt, enter ‘cd
path_to_local’, where path_to_local is the path to the local repository, and press Enter.
2. Enter ‘git push ssh://username@username.webfactional.com/~/path_to_remote
master’, where username is your WebFaction username and path_to_remote is the path to the remote
repository relative to your home directory, and press Enter.
Note: If you would like to push a branch other than the master branch, replace master with the name of the
branch you would like to push.
3. When prompted, enter your password and press Enter.
Your changes will then be transmitted and applied to the remote repository.

6.3 Publishing Git Repositories to the Web with Gitweb

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.

6.3.1 Create an Application to Serve gitweb.cgi

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.

3. Click the Add new ( ) button. The Add page appears.


4. Enter a name for the application in the Name field.
5. From the App type menu, click to select Static/CGI/PHP.
6. Click the Create button. The app will be created and the View page appears.

6.3.2 Create a Place to Store Git Repositories

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

6.3.3 Download and Install gitweb.cgi

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’.

6.3.4 Configure Apache to Use gitweb.cgi

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.

6.3. Publishing Git Repositories to the Web with Gitweb 29


WebFaction Software Documentation, Release

6.3.5 Create a Website Entry for the Git Repositories

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.

3. Click the Add new button ( ). The Add page appears.


4. Enter a name for the website entry in the Name field.
5. Click to select a domain from the Subdomains field.

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

Joomla is an open source, PHP-based content management system.

7.1 Sending Email

To configure Joomla to send mail using WebFaction’s SMTP server:


1. Log in to the Joomla Administrator Back-end with an Administrator or Super Administrator account.
2. Click Site → Global Configuration. The Global Configuration page appears on the Site tab.
3. Click the Server tab. The Global Configuration page appears on the Server tab.
4. From the Mailer menu in the Mail Settings group, click to select SMTP Server.
5. In the Mail from field, enter an email address registered in the WebFaction control panel.
6. In the From Name field, enter the name you would like to have displayed to recipients of mail sent from Joomla.
7. Next to SMTP Authentication, click to select Yes.
8. From the SMTP Security menu, click to select SSL.
9. In the SMTP Port field, enter 465.
10. In the SMTP Username field, enter a mailbox name.
11. In the SMTP Password field, enter the mailbox password.
12. In the SMTP Host field, enter smtp.webfaction.com.
13. Click the Save button.

31
WebFaction Software Documentation, Release

32 Chapter 7. Joomla
CHAPTER

EIGHT

MEMCACHED

Memcached is an open source caching system.

8.1 Setting Up Memcached

Memcached is installed server-wide on all of our machines. To start Memcached:


1. Open an SSH session.
2. Enter ‘memcached -d -m memory -s ~/memcached.sock’ where memory is the maximum number
of megabytes of memory you want Memcached to use, and press Enter.
Once your Memcached instance is up and running, you can access it by the path of the socket file
(~/memcached.sock) with the software or library which uses memcached.

8.2 Shutting Down Memcached

To stop your Memcached process:


1. Open an SSH session.
2. Find the PID of your Memcached process. Enter ‘ps -u username -o pid,command | grep
memcached’ and press Enter. A list of processes containing memcached will appear.
3. Find the PID of your Memcached process in the list. The PID is the number in the first column.
4. Enter ‘kill PID’ and press Enter.

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

9.1 Installing Mercurial

It’s easy to install Mercurial. To install Mercurial:


1. Open an SSH session to your account.
2. Enter easy_install Mercurial and press Enter.
Note: You can specify which Python version to use to install Mercurial by entering ‘easy_install-X.Y
Mercurial’ where X.Y is a Python version number. For example, to use Python 2.5, enter
easy_install-2.5 Mercurial.
3. Open ~/.hgrc in a text editor.
4. Add the following lines to ~/.hgrc:

[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.

9.2 Publishing Mercurial Repositories to the Web

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

9.2.1 Create an Application to Serve hgwebdir.cgi

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.

3. Click the Add new ( ) button. The Add page appears.


4. Enter a name for your application in the Name field.
5. From the App type menu, click to select Static/CGI/PHP.
6. Click the Create button. The app will be created and the View page appears.

9.2.2 Create a Place to Store Mercurial Repositories

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.

9.2.3 Download and Install hgwebdir.cgi

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.

9.2.4 Configure hgwebdir.cgi

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

2. Change to the Static/CGI/PHP application’s directory. Enter ‘cd


~/webapps/static_cgi_php_app_name/’ and press Enter.
3. Make hgwebdir.cgi executable. Enter chmod u+x hgwebdir.cgi and press Enter.
4. Open hgwebdir.cgi in a text editor.
5. If you installed Mercurial with a Python or easy_install version other than the default, edit this line:

#!/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.

9.2.5 Configure Apache to Use hgwebdir.cgi

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]

9.2. Publishing Mercurial Repositories to the Web 37


WebFaction Software Documentation, Release

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.

9.2.6 Create a Website Entry for the Mercurial Repositories

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.

3. Click the Add new button ( ). The Add page appears.


4. Enter a name for the website entry in the Name field.
5. Click to select Https.
6. Click to select a domain from the Subdomains field.

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.

9.2.7 Secure and Push to Repositories Served by hgwebdir.cgi

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

Deny from all


</Files>

where <username> is your username and <static_cgi_php_app> is the name of the


Static/CGI/PHP application.
Note: Alternatively, you can use the following lines to prohibit all access except for authenticated users:

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>

1. Save and close the file.


2. Now, create an initial username and password that can push to the repositories. Enter ‘htpasswd -c
.htpasswd username’ and press Enter. A prompt appears for a password.
3. Enter the password for the new user and press Enter. A prompt to confirm the password appears.
4. Enter the password again and press Enter.
5. Open hgweb.config in a text editor.
6. Add the following lines to the file:

[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.

9.2. Publishing Mercurial Repositories to the Web 39


WebFaction Software Documentation, Release

40 Chapter 9. Mercurial
CHAPTER

TEN

MONGODB

MongoDB is an open source document-oriented database.

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.”

10.1 Installing MongoDB

1. Log in to the control panel.


2. Click Domains / websites → Applications. The Apps list appears.

3. Click the Add button ( ). The Add page appears.


4. Enter a name for your MongoDB application in the Name field.
5. Click to select Custom app (listening on port) in the App type menu.
6. Click the Create button. The View page appears with a confirmation message.
7. Make a note of the number in the Port field. This will be needed later.
8. Open an SSH session to your account.
9. Switch to the directory for your MongoDB application. Enter ‘cd ~/webapps/application’ where ap-
plication is the name of your MongoDB application, and press Enter.
10. Download the MongoDB Linux 32-bit package. Enter wget http://downloads.mongodb.org/linux/mongodb-lin
and press Enter. mongodb-linux-i686-1.2.2.tgz will be created in the current directory.
Note: If you prefer, you can use past and development versions of MongoDB instead. Please see the MongoDB
downloads page for details.
11. Extract the files from the archive. Enter tar -xf mongodb-src-r1.2.2.tar.gz and press Enter. A
new directory will be created in the current directory which contains the MongoDB files.
12. Create a database data directory. Enter mkdir data and press Enter.
You may now start your MongoDB database. To run the database itself, enter
/home/{username}/webapps/mongodb/mongodb-linux-i686-1.2.2/bin/mongod --dbpath
/home/{username}/webapps/mongodb/data/ --port {number} where username is your username
and number is the port number provided by the control panel.
See Also:

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.

42 Chapter 10. MongoDB


CHAPTER

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.

11.1 Installing CPAN Modules

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:

CPAN is the world-wide archive of perl resources. It consists of about


100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the CPAN.pm module. If you
want to use CPAN.pm, you have to configure it properly.

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.)

Are you ready for manual configuration? [yes]

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 terminal expects ISO-8859-1 (yes/no)? [yes]


• ‘File to save your history? [/home/username/.cpan/histfile]’
• Number of lines to save? [100]
• Policy on building prerequisites (follow, ask or ignore)? [ask]
• Where is your gzip program? [/bin/gzip]
• Where is your tar program? [/bin/tar]
• Where is your unzip program? [/usr/bin/unzip]
• Where is your make program? [/usr/bin/make]
• Where is your links program? [/usr/bin/links]
• Where is your wget program? [/usr/bin/wget]
• Where is your ncftpget program? []
• Where is your ncftp program? []
• Where is your ftp program? [/usr/kerberos/bin/ftp]
• Where is your gpg program? [/usr/bin/gpg]
• What is your favorite pager program? [/usr/bin/less]
• What is your favorite shell? [/bin/bash]
5. Accept any additional defaults until you encounter the following prompt:

Every Makefile.PL is run by perl in a separate process. Likewise we


run ’make’ and ’make install’ in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.

If you don’t understand this question, just press ENTER.

Parameters for the ’perl Makefile.PL’ command?


Typical frequently used settings:

PREFIX=~/perl non-root users (please see manual for more hints)

Your choice: []

6. Enter ~/lib/perl5 LIB=~/lib/perl5/lib INSTALLMAN1DIR=~/lib/perl5/man1


INSTALLMAN3DIR=~/lib/perl5/man3 and press Enter.
7. Continue to press Enter until you encounter the following prompt:

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

44 Chapter 11. Perl


WebFaction Software Documentation, Release

http: -- that host a CPAN mirror.

(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.

11.1. Installing CPAN Modules 45


WebFaction Software Documentation, Release

46 Chapter 11. Perl


CHAPTER

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.

12.1 Sending Mail from a PHP Script

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";

$from_addr = "Me <my_email_address@mydomain.tld>";


$to = "Team <team@mydomain.tld>";
$subject = "Hello!";
$body = "Dear Team, here is my message text.";

$headers = array ("From" => $from_addr,


"To" => $to,
"Subject" => $subject);
$smtp = Mail::factory("smtp", array (’host’ => "smtp.webfaction.com",
’auth’ => true,
’username’ => "my_mailbox_name",
’password’ => "password1"));

$mail = $smtp->send($to, $headers, $body);


?>

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

A WebFaction user’s replacement to PHP’s mail() function

48 Chapter 12. PHP


CHAPTER

THIRTEEN

PLONE

Plone is an open source content management system built on top of Zope. Zope is an open source web application
server.

13.1 Configuring Plone to Send Email

To configure Plone to send email:


1. Log in to your Plone site as an admin user.
2. Click Site Setup. The Site Setup page appears with the Plone Configuration list.
3. Click Mail. The Mail settings page appears.
4. In the SMTP server field, enter smtp.webfaction.com.
5. In the ESMTP username field, enter a mailbox name as it appears in the WebFaction control panel.
6. In the ESMTP password field, enter the mailbox password.
7. In the Site ‘From’ name field, enter the name you would like to have appear on emails sent by Plone.
8. In the Site ‘From’ address field, enter an email address as it appears in the WebFaction control panel.
9. Click Save. A confirmation message will appear at the top of the page.
Plone will now be able to send email for password resets, notifications, and other uses.

13.2 Creating an Emergency Admin User

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

6. Move the access file to the ~/webapps/plone_app/zinstance/parts/instance directory. Enter


mv access ../../instance and press Enter.
7. Switch to the ~/webapps/plone_app/zinstance/parts/instance/bin directory. Enter cd
../../instance/bin and press Enter.
8. Restart Zope using zopectl. Enter ./zopectl restart and press Enter.
You can now access the ZMI using the username and password created.

13.3 Installing a Python Package

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:

# Add additional eggs here


eggs =

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:

# Add additional eggs here


eggs =
new.package

5. Save and close the file.


6. Complete the installation with the buildout script. Enter ./bin/buildout and press Enter. The package
(or packages) will be downloaded and installed.
See Also:
Plone Developer Manual article Installing a third party product

50 Chapter 13. Plone


CHAPTER

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"’.

14.1 Installing Python Packages

Python packages and modules are typically distributed


• automatically with easy_install,
• as a Python Egg,
• as an archive containing a setup.py file,
• or as a collection of source (.py) files.
You can install Python packages and modules distributed in each of these ways in your WebFaction account.

14.1.1 Installing Packages with easy_install

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

To use easy_install, enter easy_install module_name.


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 module_name’.

14.1.2 Installing Eggs

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’.

14.1.3 Installing Packages with setup.py

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.

14.1.4 Installing Packages Manually

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.

52 Chapter 14. Python


WebFaction Software Documentation, Release

14.2 Troubleshooting

14.2.1 Fixing ImportError Exceptions

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 to PYTHONPATH from the ~/.bash_profile File

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

2. Add ‘export PYTHONPATH="path_to_module:$PYTHONPATH"’ to the end of the file.


3. Save and close the file.
Log out and log in for the changes to take effect.
Note: Changes to ~/.bash_profile only change sys.path for Python programs executed from a shell session.
This approach would not resolve ImportError exceptions associated with web applications and other programs run
with the help of cron.

Adding to PYTHONPATH from the Command Line

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’

Adding to sys.path within a Python Program

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")

Adding to sys.path from httpd.conf

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:

PythonPath "[’/home/username/webapps/djangoapp’, ’/home/username/webapps/djangoapp/lib/python2.5’] +

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.

Adding to sys.path from myproject.wsgi

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:

sys.path = [’/home/username/webapps/djangoapp/myproject’, ’/home/username/webapps/djangoapp/lib/pytho

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.

54 Chapter 14. Python


WebFaction Software Documentation, Release

Moving or Installing Packages Directly to a Path in sys.path

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

56 Chapter 14. Python


CHAPTER

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.

15.1 Installing Ruby on Rails

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.

3. Click the Add new ( ) button. The Add page appears.


4. Enter a name for the application in the Name field.
5. In the App type menu, click to select Rails 2.3.5 (nginx 0.7.64/Passenger 2.2.8/Ruby Enterprise Edition
1.8.7).
6. Click the Create button. The application is created and the application’s View page appears with a confirmation
message.

57
WebFaction Software Documentation, Release

15.2 Installing Gems

To install a Ruby Gem in your Rails application:


1. Open an SSH session to your account.
2. Enter ‘cd ~/webapps/rails_app’, where rails_app is the name of your Ruby on Rails application, and
press Enter.
3. Enter ‘export GEM_HOME=$PWD/gems’ and press Enter.
4. Enter ‘export PATH=$PWD/bin:$PATH’ and press Enter.
5. Enter ‘gem install gem_name’, where gem_name is the name of the Ruby Gem you want to install, and
press Enter.
Note: If you do not want to install the Rdoc or RI documentation, use this version of the command: ‘gem
install --no-rdoc --no-ri gem_name’.
The gem and any of its specified dependencies will be downloaded and installed automatically.

15.3 Deploying a Ruby on Rails Application

To start using your own application with a Passenger-based Rails application:


1. Upload your application to your Rails application directory. For example, if you have an application, myapp,
upload it to ~/webapps/rails_app/myapp where rails_app is the name of your Rails application as it
appears in the WebFaction control panel.
2. Open an SSH session to your account.
3. Switch to the Rails application directory. Enter ‘cd ~/webapps/rails_app’ where rails_app is the name
of your Rails application, and press Enter.
4. Open ./nginx/conf/nginx.conf in a text editor.
5. Replace hello_world in the line containing ‘root /home/username/webapps/rails_app/hello_world/public’
with the name of your Rails app’s directory. In the earlier example, the line would contain ‘root
/home/username/webapps/rails_app/myapp/public’.
Note: You may now delete the provided hello_world directory.
6. Reboot your Rails application. Enter ./bin/restart and press Enter.

15.4 Using a Database with a Ruby on Rails Application

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.

58 Chapter 15. Ruby on Rails


WebFaction Software Documentation, Release

(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.

15.4. Using a Database with a Ruby on Rails Application 59


WebFaction Software Documentation, Release

60 Chapter 15. Ruby on Rails


CHAPTER

SIXTEEN

REDMINE

Redmine is an open source project management application.

16.1 Installing 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.

16.2 Configuring Redmine to Send Email

To configure Redmine to send email:


1. Open an SSH session.
2. 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.
3. Switch to the directory where the Redmine software itself is located (for example, redmine-0.9.3). Enter
‘cd directory’ and press Enter.

62 Chapter 16. Redmine


WebFaction Software Documentation, Release

4. Create a copy of the email configuration file. Enter cp config/email.yml.example


config/email.yml and press Enter.
5. Open config/email.yml in a text editor.
6. In the production section of the file (you may need to scroll past a very long comment block), make the following
changes:
• replace address: smtp.example.net with address: smtp.webfaction.com,
• replace domain: example.net with ‘domain: email_domain’, where email_domain is the domain
of the email address you will be sending from,
• replace user_name: “redmine@example.net” with ‘user_name: mailbox’ where mailbox is the
name of a mailbox as it appears in the WebFaction control panel,
• replace password: “redmine” with ‘password: pass’, where pass is the password for the mailbox.
7. Save and close the file.
8. Restart the Passenger application. Enter ~/webapps/{application}/bin/restart where application
is the name of the Redmine application as it appears in the control panel and press Enter.

16.2. Configuring Redmine to Send Email 63


WebFaction Software Documentation, Release

64 Chapter 16. Redmine


CHAPTER

SEVENTEEN

STATIC FILES, CGI SCRIPTS, AND PHP


PAGES

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.

17.1.1 Serving Static Media

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

17.2.1 Hiding Configuration Files

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>

17.2.2 Password Protecting a Directory with a Static/CGI/PHP App

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

# Hide files starting with a dot (.htaccess and .htpasswd in particular)


<Files .*>
order allow,deny
deny from all
</Files>

6. Save and close the file.


7. To create the first user with access to the directory, enter ‘htpasswd -c .htpasswd username’ and
press Enter. A New password prompt appears.
8. Enter the password for the new user and press Enter. A Re-type new password prompt appears.
9. Re-enter the password for the new user and press Enter.
10. To create additional users with access to the directory, enter ‘htpasswd .htpasswd username’ and press
Enter, then follow the password prompts for the new user.
Note: If you would like to password protect a subdirectory, rather than the entire application, simply move
.htaccess to the subdirectory.
Now, when you access the URL associated with the app’s protected directory, your browser will prompt you for a
username and password.

66 Chapter 17. Static Files, CGI Scripts, and PHP Pages


WebFaction Software Documentation, Release

17.2.3 Redirect a Domain with a Static/CGI/PHP App

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]

7. Save the file.


Now, all subsequent requests to a URL at origin_domain will be rewritten to corresponding URLs at destina-
tion_domain.

17.2.4 Setting an Upload Limit

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.

web120 or Greater or dweb62 or Greater

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

where X is the maximum number of megabytes you want to allow to be uploaded.


5. Save and close the file.

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.

17.2.5 Setting PHP’s DOCUMENT_ROOT

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.

web120 or Greater or dweb62 or Greater

To set DOCUMENT_ROOT on web120 or greater and dweb62 or greater:


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 the application, and press Enter.
3. Open a new file, set_document_root.php, in a text editor.
4. Insert these lines:

<?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.

68 Chapter 17. Static Files, CGI Scripts, and PHP Pages


WebFaction Software Documentation, Release

Other Servers

To set DOCUMENT_ROOT on all other servers:


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 the application, and press Enter.
3. Open a new file, set_document_root.php, in a text editor.
4. Insert these lines:

<?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>

8. Save and close the file.

17.3 Troubleshooting

17.3.1 Uploaded Files Owned by Apache

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

70 Chapter 17. Static Files, CGI Scripts, and PHP Pages


CHAPTER

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.

18.1 Send Email Notifications with a Post-Commit Hook

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)

repository, revision = sys.argv[1:]

# Get the diff from svnlook


cmd = "svnlook diff %(repository)s -r %(revision)s" % locals()

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"
)

msg = msg % locals()

server.sendmail(from_email, to_email, msg)


server.quit()

2. Open an SSH session.


3. Switch to the ~/webapps/svn_app/hooks directory.
4. Enter chmod ogu+x post-commit and press Enter.
Now, every time a new change is committed to the repository, an email will be sent with a diff of the changes committed
to the list of recipients.

18.2 Reusing Usernames and Passwords Between Subversion and


Trac

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’.

72 Chapter 18. Subversion


CHAPTER

NINETEEN

WORDPRESS

WordPress is a blog publishing application.

19.1 Getting Started Screencast

WebFaction has prepared a screencast to get you up and running with WordPress quickly.
You can watch it on YouTube.

19.1.1 Screencast Resources

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

19.2 Sending Email from WordPress

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

7. Click Install Now.


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.
3. Beneath Configure SMTP, click Activate.
4. Click Settings → SMTP. The Configure SMTP Settings page appears.
5. In the SMTP host field, enter smtp.webfaction.com.
6. Enter 465 in the SMTP port field.
7. In the Secure connection prefix menu, click to select ssl.
8. Click to select Use SMTPAuth.
9. In the SMTP username field, enter your WebFaction mailbox name.
10. In the SMTP password field, enter your WebFaction mailbox password.
11. In the Sender name field, enter a display name for email messages sent by WordPress.
12. Click Save Changes.
WordPress will now be able to send email messages for notifications and other uses.

74 Chapter 19. WordPress


CHAPTER

TWENTY

INDICES AND TABLES

• Index
• Search Page

75

Anda mungkin juga menyukai