Changes between Initial Version and Version 1 of setup_development_workstation_mac


Ignore:
Timestamp:
May 11, 2011, 2:27:01 PM (9 years ago)
Author:
Mallory Knodel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • setup_development_workstation_mac

    v1 v1  
     1== Installing and configuring critical helper packages ==
     2
     3Being able to send and receive email is often part of the web application development process.
     4
     5== Installing PHP, Apache, and MySQL ==
     6
     7PHP and Apache should be already installed. You can check your version of PHP and Apache with the following two, separate commands in a Terminal window (Applications > Utilities > Terminal):
     8
     9{{{
     10php -i
     11}}}
     12
     13Hopefully you're running php5. If not, you'll need to install it: http://php.net/downloads.php
     14
     15{{{
     16cd /etc/apache2
     17httpd -v
     18}}}
     19
     20If you are unable to complete the commands above, then you may need to install Apache from Unix source into /Library/Apache2: http://httpd.apache.org/download.cgi#apache22
     21
     22It's unlikely that your mac has mysql installed already, so you need to download the latest version from here: http://dev.mysql.com/downloads/mysql. Download and run the mysql-5.5.xxx-xxx.pkg file, which will automatically install to /usr/local. To put a control in your system preferences pane and start mysql, in the .dmg file, run MySQL.prefPane by double-clicking. Start mysql and also ensure that mysql always starts on boot.
     23
     24== Configuring the environment ==
     25
     26The goal of the configuration is to make it as easy as possible to setup a new development environment for a new project.
     27
     28Each 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.
     29
     30In this example, let's assume the workstation is named "junior" and the username is "admin." A new project called "mayfirst" would have the development domain name: mayfirst.local (below we will edit the /etc/hosts file so that this non-public domain name will resolve to the development workstation).
     31
     32Create a projects directory in your home directory:
     33
     34{{{
     35mkdir ~/projects
     36}}}
     37
     38There are a few tweaks that must be done before OS X will work with our setup:
     39
     40{{{
     41echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.profile
     42sudo mkdir /var/mysql
     43sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
     44}}}
     45
     46We need to do a lot of configuration to apache, which is almost all in the file /etc/apache2/httpd.conf. Start by commenting-out this line:
     47{{{
     48#ServerRoot "/usr"
     49}}}
     50
     51and uncommenting the following line:
     52{{{
     53LoadModule php5_module        libexec/apache2/libphp5.so
     54}}}
     55
     56and commenting-out this first line and adding the second:
     57{{{
     58#DocumentRoot "/Library/WebServer/Documents"
     59}}}
     60
     61Just below in the same file, /etc/apache2/httpd.conf, modify the default directory settings:
     62{{{
     63<Directory /User/admin/projects>
     64    Options All
     65    Options FollowSymLinks
     66    AllowOverride All
     67    Order deny,allow
     68    Deny from all
     69    Allow from 127.0.0.1
     70</Directory>
     71}}}
     72
     73There is now an entire block that must be commented-out regarding DocumentRoot. Insert a "#" in front of everything all the way to and including </Directory>. It starts with:
     74{{{
     75<Directory "/Library/WebServer/Documents">
     76}}}
     77
     78Also modify these lines so that they are as they appear below, which are sprinkled throughout the rest of this very long file and then save:
     79{{{
     80#Include /private/etc/apache2/extra/httpd-userdir.conf
     81Include /private/etc/apache2/extra/httpd-vhosts.conf
     82Include /private/etc/apache2/extra/httpd-default.conf
     83}}}
     84
     85Apache can be configured so that it dynamically sets the document root based on the domain name. Now, we want to drastically modify /etc/apache2/extras/httpd-vhosts.conf. It's best to actually create a clean file. Do this by backing up the old one and then editing a clean file with the same name:
     86{{{
     87mv /etc/apache2/extras/httpd-vhosts.conf /etc/apache2/extras/httpd-vhosts.conf.back
     88sudo nano /etc/apache2/extras/httpd-vhosts.conf
     89}}}
     90
     91While in editing mode, add this, save, and close:
     92{{{
     93<Directory /User/admin/projects>
     94  AllowOverride All
     95</Directory>
     96VirtualScriptAlias /User/admin/projects/%1/cgi-bin/
     97VirtualDocumentRoot /User/admin/projects/%1/web/
     98}}}
     99
     100This is the penultimate step to configure Apache. On a mac, you should be able to keep apache running without any issues with performance on your computer. But just to reduce traffic, since this not a live webserver, modify /etc/apache2/extras/httpd-mpm.conf with the following:
     101{{{
     102<IfModule mpm_prefork_module>
     103        StartServers          1
     104        MinSpareServers       1
     105        MaxSpareServers       2
     106        MaxClients           10
     107        MaxRequestsPerChild 100
     108</IfModule>
     109}}}
     110
     111Reload Apache so these changes take effect by going to system preferences > sharing and enabling web sharing.
     112
     113NOTE: If you are developing a Drupal project, you will need to edit your .htaccess file. There's a line that says the following:
     114
     115{{{
     116# If your site is running in a VirtualDocumentRoot at http://example.com/,
     117# uncomment the following line:
     118RewriteBase /
     119}}}
     120
     121You will want to uncomment the RewriteBase directive as shown above.
     122
     123== Steps to create a new project ==
     124
     125With your environment setup, you can easily start a new project by following these steps:
     126
     127 * Choose a name for the project. In this example, we'll choose the name mayfirst (and remember - in our example the computer name is junior).
     128 * Create the mysql database with:
     129{{{
     130mysql -u root -p -e "CREATE DATABASE mayfirst; GRANT ALL ON mayfirst.* to 'mayfirst'@'localhost' identified by 'mayfirst';"
     131}}}
     132 * 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:
     133{{{
     134127.0.0.1       localhost
     135127.0.1.1       mayfirst.local
     136}}}
     137 * Change into your projects directory:
     138{{{
     139cd ~/projects
     140}}}
     141 * Clone and checkout your source files via git
     142{{{
     143 git clone git@git.mayfirst.org:/mayfirst.git
     144}}}
     145 * OR create your project folders with:
     146{{{
     147mkdir ~/projects/mayfirst
     148mkdir ~/projects/mayfirst/web
     149mkdir ~/projects/mayfirst/cgi-bin
     150}}}
     151
     152Now you are ready to begin. You can start placing files in your project's web directory and access your project at the URL: !http://mayfirst.local/
     153
     154== Keeping files in sync ==
     155
     156If 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.
     157
     158A bash script like the following one can help - by providing an easy way to synchronize your development platform with the live site:
     159
     160{{{
     161#!/bin/bash
     162echo "Synchronizing database."
     163ssh <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>
     164
     165echo "Synchronizing files."
     166rsync -av --exclude '*/settings.php' --exclude '.svn*' --exclude '*/.svn*' --exclude 'sites*' <user>@<server>:<remote-path-to-files-directory> <local-path-to-files-director>
     167}}}