Drupal on Snow Leopard with NGINX

 

I run a mixed setup of OpenACS, ]project-open[ and Drupal on my server. To handle this correctly I decided to let nginx act as a reverse proxy for OpenACS and ]project-open[ sites and also let all the websites reside in ~/Sites.

For the installation of OpenACS please check out  http://openacs.org/xowiki/openacs-system-install-osx-macports.

To install nginx, use macports as well.

sudo port install nginx +status +ssl +flv +realip +perl5

Make sure you can start nginx on system startup

 

To get Drupal to run correctly I first had to install PHP with mysql and fastcgi support

 

sudo port install php52 +fastcgi +mysql5 +readline
sudo port install mysql5-server

This get's you going with all the needed files. 

Now install the database server

sudo -u _mysql mysql_install_db5

cd /opt/local ; sudo /opt/local/lib/mysql5/bin/mysqld_safe &

 

 

 

 

To configure nginx, go to the various instructions found here. I usually prefer to have a sites-enabled directory with just the server sections, so this is the server section for an OpenACS install, stored at /opt/local/etc/nginx/sites-enabled/yoursite.conf 

server {

    listen 192.168.2.5:80;

    server_name  cognovis.de;

    location / {

        proxy_pass http://127.0.0.1:8000;

        proxy_set_header  X-Forwarded-For  $remote_addr;

    }

    location /stats/ {

        proxy_pass http://stats.cognovis.de/awstats.pl?config=cognovis;

        include         proxy.conf;

    }

    access_log  /opt/local/var/log/nginx/cognovis.access.log  main;

}

 

Now it is time to install drupal

First configure PHP to work with mysql. 

 

sudo cp /opt/local/etc/php5/php.ini-recommended /opt/local/etc/php5/php.ini

 

Then edit the file and tell it where mysql is running

 

mysql.default_socket =  /opt/local/var/run/mysql5/mysqld.sock 

 

Then start the php fastcgi daemon

 

sudo /opt/local/bin/php-cgi -q -b 127.0.0.1:9000

 

and then test it. 

Then have the php-cgi run on startup

Edit  /Library/LaunchDaemons/org.macports.fastcgi.plist with the following content

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

  <dict>

    <key>Debug</key>

    <false/>

    <key>EnvironmentVariables</key>

  <dict>

    <key>PHP_FCGI_CHILDREN</key>

    <string>2</string>

    <key>PHP_FCGI_MAX_REQUESTS</key>

    <string>1000</string>

  </dict>

  <key>Label</key>

  <string>org.macports.fastcgi</string>

  <key>OnDemand</key>

  <false/>

  <key>ProgramArguments</key>

  <array>

    <string>/opt/local/bin/php-cgi</string>

    <string>-b127.0.0.1:9000</string>

    <string>-q</string>

  </array>

  <key>RunAtLoad</key>

  <false/>

  </dict>

</plist>

Then start it. 

 

sudo launchctl load -w /Library/LaunchDaemons/org.macports.fastcgi.plist

 

do more