Skip to content

Instantly share code, notes, and snippets.

@reegodev
Last active December 30, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reegodev/3ed6fc7c9a62cdb117c28ed2c29e9cda to your computer and use it in GitHub Desktop.
Save reegodev/3ed6fc7c9a62cdb117c28ed2c29e9cda to your computer and use it in GitHub Desktop.
OSX Dev setup

OSX Dev setup

iTerm2

Brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Zsh

brew install zsh

set as default shell chsh -s $(which zsh)

Oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

add plusins in ~/.zshrc plugins=(git colored-man colorize pip python brew osx zsh-syntax-highlighting)

OSX Dev setup

Nginx

brew install nginx

Php

brew install php72 --with-fpm --without-apache

dnsmasq

brew install dnsmasq

Mysql / Mariadb

brew install mysql / brew install mariadb brew services start mysql / brew services start mariadb

PostgreSQL

brew install postgresql brew services start postgresql

MongoDB

brew install mongodb brew services start mongodb

WP CLI

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

MailHog

brew install mailhog brew services start mailhog

OSX Dev setup

Dnsmasq

Add the custom domains to Dnsmasq config. Default path /usr/local/etc/dnsmasq.conf

address=/.wp.local/127.0.0.1
address=/.lav.local/127.0.0.1

Start the service sudo brew services start dnsmasq

Create the local DNS resolver

sudo mkdir /etc/resolver
sudo touch /etc/resolver/local

Add to the newly created file

nameserver 127.0.0.1

Save and restat the Mac.

Nginx

Default conf: /usr/local/etc/nginx/nginx.conf

  • Symlink nginx document root to a more accessible place: ln -s /usr/local/var/www /Users/rigo/Sites
  • Add index.php to allowed indexes
  • Add a server directive for dynamic subdomains on .wp.local
server {
        listen 80;

        server_name ~^(?<subfolder>.+)\.wp.local$;
        root    html/wp/$subfolder;
        
        index   index.php index.html index.htm;

        error_log  html/wp/error.log  notice;

        location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
    }
  • Add a server directive for dynamic subdomains on .lav.local (serving /public)
server {
        listen 80;

        server_name ~^(?<subfolder>.+)\.lav.local$;
        root    html/lav/$subfolder/public;
        
        index   index.php index.html index.htm;

        error_log  html/lav/error.log  notice;

        location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
    }
  • Start the service brew services start nginx

Now you should have a common nginx + php-fpm configuration

Maria DB / Mysql

  • connect via cli mysql -uroot
  • create a new user for dev operations CREATE USER 'dev'@'localhost' IDENTIFIED BY 'dev';
  • grant needed privileges GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON *.* TO 'dev'@'localhost';

PostgreSQL

We are not creating users and roles as it becomes cumbersome to grant roles for each database to a non-superuser account. Just use the root account which should have as username your SO user and an empty password.

Php

Edit the config at /usr/local/etc/php/7.2/php.ini

  • memory_limit = 512M
  • display_errors = On
  • post_max_size = 128M
  • upload_max_filesize = 128M
  • sendmail_path = /usr/local/bin/mailhog sendmail test@test

Mailhog

Access the web interface at http://localhost:8025. Allow push notifications for better usage

SSL on localhost / custom subdomains

Repeat this for every (sub)domain you need to support

Create required folders

mkdir /usr/local/etc/ssl/private
mkdir /usr/local/etc/ssl/certs

Create an openssl config

Location: /usr/local/etc/ssl/config/localhost.conf

Contents:

[req]
default_bits       = 2048
default_keyfile    = localhost.key
distinguished_name = req_distinguished_name
req_extensions     = req_ext
x509_extensions    = v3_ca

[req_distinguished_name]
countryName                 = Country Name (2 letter code)
countryName_default         = IT
stateOrProvinceName         = State or Province Name (full name)
stateOrProvinceName_default = Padova
localityName                = Locality Name (eg, city)
localityName_default        = Padova
organizationName            = Organization Name (eg, company)
organizationName_default    = localhost
organizationalUnitName      = organizationalunit
organizationalUnitName_default = Development
commonName                  = Common Name (e.g. server FQDN or YOUR name)
commonName_default          = localhost
commonName_max              = 64

[req_ext]
subjectAltName = @alt_names

[v3_ca]
subjectAltName = @alt_names

[alt_names]
DNS.1   = localhost
DNS.2   = 127.0.0.1

Generate the certificate

run sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -keyout /usr/local/etc/ssl/private/localhost.key -out /usr/local/etc/ssl/certs/localhost.crt -config /usr/local/etc/ssl/config/localhost.conf and press enter to every prompt

Update nginx server directive

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name localhost;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    ssl_certificate /usr/local/etc/ssl/certs/localhost.crt;
    ssl_certificate_key /usr/local/etc/ssl/private/localhost.key;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

    server_name localhost;
    
    # other directives...

Remember to reload nginx

Trust the certificate

run open /usr/local/etc/ssl/certs/localhost.crt and double click on the certificate file. Add it to System Certificates, then double click on it, press the "Trust" collapse and set "Always trust"

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