Nginx

Setup on Mac with MacPorts

$ sudo apt-get install

On OS X (macports):
$ port install nginx

To run at system start: 
$ sudo port load nginx

Config files and folders

- /etc/nginx/

On OS X (macport):
- /opt/local/etc/nginx/

Activate default configuration

Start by setting the default config files:

$ cd /opt/local/etc/nginx
$ sudo cp nginx.conf.default nginx.conf
$ sudo cp mime.types.default mime.types
    
Load http://localhost in your browser to see that it's working.

Reload

$ sudo nginx -s stop; sudo nginx
or, if you just need updating config 
$ sudo nginx -s reload

OS X uses launchd so the process of starting/stopping daemons is slightly different.

$ sudo port unload nginx
$ sudo port load nginx

Make Browsers Cache Static Files On nginx

location /static {
    alias {{django.static_root}};

    # Make Browsers Cache Static Files On nginx
    # See: http://www.howtoforge.com/make-browsers-cache-static-files-on-nginx
    # and  http://serverfault.com/questions/370525/nginxdjango-serving-static-files
    access_log   off;
    expires modified 1m;
}

Postgresql

Setup on Mac with MacPorts

$ sudo port install postgresql91 postgresql91-server

To create a database instance, after install do
 sudo mkdir -p /opt/local/var/db/postgresql91/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql91/defaultdb
 # sudo su postgres -c '/opt/local/lib/postgresql91/bin/initdb -D /opt/local/var/db/postgresql91/defaultdb' 
 sudo su postgres -c '/opt/local/lib/postgresql91/bin/initdb -D /opt/local/var/db/postgresql91/defaultdb --lc-collate="en_US.UTF-8" --lc-ctype="en_US.UTF-8"' 

To tweak your DBMS, consider increasing kern.sysv.shmmax by adding an increased kern.sysv.shmmax .. to /etc/sysctl.conf

Now you can start the database server using:

$ sudo su postgres -c '/opt/local/lib/postgresql91/bin/pg_ctl -D /opt/local/var/db/postgresql91/defaultdb -l logfile start'

To start the service automatically:
$ sudo launchctl load -w -F /Library/LaunchDaemons/org.macports.postgresql84-server.plist

Reload

$ sudo /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status}

Reload (on Mac)

$ sudo launchctl unload /Library/LaunchDaemons/org.macports.postgresql84-server.plist
$ sudo launchctl load /Library/LaunchDaemons/org.macports.postgresql84-server.plist

Vedere anche : http://www.jonathandean.com/2011/08/postgresql-8-4-on-mac-os-x-10-7-lion/

Oppure:

    1) Using the superuser account you can query the location of the data directory through SQL:
    # select name, setting from pg_settings where name = 'data_directory';

    2) With that information you can supply the data directory to the pg_ctl command using the -D switch:
    $ sudo su
    # su postgres
    $ pg_ctl -D PATH restart

    Thanks to: http://stackoverflow.com/questions/7990539/restarting-postgres-on-mac

Setup a Virtualenv and Python on Mac with MacPorts

XCode

- install Xcode from the Apple Appstore
- open Xcode, open the preferences, and check the downloads tab to install the latest version of the command line tools.

MacPorts

- Install MacPorts for Lion from the DMG disk image at (http://www.macports.org/install.php)
- Rename .profile to .bash_profile, or if you already have a .bash_profile, 
  edit this file to make sure that the Macports setup correctly installed the path statement
- Configure Spotlight to exclude /opt/local from indexing: system prefs -> spotlight -> privacy -> add /opt/local

Python27

$ sudo port selfupdate
$ sudo port install python27
### $ sudo port select -–set python python27
$ sudo port install py27-virtualenv

Virtualenv

$ /opt/local/bin/virtualenv-2.7 $HOME/local/python/27

Add to .bash_profile:
alias py27="source $HOME/local/python/27/bin/activate"

$ py27
$ which pip
   $HOME/local/python/27/bin/pip
$ pip install ipython

$ which easy_install
   $HOME/local/python/27/bin/easy_install
$ easy_install readline
...

Usefull environment variables

export PIP_RESPECT_VIRTUALENV=true
export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache
...

Mac port upgrade hints

Python

To make python 2.6 the default (i.e. the version you get when you run
'python'), please run:

$ sudo port select --set python python26

PostgreSQL 8.4

###########################################################
# A startup item has been generated that will aid in
# starting postgresql84-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load postgresql84-server
###########################################################
--->  Installing postgresql84-server @8.4.10_0

To create a database instance, after install do
 sudo mkdir -p /opt/local/var/db/postgresql84/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql84/defaultdb
 sudo su postgres -c '/opt/local/lib/postgresql84/bin/initdb -D /opt/local/var/db/postgresql84/defaultdb'

memcached, nginx, apache2, rsync

###########################################################
# A startup item has been generated that will aid in
# starting memcached with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load memcached
...
# sudo port load apache2
# sudo port load nginx
# sudo port load rsync

###########################################################