wiki:faq/setup-development-workstation

Version 12 (modified by Jamie McClelland, 12 years ago) (diff)

--

Setting up a development workstation

As our web sites become more complicated and more critical to our work, having a development version of your web site running in a non-public place becomes more and more important. With a development workstation, you can make and test your changes privately to ensure that they work before copying your changes to the live site. With Debian Linux, you can setup a development workstation that uses the same software used on the May First/People Link servers.

Below is a tutorial for installing Debian Linux on a computer for the purposes of developing Web-based applications that use Apache, PHP, and MySQL.

Installing Debian

Installing and configuring critical helper packages

Being able to send and receive email is often part of the web application development process.

0 fidel:~# aptitude install mailx esmtp-run

You will then want to edit the /etc/esmtprc file, modifying the following lines:

# Config file for ESMTP sendmail

# The SMTP host and service (port)
hostname=chavez.mayfirst.org:587

# The user name
username=

# The password
password=

#qualifydomain=@mayfirst.org
#force sender=your-username@mayfirst.org
#force reverse_path=your-username@mayfirst.org

# Whether to use Starttls
starttls=enabled

FIXME: I can't properly send mail with this configuration, I get the following error:

Invalid peer certificate (error 20)
0 (null)
jamie@mayfirst.org: 0 (null)
Can't send mail: sendmail process failed with error code 70

This could be related to a known bug in esmtp.

Installing PHP, Apache, and MySQL

Install the required packages with:

aptitude install mysql-server php5-cgi php5-cli libapache2-mod-php5 apache2-mpm-prefork php5-mysql

Configuring the environment

The goal of the configuration is to make it as easy as possible to setup a new development environment for a new project.

Each new project will have a unique, non-public domain name based on the name of the workstation. Each project will have a corresponding directory in your home directory where you can place php and other files to be served by apache.

In this example, let's assume the workstation is named "fidel." So - a new project called mfpl would have the development domain name: mfpl.fidel (below we will edit the /etc/hosts file so that this non-public domain name will resolve to the development workstation).

Create a projects directory in your home directory:

mkdir ~/projects

Apache can be configured so that it dynamically sets the document root based on the domain name.

To enable that feature, create a new file called virtual-document-roots in the /etc/apache2/sites-available directory with the following contents (replace your-username with your actual username).

<Directory /home/your-username/projects>
AllowOverride All
</Directory>
VirtualScriptAlias /home/your-username/projects/%1/cgi-bin/
VirtualDocumentRoot /home/your-username/projects/%1/web/

Next enable the vhost_alias module and the site configuration file you just created with:

a2enmod vhost_alias
a2enmod rewrite
a2ensite virtual-document-roots

Reload Apache so these changes take effect:

/etc/init.d/apache2 reload

NOTE: If you are developing a Drupal project, you will need to edit your .htaccess file. There's a line that says the following:

# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /

You will want to uncomment the RewriteBase directive as shown above.

Steps to create a new project

With your environment setup, you can easily start a new project by following these steps:

  • Choose a name for the project. In this example, we'll choose the name mfpl (and remember - in our example the computer name is fidel).
  • Create the mysql database with:
    mysql -u root -p -e "CREATE DATABASE mfpl; GRANT ALL ON mfpl.* to 'mfpl'@'localhost' identified by 'mfpl';"
    
  • Add a new domain to your /etc/hosts file. Add it to the line that starts with 127.0.1.1 (you can safely create the line if it doesn't exist). For example:
    127.0.0.1       localhost 
    127.0.1.1       fidel.sunsetpark.mayfirst.org   fidel mfpl.fidel
    
  • Change into your proects directory:
    cd ~/projects
    
  • Checkout your src files via svn
     svn co svn+ssh://svn.mayfirst.org/trunk/mfpl
    
  • OR create your project folders with:
    mkdir ~/projects/mfpl
    mkdir ~/projects/mfpl/web
    mkdir ~/projects/mfpl/cgi-bin
    

Now you are ready to begin. You can start placing files in your project's web directory and access your project at the URL: http://mfpl.fidel/

Keeping files in sync

If you are working on a database driven project (like Drupal) it can be difficult to keep your database and (in the case of Drupal) your files directory in sync.

A bash script like the following one can help - by providing an easy way to synchronize your development platform with the live site:

#!/bin/bash
echo "Synchronizing database."
ssh <user>@<server> "mysqldump -u <remote-db-user> -p<remote-db-pass> <remote-db-name>" | mysql -u <local-db-user> -p<local-db-pass> <local-db-name>

echo "Synchronizing files."
rsync -av --exclude '*/settings.php' --exclude '.svn*' --exclude '*/.svn*' --exclude 'sites*' <user>@<server>:<remote-path-to-files-directory> <local-path-to-files-director>