Changes between Initial Version and Version 1 of setup_development_workstation_mac

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



  • setup_development_workstation_mac

    v1 v1  
     1== Installing and configuring critical helper packages ==
     3Being able to send and receive email is often part of the web application development process.
     5== Installing PHP, Apache, and MySQL ==
     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):
     10php -i
     13Hopefully you're running php5. If not, you'll need to install it:
     16cd /etc/apache2
     17httpd -v
     20If you are unable to complete the commands above, then you may need to install Apache from Unix source into /Library/Apache2:
     22It's unlikely that your mac has mysql installed already, so you need to download the latest version from here: Download and run the 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.
     24== Configuring the environment ==
     26The goal of the configuration is to make it as easy as possible to setup a new development environment for a new project.
     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.
     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).
     32Create a projects directory in your home directory:
     35mkdir ~/projects
     38There are a few tweaks that must be done before OS X will work with our setup:
     41echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.profile
     42sudo mkdir /var/mysql
     43sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
     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:
     48#ServerRoot "/usr"
     51and uncommenting the following line:
     53LoadModule php5_module        libexec/apache2/
     56and commenting-out this first line and adding the second:
     58#DocumentRoot "/Library/WebServer/Documents"
     61Just below in the same file, /etc/apache2/httpd.conf, modify the default directory settings:
     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
     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:
     75<Directory "/Library/WebServer/Documents">
     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:
     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
     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:
     87mv /etc/apache2/extras/httpd-vhosts.conf /etc/apache2/extras/httpd-vhosts.conf.back
     88sudo nano /etc/apache2/extras/httpd-vhosts.conf
     91While in editing mode, add this, save, and close:
     93<Directory /User/admin/projects>
     94  AllowOverride All
     96VirtualScriptAlias /User/admin/projects/%1/cgi-bin/
     97VirtualDocumentRoot /User/admin/projects/%1/web/
     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:
     102<IfModule mpm_prefork_module>
     103        StartServers          1
     104        MinSpareServers       1
     105        MaxSpareServers       2
     106        MaxClients           10
     107        MaxRequestsPerChild 100
     111Reload Apache so these changes take effect by going to system preferences > sharing and enabling web sharing.
     113NOTE: If you are developing a Drupal project, you will need to edit your .htaccess file. There's a line that says the following:
     116# If your site is running in a VirtualDocumentRoot at,
     117# uncomment the following line:
     118RewriteBase /
     121You will want to uncomment the RewriteBase directive as shown above.
     123== Steps to create a new project ==
     125With your environment setup, you can easily start a new project by following these steps:
     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:
     130mysql -u root -p -e "CREATE DATABASE mayfirst; GRANT ALL ON mayfirst.* to 'mayfirst'@'localhost' identified by 'mayfirst';"
     132 * Add a new domain to your /etc/hosts file. Add it to the line that starts with (you can safely create the line if it doesn't exist). For example:
     134127.0.0.1       localhost
     135127.0.1.1       mayfirst.local
     137 * Change into your projects directory:
     139cd ~/projects
     141 * Clone and checkout your source files via git
     143 git clone
     145 * OR create your project folders with:
     147mkdir ~/projects/mayfirst
     148mkdir ~/projects/mayfirst/web
     149mkdir ~/projects/mayfirst/cgi-bin
     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/
     154== Keeping files in sync ==
     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.
     158A bash script like the following one can help - by providing an easy way to synchronize your development platform with the live site:
     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>
     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>