Changes between Version 13 and Version 14 of faq/setup-development-workstation


Ignore:
Timestamp:
Jun 3, 2012, 2:26:40 PM (9 years ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • faq/setup-development-workstation

    v13 v14  
    1010== Installing and configuring critical helper packages ==
    1111
    12 Being able to send and receive email is often part of the web application development process.
     12Being 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).
     13
     14For starters, follow the [wiki:email_setup_postfix_debian instructions for configuring postfix to relay email for you].
     15
     16Once you have a working postfix installation, you may want to further configure it to relay ''all'' email to your email address:
    1317
    1418{{{
    15 0 fidel:~# aptitude install mailx esmtp-run
     190 fidel:~# aptitude install postfix-pcre
    1620}}}
    1721
    18 You will then want to edit the /etc/esmtprc file, modifying the following lines:
     22Then, create the file /etc/postfix/recipient_canonical:
    1923
    2024{{{
    21 # Config file for ESMTP sendmail
    22 
    23 # The SMTP host and service (port)
    24 hostname=chavez.mayfirst.org:587
    25 
    26 # The user name
    27 username=
    28 
    29 # The password
    30 password=
    31 
    32 #qualifydomain=@mayfirst.org
    33 #force sender=your-username@mayfirst.org
    34 #force reverse_path=your-username@mayfirst.org
    35 
    36 # Whether to use Starttls
    37 starttls=enabled
     25/.*/ you@example.org
    3826}}}
    3927
    40 FIXME: I can't properly send mail with this configuration, I get the following error:
     28Replace {{{you@example.org}}} with your actual email address.
     29
     30Then edit the /etc/postf file, adding the following lines:
    4131
    4232{{{
    43 Invalid peer certificate (error 20)
    44 0 (null)
    45 jamie@mayfirst.org: 0 (null)
    46 Can't send mail: sendmail process failed with error code 70
     33recipient_canonical_classes = envelope_recipient
     34recipient_canonical_maps = pcre:/etc/postfix/recipient_canonical
    4735}}}
    4836
    49 This could be related to a known [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=310968 bug in esmtp].
     37Lastly, restart postfix:
    5038
    51 == Installing PHP, Apache, and MySQL ==
     39{{{
     40/etc/init.d/postfix reload
     41}}}
     42
     43== Installing PHP, Apache, MySQL, and sudo ==
    5244
    5345Install the required packages with:
    5446
    5547{{{
    56 aptitude install mysql-server php5-cgi php5-cli libapache2-mod-php5 apache2-mpm-prefork php5-mysql
     48aptitude install mysql-server php5-cgi php5-cli libapache2-mod-php5 apache2-mpm-prefork php5-mysql sudo
     49}}}
     50
     51You should be prompted to create a password for the MySQL root user. You can generate a random password with the command:
     52
     53{{{
     54pwgen
     55}}}
     56
     57If you receive an command not found error, install pwgen:
     58
     59{{{
     60apt-get install pwgen
     61}}}
     62
     63Once you have your MySQL root user setup with a good password, record that password in /root/.my.cnf:
     64
     65{{{
     66[client]
     67user=root
     68password=password-you-created-above
     69}}}
     70
     71Fix permissions on the file:
     72
     73{{{
     74chmod 600 /root/.my.cnf
     75}}}
     76
     77Now, create a non-privileged user that you will use for doing your normal development work:
     78
     79{{{
     80adduser jamie
     81}}}
     82
     83Add that users to the sudo group:
     84
     85{{{
     86adduser jamie sudo
    5787}}}
    5888
    5989== Configuring the environment ==
    6090
    61 The goal of the configuration is to make it as easy as possible to setup a new development environment for a new project.
     91The rest of the steps should done as the non-privileged user. We will use sudo when you need root access.
    6292
    6393Each 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.
     
    71101}}}
    72102
    73 Apache can be configured so that it dynamically sets the document root based on the domain name.
    74 
    75 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).
    76 
    77 {{{
    78 <Directory /home/your-username/projects>
    79 AllowOverride All
    80 </Directory>
    81 VirtualScriptAlias /home/your-username/projects/%1/cgi-bin/
    82 VirtualDocumentRoot /home/your-username/projects/%1/web/
    83 }}}
    84 
    85 Next enable the vhost_alias module and the site configuration file you just created with:
    86 
    87 {{{
    88 a2enmod vhost_alias
    89 a2enmod rewrite
    90 a2ensite virtual-document-roots
    91 }}}
    92 
    93 Reload Apache so these changes take effect:
    94 
    95 {{{
    96 /etc/init.d/apache2 reload
    97 }}}
    98 
    99 NOTE: If you are developing a Drupal project, you will need to edit your .htaccess file. There's a line that says the following:
    100 
    101 {{{
    102 # If your site is running in a VirtualDocumentRoot at http://example.com/,
    103 # uncomment the following line:
    104 RewriteBase /
    105 }}}
    106 
    107 You will want to uncomment the RewriteBase directive as shown above.
    108 
    109103== Steps to create a new project ==
    110104
    111 With your environment setup, you can easily start a new project by following these steps:
    112 
    113105 * 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).
    114  * Create the mysql database with:
     106 * Choose a new random password:
    115107{{{
    116 mysql -u root -p -e "CREATE DATABASE mfpl; GRANT ALL ON mfpl.* to 'mfpl'@'localhost' identified by 'mfpl';"
     108pwgen -s 15 1
    117109}}}
    118  * 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:
     110 * 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.
     111{{{
     112sudo mysql -e "CREATE DATABASE mfpl; GRANT ALL ON mfpl.* to 'mfpl'@'localhost' identified by 'your-random-password-goes-here';"
     113}}}
     114 * 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:
    119115{{{
    120116127.0.0.1       localhost
    121 127.0.1.1       fidel.sunsetpark.mayfirst.org   fidel mfpl.fidel
     117127.0.1.1       fidel.sunsetpark.mayfirst.org   fidel
     118# linux environment installed directly on your workstation:
     119127.0.1.2                               mfpl.fidel
     120# OR linux environment installed on a virtual machine:
     121192.168.1.2             mfpl.fidel
    122122}}}
    123  * Change into your proects directory:
     123 * Change into your projects directory:
    124124{{{
    125125cd ~/projects
    126126}}}
    127  * Checkout your src files via svn
     127 * Create a project directory:
    128128{{{
    129  svn co svn+ssh://svn.mayfirst.org/trunk/mfpl
     129mkdir mfpl
    130130}}}
    131  * OR create your project folders with:
     131 * Create a web directory:
    132132{{{
    133 mkdir ~/projects/mfpl
    134 mkdir ~/projects/mfpl/web
    135 mkdir ~/projects/mfpl/cgi-bin
     133mkdir mfpl/web
     134}}}
     135 * Add an apache configuration by creating an apache sites file:
     136{{{
     137sudo nano /etc/apache2/sites-available/mfpl.fidel
     138}}}
     139 * With the contents (replace "jamie" with your actual username):
     140{{{
     141<VirtualHost *:80>
     142        ServerName mfpl.fidel
     143        DocumentRoot /home/jamie/projects/mfpl/web
     144</VirtualHost>
     145}}}
     146 * Enable the site:
     147{{{
     148sudo a2ensite mfpl.fidel
     149}}}
     150 * Reload apache:
     151{{{
     152sudo /etc/init.d/apache2 reload
    136153}}}
    137154
    138 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/
     155Done! Now you should be ready to download or create your web files in your web directory and access them via: http://mfpl.fidel/
    139156
    140157== Keeping files in sync ==
     
    147164#!/bin/bash
    148165echo "Synchronizing database."
    149 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>
     166ssh <user>@<server> "mysqldump -u <remote-db-user> -p<remote-db-pass> <remote-db-name>" | sudo mysql <local-db-name>
    150167
    151168echo "Synchronizing files."