Skip to content

Instantly share code, notes, and snippets.

@gagarine
Created February 17, 2012 14:18
Show Gist options
  • Save gagarine/1853709 to your computer and use it in GitHub Desktop.
Save gagarine/1853709 to your computer and use it in GitHub Desktop.
Drupal on php-fpm + nginx + apc
brew update
brew install gmp
#install Nginx
brew install nginx
# copy launch script
cp /usr/local/Cellar/nginx/1.0.12/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
#try to launch Nginx
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
# Remove old version of PHP
brew remove php
#We have to remove some pear config files otherwise you get a Error like:
# Failed executing: /usr/local/Cellar/php/5.3.10/bin/pear config-set php_ini /usr/local/etc/php.ini
rm -rf ~/.pearrc
rm -rf ~/.pear
#install PHP with intl (for symfony) and fpm (for ngninx)
# WARNING better use https://github.com/josegonzalez/homebrew-php now (untested)
brew install https://github.com/adamv/homebrew-alt/raw/master/duplicates/php.rb --without-apache --with-intl --with-fpm --with-mysql
cp /usr/local/Cellar/php/5.3.10/etc/php-fpm.conf.default /usr/local/Cellar/php/5.3.10/etc/php-fpm.conf
mkdir /usr/local/Cellar/php/5.3.10/var/log
# APC, don't forget to add the conf in the php.ini
brew install apc
# Configure nginx, you can check the config files below
echo "Try http://localhost:8080 you will certainly need to configure nginx to do anythings useful"
# Extra
brew install xdebug
brew install xhprof

Nginx + PHP-fpm + APC + Drupal 7

Some documentations I used:

Start and Stop services

nginx

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

php-fpm

sudo /usr/local/sbin/php-fpm
sudo killall -c php-fpm

Nginx conf for Drupal with wildcard

worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
    index index.php index.html index.htm;

    server {
        
            listen       8080;
        
            server_name localhost local *.dev;
            
            root /Users/simon/Sites/$host/; ## <-- the only path reference.

            access_log off; # <--- on my personal dev machine

            #error_page  404              /404.html;

            # redirect server error pages to the static page /50x.html
            #
            #error_page   500 502 503 504  /50x.html;
            #location = /50x.html {
            #    root   html;
            #}
                        
            location = /favicon.ico {
                    log_not_found off;
                    access_log off;
            }

            location = /robots.txt {
                    allow all;
                    log_not_found off;
                    access_log off;
            }

            # This matters if you use drush
            location = /backup {
                    deny all;
            }

            # Very rarely should these ever be accessed outside of your lan
            location ~* \.(txt|log)$ {
                    allow 192.168.0.0/16;
                    deny all;
            }

            location ~ \..*/.*\.php$ {
                    return 403;
            }

            location / {
                    # This is cool because no php is touched for static content
                    try_files $uri @rewrite;
            }

            location @rewrite {
                    # Some modules enforce no slash (/) at the end of the URL
                    # Else this rewrite block wouldn't be needed (GlobalRedirect)
                    rewrite ^/(.*)$ /index.php?q=$1;
            }

            location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_intercept_errors on;
                    #fastcgi_pass unix:/tmp/phpfpm.sock;
            }

            # Fighting with ImageCache? This little gem is amazing.
            location ~ ^/sites/.*/files/imagecache/ {
                    try_files $uri @rewrite;
            }
            # Catch image styles for D7 too.
            location ~ ^/sites/.*/files/styles/ {
                    try_files $uri @rewrite;
            }

            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }
            
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #    deny  all;
            #}
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment