Skip to content

Local Development of Warmshowers.org

Cyril Wendl edited this page Oct 2, 2016 · 1 revision

This wiki page is slowly being superseded by https://github.com/warmshowers/warmshowers_vagrant This page is now just for archival purposes.


The goal is to create a copy of the warmshowers.org website on a PC running Linux. This procedure is specifically for Ubuntu 11.04, but it should work for nearly all Debian/Ubuntu variants, and the concepts are the same for All Linux and Windows/Mac installations.

Summary of Steps to Perform

  • Install a LAMP package
    • install Apache server
    • install MySQL database
    • install PHP
  • configure an Apache VirtualHost
  • create a database
  • download/install the warmshowers.org Drupal code
  • import the sanitized warmshowers.org database
  • download and install the warmshowers.org user-created files
  • modify the settings.php file
  • create Warmshowers.dev Administrator account
  • enable Google Maps
  • enable email (and prevent it accidentally going out)
  • check the status report

install LAMP

The first three steps can be covered by installing LAMP. LAMP (Linux Apache MySQL PHP) is a software bundle that provides the main components of a web server.

First tasksel must be installed (tasksel is a tool that installs multiple related packages onto your system):
sudo apt-get install tasksel

Now install LAMP:
sudo tasksel install lamp-server

To get the proper redirection of webpages the rewrite function in Apache2 must be enabled:
sudo a2enmod rewrite

Create a username and password for MySQL.
First login to MySQL:
mysql -u root -p
At the mysql> prompt create username (root) and password (xxxxxxxx):
set password for 'root'@'localhost' = password('xxxxxxxx');

Reload and Restart the server:
sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 restart

Verify that the server is alive by typing into your browser:
http://localhost
You should get something like It Works!

configure an Apache VirtualHost

A VirtualHost is used to configure the web server to respond to queries made to our local copy of the warmshowers.org website. We recommend that you use the name warmshowers.dev (http://warmshowers.dev) for the local copy, but it could be hostname that is not a real internet hostname.

Copy the default configuration file and rename it to warmshowers, leaving it in the same directory:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/warmshowers

Use a text editor (like gedit or vi or nano) to open the file warmshowers:
sudo vi /etc/apache2/sites-available/warmshowers

Append a block of code similar to the one below to this file. Note that it defines the top-level Drupal directory to be /home/warmshowers.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName warmshowers.dev
DocumentRoot /home/warmshowers
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Copy the index.html file in this directory to /home/warmshowers:
sudo mkdir /home/warmshowers
sudo cp /etc/apache2/sites-available/index.html /home/warmshowers

Note that index.html has the code that displayed the message It Works! when http://warmshowers.dev was typed into the browswer. With a plain text editor, edit the index.html file just copied:
sudo vi /home/warmshowers/index.html

Change the text that is displayed to something like Warmshowers.dev is Alive (this file will be used to test our configuration changes shortly).

In the file /etc/hosts a single line of code needs to be added:
127.0.0.1 localhost

Disable the old configuration file (/etc/apache2/sites-available/default):
sudo a2dissite default

Reload the server:
sudo /etc/init.d/apache2 reload

Enable the new configuration file (/etc/apache2/sites-available/warmshowers):
sudo a2ensite warmshowers

Restart the server:
sudo /etc/init.d/apache2 restart

Test the two virtual hosts to verify they are functional by typing two commands into the browser:
http://localhost
The correct response displays the phrase It Works!
http://warmshowers.dev
The phrase Warmshowers.dev is Alive should appear in the browser

In some cases, you will see an error about unrecognized virtual host and a new IP address 127.0.1.1 or similar. If so, add that address in the file /etc/hosts 127.0.1.1 warmshowers.dev

The virtual host warmshowers.dev works only after that.

import warmshowers.org Drupal code

The drupal git repository is on Github (at https://github.com/rfay/Warmshowers.org). Use git to get them.

Preferably use git to get the codebase. Alternately, after logging into Github go to the Warmshowers.org page linked to above. Click on the Downloads button on this page. In the popup that appears select the .tar.gz format for the file. Then choose to open the file in Archive Manager. (Alternately, you may use git to check out the code; that's how the actual code will be managed in the long term if you end up contributing code changes to the site or update modules, etc.)

Use Archive Manager (or just the tar command on the command line) to decompress, unpack, and then move the archived warmshowers.org files into the /home/warmshowers directory.

Rename the file .htaccess.d6_standard to .htaccess. This is necessary to get Clean URLs working on the site.
sudo mv .htaccess.d6_standard .htaccess

Remove the index.html file that was added to /home/warmshowers earlier to test our configuration:
sudo rm /home/warmshowers/index.html

create a database

You can either use the web-based phpMyAdmin GUI to create a database or do it from the command line. From the command line: echo "create database warmshowersDB;" | mysql -uroot -p

or follow these instructions for the friendly phpMyAdmin tool:

The GUI phpMyAdmin will create a MySQL database. To install it:
sudo apt-get install phpmyadmin

To enable phpMyAdmin a line of code should be added to the file apache2.conf. Use a text editor like gedit or vi to edit this file:
sudo vi /etc/apache2/apache2.conf
Add the following line to the bottom of this file:
Include /etc/phpmyadmin/apache.conf

Type the following address into the browser to bring up phpMyAdmin:
http://warmshowers.dev/phpMyAdmin
You will be prompted for a username and password. Input the username (root) and password (xxxxxxxx) you made earlier.

On the page that appears there is a block labeled MySQL Localhost where a database can be created. Under the label Create new database type in the database name (use warmshowersDB for this example) and click on the Create button.

import the sanitized warmshowers.org database

A sanitized database dump for warmshowers.org is available to those who need it. The passwords have been changed, etc. This is still a sensitive file and must be treated with respect and not copied beyond your local machine. Load the database dump into the warmshowersDB MySQL database you created above.

After logging into Dropbox select the Files tab. Then click on the warmshowers folder that appears in the list. Right-click on the file ws_sanitized_db_20110705.sql.gz and choose Download File from the menu that appears. In the next menu choose to Save this file to a destination of your choice (e.g., /home/Downloads).

The database file needs to be decompressed:
gzip -d ws_sanitized_db_20110705.sql.gz

Import the decompressed file into the MySQL database (named warmshowersDB) created earlier:
mysql -p -u root warmshowersDB < ws_sanitized_db_20110705.sql

import warmshowers.org user-created files

The data files for warmshowers.org were archived on Dropbox. Put a copy of these files into the directory /home/warmshowers/files.

After logging into Dropbox maneuver to the warmshowers folder as before. Right-click on the file ws_files.20110705.tgz and choose Download File from the menu that appears. In the next menu choose to open the file in Archive Manager.

Use Archive Manager (or using tar) to decompress, unpack, and then move the archived files into the /home/warmshowers/files directory.

The permissions of the /files directory (and its contents) needs to be changed because the Apache server cannot write to them as is. Change the group to www-data (www-data is the group name of the server) and change the group and user category permissions to read + write:
sudo chgrp -R <your_username>:www-data /home/warmshowers/files
sudo chmod -R ug+rw /home/warmshowers/files
Note: in the chown command substitute your username for "your_username"

modify the settings.php file

After the archived warmshowers.org Drupal files user-created files, and database are loaded, the file settings.php must be created and configured to get the local copy functional.
To create the file, copy /sites/default/default.settings.php and save it as settings.php:
sudo cp /home/warmshowers/sites/default/default.settings.php /home/warmshowers/sites/default/settings.php

The variable $db_url in the settings.php file needs to be changed. Using a plain-text editor like vi open the file:
sudo vi /home/warmshowers/sites/default/settings.php
Find the following line in this file: $db_url = 'mysql://username:password@localhost/databasename';
Substitute the username/password for acessing MySQL plus the name of the database. The line should become:
$db_url = 'mysqli://root:xxxxxxxx@localhost/warmshowersDB';

Typing http://warmshowers.dev into the browser should bring up the familiar warmshowers.org home page.

take over the Warmshowers.dev Administrator account

The passwords for the users of warmshowers.org were changed when the database was archived. To gain access in the administrator role (user id 1) the database for warmshowers.dev must be modified.

Login to MySQL:
mysql -u root -h localhost -p
Enter your password (xxxxxxxx) when prompted

At the mysql prompt type in the name of the database:
use warmshowersDB

Assign the administrator account a Username (for this example use "admin") and Password (use "yyyyyyyy"):
update users set name='admin', pass=md5('yyyyyyyy') where uid=1;

Test the new username/password combination by trying to login to the warmshowers.dev website.
Access the website home page by typing http://warmshowers.dev into the browser. In the User login block enter the Username of admin and the Password of yyyyyyyy. In the page that appears the first sentence in the Login status block should read Logged in as admin.

To assist in debugging efforts later turn off CSS and Javascript aggregation.
While logged into warmshowers.dev go to the Performance page (/admin/settings/performance). In the Bandwidth Optimization block disable Optimize CSS files and Optimize JavaScript files. Click on the Save configuration button to finish.

enable Google Maps

A new Google Maps API key is required to make the map on _warmshowers.dev functional.

Login to Google and then go to this page: http://code.google.com/apis/maps/signup.html
Input the appropriate URL (http://warmshowers.dev) into the required URL field. Then click on the Generate API key button. Copy the new key when it appears.

This new key must be input into the Google Maps API key field on the User Location Settings page (/admin/settings/user_location). Click on the Save Configuration button to complete the process.

Test the functionality of the website map by going to the map page (/map) and using some of the control features.

enable email

Email must be active to verify that messages are sent from the website at the appropriate time. Mail should be configured so that messages never actually leave your computer regardless of who they are addressed to.

A mail server needs to be installed and Postfix was chosen to meet this need.
sudo apt-get install postfix
When prompted for the general type of mail configuration select the last option listed Local only.

Mailutils is a general purpose package for processing email that may be installed:
sudo apt-get install mailutils

Next configure email in Drupal. After logging into the local copy of the warmshowers.org website (http://warmshowers.dev) go to the SMTP Authentication Support page (/admin/settings/smtp) and use the following settings:

  • Turn the module “On”
  • SMTP server (and backup server) = localhost
  • SMTP port = 25
  • Use encrypted protocol = No
  • SMTP Authentication block: leave Username and Password blank
  • Email from address = wsl @warmshowers.dev
  • Email from name = Warmshowers.dev

Enable the "Reroute Email" module at /admin/build/modules.

Configure email so that all the messages sent by the website go to my local email account. Go to the Reroute Email page (/admin/settings/reroute_email) and in the Email address field enter your local email address (kevin@localhost)
Click on the Save configuration button when done.

Email functionality can be tested by returning to the SMTP Authentication page and sending a message. In the Send test email box enter your local email address (kevin@localhost) and then click on the Save configuration button.
Your mailbox can be checked by typing the following command:
mail
In the information that appears verify that there is a new message with the subject Drupal test e-mail that was sent from the website (Warmshowers.dev).

status report

As a final configuration check go to the Status Report page (/admin/reports/status). In the Report all of the fields listed should appear in green with the following exceptions:

  • Cron maintenance tasks: this field should specify when Cron was last run
  • Drupal core update status: No update data available
  • IP to Country/Additional data: Not available
  • IP to Country/Database data: Out of date
  • Performance logging APC (memory size): Disabled
  • Upload progress: Not enabled