Skip to content

Instantly share code, notes, and snippets.

@anderssvendal
Created May 3, 2012 13:44
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save anderssvendal/2585743 to your computer and use it in GitHub Desktop.
Save anderssvendal/2585743 to your computer and use it in GitHub Desktop.
Foreman nginx, php, mysql setup

Install packages

You should have homebrew version 0.9 or newer.

Install nginx

brew install nginx

Install mysql

brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

Install php

brew tap josegonzalez/homebrew-php
brew install php --with-mysql --with-fpm

Tweak config

php-fpm

To run php-fpm in the foreground set deamonize = no in the php-fpm.conf. Should be located in /usr/local/Cellar/php/5.3.10/etc

nginx

Change the root-path in nginx.conf

Folder structure

Procfile
app
  <webapp goes here>
nginx.conf
tmp
  nginx
    logs
      access.log
      error.log

Setup script

Use the setup.rb script to quickly prepare a new project. It creates the configuration files and skeleton folder structure.

You can pass one parameter to the script, the name of the folder to use. Leave it empty to use the current directory.

Run it directly from this gist:

ruby -e "$(curl -fsSL https://raw.github.com/gist/2585743/d4d1fdb431724675ec2c6894a083c8af3872bb6f/setup.rb)" [optional folder name]
daemon off;
http {
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 3000;
server_name localhost;
root <absolute path to document root>;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$
{
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
}
events {
}
web: /usr/local/sbin/nginx -p `pwd`/tmp/nginx/ -c ../../nginx.conf
fastcgi: /usr/local/sbin/php-fpm
db: /usr/local/bin/mysqld
require 'fileutils'
base = ARGV[0] || '.'
homebrew_path = `brew --prefix`.gsub(/\n/, '')
current_dir = File.expand_path(base)
procfile = <<PROCFILE
web: #{homebrew_path}/sbin/nginx -p #{current_dir}/tmp/nginx/ -c ../../nginx.conf
fastcgi: #{homebrew_path}/sbin/php-fpm
db: #{homebrew_path}/bin/mysqld
PROCFILE
nginx_conf = <<NGINX_CONF
daemon off;
http {
include #{homebrew_path}/etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 3000;
server_name localhost;
root #{current_dir}/app;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$
{
include #{homebrew_path}/etc/nginx/fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
}
events {
}
NGINX_CONF
# Create folder structure
FileUtils.mkdir_p "#{base}/tmp/nginx/logs"
FileUtils.mkdir "#{base}/app"
# Create empty files
FileUtils.touch "#{base}/tmp/nginx/logs/access.log"
FileUtils.touch "#{base}/tmp/nginx/logs/error.log"
# Create config files
File.open("#{base}/Procfile", 'w') {|f| f.write(procfile) }
File.open("#{base}/nginx.conf", 'w') {|f| f.write(nginx_conf) }
# Create test php file
File.open("#{base}/app/index.php", 'w') {|f| f.write("<?php\n echo '<h1>It works!</h1>';\n") }
@kinglouie
Copy link

i got the same problem, also tried with daemonize = no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment