[[TranslatedPages]] [[PageOutline]] = 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. View this other tutorial if you want to set up your [wiki:setup_development_workstation_mac development workstation using OS X on a Macintosh]. If you want to setup your development environment in a virtual machine, see [wiki:setup_virtual_machine]. == Installing Debian == == Installing and configuring critical helper packages == Being able to send and receive email is often part of the web application development process. However, you don't want emails that are sent to be delivered to their actual recipients - but instead, delivered to you (this allows you to safely test web applications that send mail without the risk of accidentally sending a test email to thousands of people). For starters, follow the [wiki:email_setup_postfix_debian instructions for configuring postfix to relay email for you]. Once you have a working postfix installation, you may want to further configure it to relay ''all'' email to your email address: {{{ 0 fidel:~# aptitude install postfix-pcre }}} Then, create the file /etc/postfix/recipient_canonical: {{{ /.*/ you@example.org }}} Replace {{{you@example.org}}} with your actual email address. Then edit the /etc/postf file, adding the following lines: {{{ recipient_canonical_classes = envelope_recipient recipient_canonical_maps = pcre:/etc/postfix/recipient_canonical }}} Lastly, restart postfix: {{{ /etc/init.d/postfix reload }}} == Installing PHP, Apache, MySQL, and sudo == Install the required packages with: {{{ aptitude install mysql-server php5-cgi php5-cli libapache2-mod-php5 apache2-mpm-prefork php5-mysql sudo }}} You should be prompted to create a password for the MySQL root user. You can generate a random password with the command: {{{ pwgen }}} If you receive an command not found error, install pwgen: {{{ apt-get install pwgen }}} Once you have your MySQL root user setup with a good password, record that password in /root/.my.cnf: {{{ [client] user=root password=password-you-created-above }}} Fix permissions on the file: {{{ chmod 600 /root/.my.cnf }}} Now, create a non-privileged user that you will use for doing your normal development work: {{{ adduser jamie }}} Add that users to the sudo group: {{{ adduser jamie sudo }}} == Configuring the environment == The rest of the steps should done as the non-privileged user. We will use sudo when you need root access. 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 }}} == Steps to create a new project == * 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). * Choose a new random password: {{{ pwgen -s 15 1 }}} * Create the mysql database. We're using sudo, which means we execute with root privileges. Since we have our root password stored in /root/.my.cnf, we don't have to specify a MySQL username and password. {{{ sudo mysql -e "CREATE DATABASE mfpl; GRANT ALL ON mfpl.* to 'mfpl'@'localhost' identified by 'your-random-password-goes-here';" }}} * Add a new domain to your /etc/hosts file. This step must be taken on the computer that runs your web browser. In other words, if you have Linux directly installed on your laptop/workstation, then add this file to your /etc/hosts file and use the IP address 127.0.1.2 (or any IP address that starts with 127). On the other hand, if your development environment is a virtual server on your workstation, then be sure to edit the /etc/hosts file on your host operating system, not on the virtual server. Also, instead of using 127.0.1.2, use the IP address assigned to your virtaul machine. For example: {{{ 127.0.0.1 localhost 127.0.1.1 fidel.sunsetpark.mayfirst.org fidel # linux environment installed directly on your workstation: 127.0.1.2 mfpl.fidel # OR linux environment installed on a virtual machine: 192.168.1.2 mfpl.fidel }}} * Change into your projects directory: {{{ cd ~/projects }}} * Create a project directory: {{{ mkdir mfpl }}} * Create a web directory: {{{ mkdir mfpl/web }}} * Add an apache configuration by creating an apache sites file: {{{ sudo nano /etc/apache2/sites-available/mfpl.fidel }}} * With the contents (replace "jamie" with your actual username): {{{ ServerName mfpl.fidel DocumentRoot /home/jamie/projects/mfpl/web Order allow,deny Allow from all # New directive needed in Apache 2.4.3: Require all granted }}} * Enable the site: {{{ sudo a2ensite mfpl.fidel }}} * Reload apache: {{{ sudo /etc/init.d/apache2 reload }}} Done! Now you should be ready to download or create your web files in your web directory and access them via: 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 @ "mysqldump -u -p " | sudo mysql echo "Synchronizing files." rsync -av --exclude '*/settings.php' --exclude '.svn*' --exclude '*/.svn*' --exclude 'sites*' @: }}}