###Phing Install (development)

####0. Get Code

Assuming you've added your pubkey to your github account (if you don't have pubkey setup, read more [Generating SSH keys](https://help.github.com/articles/generating-ssh-keys)), do the following:

```
$ cd /path/to/your/web/dir
$ git clone git@github.com:theorchard/orchard.git ./
```

####1. Get Phing

[Phing](http://www.phing.info/) is a build tool for PHP. It is similar to Apache Ant and uses XML build files. In order to use Phing you will need to install it using PEAR.

```
$ sudo pear channel-discover pear.phing.info
$ sudo pear install phing/phing
```

Check to make sure Phing is present in your path:

```
$ which phing
```

Should give you something like (path may differ from example):

```
$ /usr/local/opt/php53/bin/phing
```


####2. Phing Config

Rename `/application/configs/phing.shadow.properties` to `/application/configs/phing.properties`. Now fill out the following fields:

```
//host for memcache. no need for port
memcache.host=
//alw hostname without www or http://
workstation.host=
//alw hostname without www or http://
oa.host=
//138 username for art_relations, etc.
db.username=
//138 username for art_relations, etc.
db.password=
```

So, for example:

```
memcache.host=127.0.0.1
workstation.host=alw.orchard
oa.host=oa.orchard
db.username=brucebanner
db.password=password123
```

####3. Run Phing

From the root of your codebase run:

```
$ phing -f phing.xml
```

####4. Get Composer

[Composer](https://getcomposer.org/) is a package manager for PHP (similar to Ruby Gems or NPM). If you don't have it, you can get it [here](https://getcomposer.org/download/).

After you've got it installed:

```
$ composer install
```

Composer should grab all the necessary dependencies.


####5. Set up your Apache vhosts

You will need two Apache virtual hosts sharing one codebase. The following is only given as an example. Replace the bracketed items with your own values. Notice that the DocumentRoot is the same for both hosts, but the ServerName differs. Also notice that the DocumentRoot points to the *public* directory of your codebase.

```
    <VirtualHost SERVERIP:80>
        ServerAdmin {youremail@theorchard.com}
        DocumentRoot {/path/to/your/orchard/codebase/public}
        ServerName {oa.server.name.given.in.phing.properties}
        ErrorLog logs/oa-marketing-error_log
        CustomLog logs/oa-marketing-access_log combined
        SetEnv APPLICATION_ENV development
        RewriteEngine off
        <Directory />
            Options FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>

    <VirtualHost SERVERIP:80>
        ServerAdmin {youremail@theorchard.com}
        DocumentRoot {/path/to/your/orchard/codebase/public}
        ServerName {alw.server.name.given.in.phing.properties}
        ErrorLog logs/alw-marketing-error_log
        CustomLog logs/alw-marketing-access_log combined
        SetEnv APPLICATION_ENV development
        RewriteEngine off
        <Directory />
            Options FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
```

Restart Apache, and you are good to go.


###Postscript: What Phing is doing (Mostly)

It is best to simply read the Phing.xml file to see how to do this 'by hand,' but here is a somewhat current explanation.

```
$ mkdir -p application/modules/alw/data/logs
$ mkdir -p application/modules/oa/data/logs
$ mkdir -p public/tmp
$ mkdir -p public/images/coverart
$ mkdir -p public/images/coverart_10
$ mkdir -p public/images/coverart_correction
$ mkdir -p public/images/lg_coverart
$ mkdir -p public/images/lg_coverart_10
$ mkdir -p public/images/log_coverart_correction
$ chmod 775 application/modules/alw/data/logs
$ chmod 775 application/modules/oa/data/logs
$ chmod 775 public/tmp
$ chmod 775 pulbic/images/coverart
$ chmod 775 public/images/coverart_10
$ chmod 775 public/images/coverart_correction
$ chmod 775 public/images/lg_coverart
$ chmod 775 public/images/lg_coverart_10
$ chmod 775 public/images/log_coverart_correction
$ cp public/.dev.shadow.htaccess public/.htaccess
$ cp application/configs/application.shadow.ini application/configs/application.ini
$ cp application/configs/accounting.shadow.ini application/configs/accounting.ini
$ cp application/configs/server_locations.shadow.ini application/configs/server_locations.ini
$ cp application/configs/config.shadow.ini application/configs/config.ini
$ cp application/configs/aws.shadow.ini application/configs/aws.ini
```

And then:

* /public/error.inc: change the webdev@theorchard.com to {YOUR EMAIL/SQUAD ALIAS}
* /application/configs/config.ini:

```
cache.memcached.host = "REPLACE ME"
cache.memcached.port = "11211"
```

*These settings should match your php.ini settings for memcached.*

```
notification.email.subject = "ALW Notification" to "ALW Notification - {Your Name/SQUAD}
notification.email.addresses["alw-error-watchersnotification"] to {Your Email/SQUAD ALIAS}
workstation_host = "your.workstation.host.devorch.com";
workstation_login_url = "http://your.workstation.host.devorch.com/login/index";
oa_host = "your.oa.hostname.devorch.com";
```

* /application/configs/application.ini

```
routes.alw.route = "your.workstation.host.devorch.com"
routes.oa.route = "your.oa.host.devorch.com"
resources.doctrine.resultscache.on = true
resources.doctrine.resultscache.memcached.host = localhost
resources.doctrine.resultscache.memcached.port = 11211
resources.doctrine.resultscache.memcached.persistent = true
resources.doctrine.resultscache.memcached.compression = false
```
