Last Updated: February 25, 2016
·
1.028K
· walidvb

Drush + nginx + php53 + Mavericks

So I was trying to reinstall MAMP to dev drupal locally after my HD failure, and I ran into some issues. Someone told me to not use MAMP, but to go with nginx. yay. sounds like fun. Or how to turn a click-to-install process into smth very complicated. Problem is, I like complicated. Anyways, it was a struggle to get this done, but thanks to the one and only chipotle(who spent 5 hours debugging this with me), I was able to get it running. Huge shout out to him.

I tried to paste instructions as they came in here, some might have changed, As i had to go back and forth, but if you do use them and run into an error, please feel free to contact me, maybe I'll remember what I did.

quick tip: to paste something directly into a foo file use pbpaste > foo

SET UP

[brew tap homebrew/versions && brew tap homebrew/homebrew-php]
brew install composer
brew install --without-apache --with-fpm --with-mysql php53
brew install --HEAD drush
brew switch drush HEAD
brew install mysql
[ mysql_secure_installation ]
brew install nginx


mkdir -p /usr/local/etc/nginx/logs
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl
sudo mkdir -p /var/www

sudo chown :staff /var/www
sudo chmod 775 /var/www

Save this as /usr/local/etc/nginx/nginx.conf:

worker_processes  1;

error_log  /usr/local/etc/nginx/logs/error.log debug;

events {
    worker_connections  256;
}

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  /usr/local/etc/nginx/logs/access.log  main;

    sendfile            on;

    keepalive_timeout   65;

    index index.html index.php;

    include /usr/local/etc/nginx/sites-enabled/*; 
}

Save this as /usr/local/etc/nginx/conf.d/php-fpm

location ~ \.php$ {
    try_files      $uri = 404;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

save this as template in /usr/local/etc/nginx

#Drupal specific rewriting configuration
    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

#Do not allow to view  .htaccess and .htpassword
    location ~ /\.ht {
        deny  all;
    }

ADD A NEW SITE

To add a new site, add a file with the site's name in /usr/local/etc/nginx/sites-enabled

server {
    listen 80;
    server_name foo.dev;
    root /Users/Gaston/Sites/foo;
    index index.php;

    #setup logging
    access_log /usr/local/etc/nginx/logs/foo.access.log;
    error_log /usr/local/etc/nginx/logs/foo.error.log;

    location / {
    include   /usr/local/etc/nginx/conf.d/php-fpm;
    include template;
}

    location = /info {
    allow   127.0.0.1;
    deny    all;
    rewrite (.*) /.info.php;

    error_page  404     /404.html;
    error_page  403     /403.html;
}

}

and add it to your hosts

sudo echo "127.0.0.1 foo.dev" >> /etc/hosts

DEBUG

Composer needed: run

cd /usr/local/Cellar/drush/HEAD/libexec/
composer install

If you want php on login, do smth like:

    echo 'export PATH="$(brew --prefix josegonzalez/php/php55)/bin:$PATH"' >> ~/.bash_profile
cp /usr/local/Cellar/php53/<tab complete>/homebrew.mxcl.php53.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php53.plist 
cp /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Else, if like me, you like to run it on demand, just write a small script or a function in your ~/.bash_profile along those lines. <COMING SOON>

Again, thanks to chipotle for spending the time on this with me.

2 Responses
Add your response

Good tip. The code are helping for me.

over 1 year ago ·

Good~~

over 1 year ago ·