Run your legacy projects in PHP 5.6 along with Laravel Valet that runs under PHP 7.2 in macOS

As of this writing, the latest Laravel Valet requires PHP 7.2. What if you still have legacy projects or Drupal 6 modules you maintain that can't run under PHP 7.2? It would be nice if Laravel Valet has option to run multiple PHP versions but there isn't one. Laravel Valet uses nginx + php-fpm and we can tap to nginx and php-fpm's configurations to make possible to run our legacy projects in PHP 5.6. This will make our nginx running both PHP 7.2 and PHP 5.6.

Let's use Drupal 6 as our legacy project example. In the following steps, macOS user webfoobar will be used. The Drupal 6 files are in /Users/webfoobar/Documents/htdocs/drupal6 and test domain drupal6site.test will be used. Note: You can utilize the features of Laravel Valet only to your projects that don't have problem running in PHP 7.2 but not for your legacy projects that can't run in PHP 7.2 (you will need to do it manually).

  1.       
    brew install php56 --with-pear
          
        
  2. Edit the file /usr/local/etc/php/5.6/php-fpm.conf and replace all of its content with the following scripts:

          
    ;;;;;;;;;;;;;;;;;;;;;
    ; FPM Configuration ;
    ;;;;;;;;;;;;;;;;;;;;;
    
    ; All relative paths in this configuration file are relative to PHP's install
    ; prefix (/usr/local/Cellar/php@5.6/5.6.36). This prefix can be dynamically changed by using the
    ; '-p' argument from the command line.
    
    ; Include one or more files. If glob(3) exists, it is used to include a bunch of
    ; files from a glob(3) pattern. This directive can be used everywhere in the
    ; file.
    ; Relative path can also be used. They will be prefixed by:
    ;  - the global prefix if it's been set (-p argument)
    ;  - /usr/local/Cellar/php@5.6/5.6.36 otherwise
    ;include=etc/fpm.d/*.conf
    
    ;;;;;;;;;;;;;;;;;;
    ; Global Options ;
    ;;;;;;;;;;;;;;;;;;
    
    [global]
    ; Pid file
    ; Note: the default prefix is /usr/local/var
    ; Default Value: none
    ;pid = run/php-fpm.pid
    
    ; Error log file
    ; If it's set to "syslog", log is sent to syslogd instead of being written
    ; in a local file.
    ; Note: the default prefix is /usr/local/var
    ; Default Value: log/php-fpm.log
    ;error_log = log/php-fpm.log
    
    ; syslog_facility is used to specify what type of program is logging the
    ; message. This lets syslogd specify that messages from different facilities
    ; will be handled differently.
    ; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
    ; Default Value: daemon
    ;syslog.facility = daemon
    
    ; syslog_ident is prepended to every message. If you have multiple FPM
    ; instances running on the same server, you can change the default value
    ; which must suit common needs.
    ; Default Value: php-fpm
    ;syslog.ident = php-fpm
    
    ; Log level
    ; Possible Values: alert, error, warning, notice, debug
    ; Default Value: notice
    ;log_level = notice
    
    ; If this number of child processes exit with SIGSEGV or SIGBUS within the time
    ; interval set by emergency_restart_interval then FPM will restart. A value
    ; of '0' means 'Off'.
    ; Default Value: 0
    ;emergency_restart_threshold = 0
    
    ; Interval of time used by emergency_restart_interval to determine when 
    ; a graceful restart will be initiated.  This can be useful to work around
    ; accidental corruptions in an accelerator's shared memory.
    ; Available Units: s(econds), m(inutes), h(ours), or d(ays)
    ; Default Unit: seconds
    ; Default Value: 0
    ;emergency_restart_interval = 0
    
    ; Time limit for child processes to wait for a reaction on signals from master.
    ; Available units: s(econds), m(inutes), h(ours), or d(ays)
    ; Default Unit: seconds
    ; Default Value: 0
    ;process_control_timeout = 0
    
    ; The maximum number of processes FPM will fork. This has been design to control
    ; the global number of processes when using dynamic PM within a lot of pools.
    ; Use it with caution.
    ; Note: A value of 0 indicates no limit
    ; Default Value: 0
    ; process.max = 128
    
    ; Specify the nice(2) priority to apply to the master process (only if set)
    ; The value can vary from -19 (highest priority) to 20 (lower priority)
    ; Note: - It will only work if the FPM master process is launched as root
    ;       - The pool process will inherit the master process priority
    ;         unless it specified otherwise
    ; Default Value: no set
    ; process.priority = -19
    
    ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
    ; Default Value: yes
    daemonize = no
     
    ; Set open file descriptor rlimit for the master process.
    ; Default Value: system defined value
    ;rlimit_files = 1024
     
    ; Set max core size rlimit for the master process.
    ; Possible Values: 'unlimited' or an integer greater or equal to 0
    ; Default Value: system defined value
    ;rlimit_core = 0
    
    ; Specify the event mechanism FPM will use. The following is available:
    ; - select     (any POSIX os)
    ; - poll       (any POSIX os)
    ; - epoll      (linux >= 2.5.44)
    ; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
    ; - /dev/poll  (Solaris >= 7)
    ; - port       (Solaris >= 10)
    ; Default Value: not set (auto detection)
    ;events.mechanism = epoll
    
    ; When FPM is build with systemd integration, specify the interval,
    ; in second, between health report notification to systemd.
    ; Set to 0 to disable.
    ; Available Units: s(econds), m(inutes), h(ours)
    ; Default Unit: seconds
    ; Default value: 10
    ;systemd_interval = 10
    
    ;;;;;;;;;;;;;;;;;;;;
    ; Pool Definitions ; 
    ;;;;;;;;;;;;;;;;;;;;
    
    ; Multiple pools of child processes may be started with different listening
    ; ports and different management options.  The name of the pool will be
    ; used in logs and stats. There is no limitation on the number of pools which
    ; FPM can handle. Your system will tell you anyway :)
    
    
    ; Include one or more files. If glob(3) exists, it is used to include a bunch of
    ; files from a glob(3) pattern. This directive can be used everywhere in the
    ; file.
    ; Relative path can also be used. They will be prefixed by:
    ;  - the global prefix if it's been set (-p argument)
    ;  - /usr/local/Cellar/php@5.6/5.6.36 otherwise
    include=/usr/local/etc/php/5.6/php-fpm.d/*.conf
          
        
  3. Create php-fpm.d directory:

          
    mkdir /usr/local/etc/php/5.6/php-fpm.d
          
        
  4. Create the file /usr/local/etc/php/5.6/php-fpm.d/www1.conf and copy the following scripts to this file:

          
    ; Start a new pool named 'www'.
    ; the variable $pool can we used in any directive and will be replaced by the
    ; pool name ('www' here)
    [www1]
    
    ; Per pool prefix
    ; It only applies on the following directives:
    ; - 'access.log'
    ; - 'slowlog'
    ; - 'listen' (unixsocket)
    ; - 'chroot'
    ; - 'chdir'
    ; - 'php_values'
    ; - 'php_admin_values'
    ; When not set, the global prefix (or /usr/local/Cellar/php@5.6/5.6.36) applies instead.
    ; Note: This directive can also be relative to the global prefix.
    ; Default Value: none
    ;prefix = /path/to/pools/$pool
    
    ; Unix user/group of processes
    ; Note: The user is mandatory. If the group is not set, the default user's group
    ;       will be used.
    user = webfoobar
    group = staff
    
    ; The address on which to accept FastCGI requests.
    ; Valid syntaxes are:
    ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
    ;                            a specific port;
    ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
    ;                            a specific port;
    ;   'port'                 - to listen on a TCP socket to all IPv4 addresses on a
    ;                            specific port;
    ;   '[::]:port'            - to listen on a TCP socket to all addresses
    ;                            (IPv6 and IPv4-mapped) on a specific port;
    ;   '/path/to/unix/socket' - to listen on a unix socket.
    ; Note: This value is mandatory.
    listen = 127.0.0.1:9001
    
    ; Set listen(2) backlog.
    ; Default Value: 65535 (-1 on FreeBSD and OpenBSD)
    ;listen.backlog = 65535
    
    ; Set permissions for unix socket, if one is used. In Linux, read/write
    ; permissions must be set in order to allow connections from a web server. Many
    ; BSD-derived systems allow connections regardless of permissions. 
    ; Default Values: user and group are set as the running user
    ;                 mode is set to 0660
    ;listen.owner = _www
    ;listen.group = _www
    ;listen.mode = 0660
    ; When POSIX Access Control Lists are supported you can set them using
    ; these options, value is a comma separated list of user/group names.
    ; When set, listen.owner and listen.group are ignored
    ;listen.acl_users =
    ;listen.acl_groups =
     
    ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
    ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
    ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
    ; must be separated by a comma. If this value is left blank, connections will be
    ; accepted from any ip address.
    ; Default Value: any
    ;listen.allowed_clients = 127.0.0.1
    
    ; Specify the nice(2) priority to apply to the pool processes (only if set)
    ; The value can vary from -19 (highest priority) to 20 (lower priority)
    ; Note: - It will only work if the FPM master process is launched as root
    ;       - The pool processes will inherit the master process priority
    ;         unless it specified otherwise
    ; Default Value: no set
    ; process.priority = -19
    
    ; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
    ; or group is differrent than the master process user. It allows to create process
    ; core dump and ptrace the process for the pool user.
    ; Default Value: no
    ; process.dumpable = yes
    
    ; Choose how the process manager will control the number of child processes.
    ; Possible Values:
    ;   static  - a fixed number (pm.max_children) of child processes;
    ;   dynamic - the number of child processes are set dynamically based on the
    ;             following directives. With this process management, there will be
    ;             always at least 1 children.
    ;             pm.max_children      - the maximum number of children that can
    ;                                    be alive at the same time.
    ;             pm.start_servers     - the number of children created on startup.
    ;             pm.min_spare_servers - the minimum number of children in 'idle'
    ;                                    state (waiting to process). If the number
    ;                                    of 'idle' processes is less than this
    ;                                    number then some children will be created.
    ;             pm.max_spare_servers - the maximum number of children in 'idle'
    ;                                    state (waiting to process). If the number
    ;                                    of 'idle' processes is greater than this
    ;                                    number then some children will be killed.
    ;  ondemand - no children are created at startup. Children will be forked when
    ;             new requests will connect. The following parameter are used:
    ;             pm.max_children           - the maximum number of children that
    ;                                         can be alive at the same time.
    ;             pm.process_idle_timeout   - The number of seconds after which
    ;                                         an idle process will be killed.
    ; Note: This value is mandatory.
    pm = dynamic
    
    ; The number of child processes to be created when pm is set to 'static' and the
    ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
    ; This value sets the limit on the number of simultaneous requests that will be
    ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
    ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
    ; CGI. The below defaults are based on a server without much resources. Don't
    ; forget to tweak pm.* to fit your needs.
    ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
    ; Note: This value is mandatory.
    pm.max_children = 5
    
    ; The number of child processes created on startup.
    ; Note: Used only when pm is set to 'dynamic'
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 2
    
    ; The desired minimum number of idle server processes.
    ; Note: Used only when pm is set to 'dynamic'
    ; Note: Mandatory when pm is set to 'dynamic'
    pm.min_spare_servers = 1
    
    ; The desired maximum number of idle server processes.
    ; Note: Used only when pm is set to 'dynamic'
    ; Note: Mandatory when pm is set to 'dynamic'
    pm.max_spare_servers = 3
    
    ; The number of seconds after which an idle process will be killed.
    ; Note: Used only when pm is set to 'ondemand'
    ; Default Value: 10s
    ;pm.process_idle_timeout = 10s;
     
    ; The number of requests each child process should execute before respawning.
    ; This can be useful to work around memory leaks in 3rd party libraries. For
    ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
    ; Default Value: 0
    ;pm.max_requests = 500
    
    ; The URI to view the FPM status page. If this value is not set, no URI will be
    ; recognized as a status page. It shows the following informations:
    ;   pool                 - the name of the pool;
    ;   process manager      - static, dynamic or ondemand;
    ;   start time           - the date and time FPM has started;
    ;   start since          - number of seconds since FPM has started;
    ;   accepted conn        - the number of request accepted by the pool;
    ;   listen queue         - the number of request in the queue of pending
    ;                          connections (see backlog in listen(2));
    ;   max listen queue     - the maximum number of requests in the queue
    ;                          of pending connections since FPM has started;
    ;   listen queue len     - the size of the socket queue of pending connections;
    ;   idle processes       - the number of idle processes;
    ;   active processes     - the number of active processes;
    ;   total processes      - the number of idle + active processes;
    ;   max active processes - the maximum number of active processes since FPM
    ;                          has started;
    ;   max children reached - number of times, the process limit has been reached,
    ;                          when pm tries to start more children (works only for
    ;                          pm 'dynamic' and 'ondemand');
    ; Value are updated in real time.
    ; Example output:
    ;   pool:                 www
    ;   process manager:      static
    ;   start time:           01/Jul/2011:17:53:49 +0200
    ;   start since:          62636
    ;   accepted conn:        190460
    ;   listen queue:         0
    ;   max listen queue:     1
    ;   listen queue len:     42
    ;   idle processes:       4
    ;   active processes:     11
    ;   total processes:      15
    ;   max active processes: 12
    ;   max children reached: 0
    ;
    ; By default the status page output is formatted as text/plain. Passing either
    ; 'html', 'xml' or 'json' in the query string will return the corresponding
    ; output syntax. Example:
    ;   http://www.foo.bar/status
    ;   http://www.foo.bar/status?json
    ;   http://www.foo.bar/status?html
    ;   http://www.foo.bar/status?xml
    ;
    ; By default the status page only outputs short status. Passing 'full' in the
    ; query string will also return status for each pool process.
    ; Example: 
    ;   http://www.foo.bar/status?full
    ;   http://www.foo.bar/status?json&full
    ;   http://www.foo.bar/status?html&full
    ;   http://www.foo.bar/status?xml&full
    ; The Full status returns for each process:
    ;   pid                  - the PID of the process;
    ;   state                - the state of the process (Idle, Running, ...);
    ;   start time           - the date and time the process has started;
    ;   start since          - the number of seconds since the process has started;
    ;   requests             - the number of requests the process has served;
    ;   request duration     - the duration in µs of the requests;
    ;   request method       - the request method (GET, POST, ...);
    ;   request URI          - the request URI with the query string;
    ;   content length       - the content length of the request (only with POST);
    ;   user                 - the user (PHP_AUTH_USER) (or '-' if not set);
    ;   script               - the main script called (or '-' if not set);
    ;   last request cpu     - the %cpu the last request consumed
    ;                          it's always 0 if the process is not in Idle state
    ;                          because CPU calculation is done when the request
    ;                          processing has terminated;
    ;   last request memory  - the max amount of memory the last request consumed
    ;                          it's always 0 if the process is not in Idle state
    ;                          because memory calculation is done when the request
    ;                          processing has terminated;
    ; If the process is in Idle state, then informations are related to the
    ; last request the process has served. Otherwise informations are related to
    ; the current request being served.
    ; Example output:
    ;   ************************
    ;   pid:                  31330
    ;   state:                Running
    ;   start time:           01/Jul/2011:17:53:49 +0200
    ;   start since:          63087
    ;   requests:             12808
    ;   request duration:     1250261
    ;   request method:       GET
    ;   request URI:          /test_mem.php?N=10000
    ;   content length:       0
    ;   user:                 -
    ;   script:               /home/fat/web/docs/php/test_mem.php
    ;   last request cpu:     0.00
    ;   last request memory:  0
    ;
    ; Note: There is a real-time FPM status monitoring sample web page available
    ;       It's available in: /usr/local/Cellar/php@5.6/5.6.36/share/php/fpm/status.html
    ;
    ; Note: The value must start with a leading slash (/). The value can be
    ;       anything, but it may not be a good idea to use the .php extension or it
    ;       may conflict with a real PHP file.
    ; Default Value: not set 
    ;pm.status_path = /status
     
    ; The ping URI to call the monitoring page of FPM. If this value is not set, no
    ; URI will be recognized as a ping page. This could be used to test from outside
    ; that FPM is alive and responding, or to
    ; - create a graph of FPM availability (rrd or such);
    ; - remove a server from a group if it is not responding (load balancing);
    ; - trigger alerts for the operating team (24/7).
    ; Note: The value must start with a leading slash (/). The value can be
    ;       anything, but it may not be a good idea to use the .php extension or it
    ;       may conflict with a real PHP file.
    ; Default Value: not set
    ;ping.path = /ping
    
    ; This directive may be used to customize the response of a ping request. The
    ; response is formatted as text/plain with a 200 response code.
    ; Default Value: pong
    ;ping.response = pong
    
    ; The access log file
    ; Default: not set
    ;access.log = log/$pool.access.log
    
    ; The access log format.
    ; The following syntax is allowed
    ;  %%: the '%' character
    ;  %C: %CPU used by the request
    ;      it can accept the following format:
    ;      - %{user}C for user CPU only
    ;      - %{system}C for system CPU only
    ;      - %{total}C  for user + system CPU (default)
    ;  %d: time taken to serve the request
    ;      it can accept the following format:
    ;      - %{seconds}d (default)
    ;      - %{miliseconds}d
    ;      - %{mili}d
    ;      - %{microseconds}d
    ;      - %{micro}d
    ;  %e: an environment variable (same as $_ENV or $_SERVER)
    ;      it must be associated with embraces to specify the name of the env
    ;      variable. Some exemples:
    ;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
    ;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
    ;  %f: script filename
    ;  %l: content-length of the request (for POST request only)
    ;  %m: request method
    ;  %M: peak of memory allocated by PHP
    ;      it can accept the following format:
    ;      - %{bytes}M (default)
    ;      - %{kilobytes}M
    ;      - %{kilo}M
    ;      - %{megabytes}M
    ;      - %{mega}M
    ;  %n: pool name
    ;  %o: output header
    ;      it must be associated with embraces to specify the name of the header:
    ;      - %{Content-Type}o
    ;      - %{X-Powered-By}o
    ;      - %{Transfert-Encoding}o
    ;      - ....
    ;  %p: PID of the child that serviced the request
    ;  %P: PID of the parent of the child that serviced the request
    ;  %q: the query string 
    ;  %Q: the '?' character if query string exists
    ;  %r: the request URI (without the query string, see %q and %Q)
    ;  %R: remote IP address
    ;  %s: status (response code)
    ;  %t: server time the request was received
    ;      it can accept a strftime(3) format:
    ;      %d/%b/%Y:%H:%M:%S %z (default)
    ;  %T: time the log has been written (the request has finished)
    ;      it can accept a strftime(3) format:
    ;      %d/%b/%Y:%H:%M:%S %z (default)
    ;  %u: remote user
    ;
    ; Default: "%R - %u %t \"%m %r\" %s"
    ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
     
    ; The log file for slow requests
    ; Default Value: not set
    ; Note: slowlog is mandatory if request_slowlog_timeout is set
    ;slowlog = log/$pool.log.slow
     
    ; The timeout for serving a single request after which a PHP backtrace will be
    ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_slowlog_timeout = 0
     
    ; The timeout for serving a single request after which the worker process will
    ; be killed. This option should be used when the 'max_execution_time' ini option
    ; does not stop script execution for some reason. A value of '0' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_terminate_timeout = 0
     
    ; Set open file descriptor rlimit.
    ; Default Value: system defined value
    ;rlimit_files = 1024
     
    ; Set max core size rlimit.
    ; Possible Values: 'unlimited' or an integer greater or equal to 0
    ; Default Value: system defined value
    ;rlimit_core = 0
     
    ; Chroot to this directory at the start. This value must be defined as an
    ; absolute path. When this value is not set, chroot is not used.
    ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
    ; of its subdirectories. If the pool prefix is not set, the global prefix
    ; will be used instead.
    ; Note: chrooting is a great security feature and should be used whenever 
    ;       possible. However, all PHP paths will be relative to the chroot
    ;       (error_log, sessions.save_path, ...).
    ; Default Value: not set
    ;chroot = 
     
    ; Chdir to this directory at the start.
    ; Note: relative path can be used.
    ; Default Value: current directory or / when chroot
    ;chdir = /var/www
     
    ; Redirect worker stdout and stderr into main error log. If not set, stdout and
    ; stderr will be redirected to /dev/null according to FastCGI specs.
    ; Note: on highloaded environement, this can cause some delay in the page
    ; process time (several ms).
    ; Default Value: no
    ;catch_workers_output = yes
    
    ; Clear environment in FPM workers
    ; Prevents arbitrary environment variables from reaching FPM worker processes
    ; by clearing the environment in workers before env vars specified in this
    ; pool configuration are added.
    ; Setting to "no" will make all environment variables available to PHP code
    ; via getenv(), $_ENV and $_SERVER.
    ; Default Value: yes
    ;clear_env = no
    
    ; Limits the extensions of the main script FPM will allow to parse. This can
    ; prevent configuration mistakes on the web server side. You should only limit
    ; FPM to .php extensions to prevent malicious users to use other extensions to
    ; exectute php code.
    ; Note: set an empty value to allow all extensions.
    ; Default Value: .php
    ;security.limit_extensions = .php .php3 .php4 .php5
     
    ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
    ; the current environment.
    ; Default Value: clean env
    ;env[HOSTNAME] = $HOSTNAME
    ;env[PATH] = /usr/local/bin:/usr/bin:/bin
    ;env[TMP] = /tmp
    ;env[TMPDIR] = /tmp
    ;env[TEMP] = /tmp
    
    ; Additional php.ini defines, specific to this pool of workers. These settings
    ; overwrite the values previously defined in the php.ini. The directives are the
    ; same as the PHP SAPI:
    ;   php_value/php_flag             - you can set classic ini defines which can
    ;                                    be overwritten from PHP call 'ini_set'. 
    ;   php_admin_value/php_admin_flag - these directives won't be overwritten by
    ;                                     PHP call 'ini_set'
    ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
    
    ; Defining 'extension' will load the corresponding shared extension from
    ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
    ; overwrite previously defined php.ini values, but will append the new value
    ; instead.
    
    ; Note: path INI options can be relative and will be expanded with the prefix
    ; (pool, global or /usr/local/Cellar/php@5.6/5.6.36)
    
    ; Default Value: nothing is defined by default except the values in php.ini and
    ;                specified at startup with the -d argument
    ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
    ;php_flag[display_errors] = off
    ;php_admin_value[error_log] = /var/log/fpm-php.www.log
    ;php_admin_flag[log_errors] = on
    ;php_admin_value[memory_limit] = 32M
    
    php_value[mbstring.http_input]  = pass
    php_value[mbstring.http_output]  = pass
    php_value[always_populate_raw_post_data] = -1
          
        
  5. Create the file /usr/local/etc/php/5.6/php-fpm.d/www2.conf and copy the following scripts to this file:

          
    ; Start a new pool named 'www'.
    ; the variable $pool can we used in any directive and will be replaced by the
    ; pool name ('www' here)
    [www2]
    
    ; Per pool prefix
    ; It only applies on the following directives:
    ; - 'access.log'
    ; - 'slowlog'
    ; - 'listen' (unixsocket)
    ; - 'chroot'
    ; - 'chdir'
    ; - 'php_values'
    ; - 'php_admin_values'
    ; When not set, the global prefix (or /usr/local/Cellar/php@5.6/5.6.36) applies instead.
    ; Note: This directive can also be relative to the global prefix.
    ; Default Value: none
    ;prefix = /path/to/pools/$pool
    
    ; Unix user/group of processes
    ; Note: The user is mandatory. If the group is not set, the default user's group
    ;       will be used.
    user = webfoobar
    group = staff
    
    ; The address on which to accept FastCGI requests.
    ; Valid syntaxes are:
    ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
    ;                            a specific port;
    ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
    ;                            a specific port;
    ;   'port'                 - to listen on a TCP socket to all IPv4 addresses on a
    ;                            specific port;
    ;   '[::]:port'            - to listen on a TCP socket to all addresses
    ;                            (IPv6 and IPv4-mapped) on a specific port;
    ;   '/path/to/unix/socket' - to listen on a unix socket.
    ; Note: This value is mandatory.
    listen = 127.0.0.1:9002
    
    ; Set listen(2) backlog.
    ; Default Value: 65535 (-1 on FreeBSD and OpenBSD)
    ;listen.backlog = 65535
    
    ; Set permissions for unix socket, if one is used. In Linux, read/write
    ; permissions must be set in order to allow connections from a web server. Many
    ; BSD-derived systems allow connections regardless of permissions. 
    ; Default Values: user and group are set as the running user
    ;                 mode is set to 0660
    ;listen.owner = _www
    ;listen.group = _www
    ;listen.mode = 0660
    ; When POSIX Access Control Lists are supported you can set them using
    ; these options, value is a comma separated list of user/group names.
    ; When set, listen.owner and listen.group are ignored
    ;listen.acl_users =
    ;listen.acl_groups =
     
    ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
    ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
    ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
    ; must be separated by a comma. If this value is left blank, connections will be
    ; accepted from any ip address.
    ; Default Value: any
    ;listen.allowed_clients = 127.0.0.1
    
    ; Specify the nice(2) priority to apply to the pool processes (only if set)
    ; The value can vary from -19 (highest priority) to 20 (lower priority)
    ; Note: - It will only work if the FPM master process is launched as root
    ;       - The pool processes will inherit the master process priority
    ;         unless it specified otherwise
    ; Default Value: no set
    ; process.priority = -19
    
    ; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
    ; or group is differrent than the master process user. It allows to create process
    ; core dump and ptrace the process for the pool user.
    ; Default Value: no
    ; process.dumpable = yes
    
    ; Choose how the process manager will control the number of child processes.
    ; Possible Values:
    ;   static  - a fixed number (pm.max_children) of child processes;
    ;   dynamic - the number of child processes are set dynamically based on the
    ;             following directives. With this process management, there will be
    ;             always at least 1 children.
    ;             pm.max_children      - the maximum number of children that can
    ;                                    be alive at the same time.
    ;             pm.start_servers     - the number of children created on startup.
    ;             pm.min_spare_servers - the minimum number of children in 'idle'
    ;                                    state (waiting to process). If the number
    ;                                    of 'idle' processes is less than this
    ;                                    number then some children will be created.
    ;             pm.max_spare_servers - the maximum number of children in 'idle'
    ;                                    state (waiting to process). If the number
    ;                                    of 'idle' processes is greater than this
    ;                                    number then some children will be killed.
    ;  ondemand - no children are created at startup. Children will be forked when
    ;             new requests will connect. The following parameter are used:
    ;             pm.max_children           - the maximum number of children that
    ;                                         can be alive at the same time.
    ;             pm.process_idle_timeout   - The number of seconds after which
    ;                                         an idle process will be killed.
    ; Note: This value is mandatory.
    pm = dynamic
    
    ; The number of child processes to be created when pm is set to 'static' and the
    ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
    ; This value sets the limit on the number of simultaneous requests that will be
    ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
    ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
    ; CGI. The below defaults are based on a server without much resources. Don't
    ; forget to tweak pm.* to fit your needs.
    ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
    ; Note: This value is mandatory.
    pm.max_children = 5
    
    ; The number of child processes created on startup.
    ; Note: Used only when pm is set to 'dynamic'
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 2
    
    ; The desired minimum number of idle server processes.
    ; Note: Used only when pm is set to 'dynamic'
    ; Note: Mandatory when pm is set to 'dynamic'
    pm.min_spare_servers = 1
    
    ; The desired maximum number of idle server processes.
    ; Note: Used only when pm is set to 'dynamic'
    ; Note: Mandatory when pm is set to 'dynamic'
    pm.max_spare_servers = 3
    
    ; The number of seconds after which an idle process will be killed.
    ; Note: Used only when pm is set to 'ondemand'
    ; Default Value: 10s
    ;pm.process_idle_timeout = 10s;
     
    ; The number of requests each child process should execute before respawning.
    ; This can be useful to work around memory leaks in 3rd party libraries. For
    ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
    ; Default Value: 0
    ;pm.max_requests = 500
    
    ; The URI to view the FPM status page. If this value is not set, no URI will be
    ; recognized as a status page. It shows the following informations:
    ;   pool                 - the name of the pool;
    ;   process manager      - static, dynamic or ondemand;
    ;   start time           - the date and time FPM has started;
    ;   start since          - number of seconds since FPM has started;
    ;   accepted conn        - the number of request accepted by the pool;
    ;   listen queue         - the number of request in the queue of pending
    ;                          connections (see backlog in listen(2));
    ;   max listen queue     - the maximum number of requests in the queue
    ;                          of pending connections since FPM has started;
    ;   listen queue len     - the size of the socket queue of pending connections;
    ;   idle processes       - the number of idle processes;
    ;   active processes     - the number of active processes;
    ;   total processes      - the number of idle + active processes;
    ;   max active processes - the maximum number of active processes since FPM
    ;                          has started;
    ;   max children reached - number of times, the process limit has been reached,
    ;                          when pm tries to start more children (works only for
    ;                          pm 'dynamic' and 'ondemand');
    ; Value are updated in real time.
    ; Example output:
    ;   pool:                 www
    ;   process manager:      static
    ;   start time:           01/Jul/2011:17:53:49 +0200
    ;   start since:          62636
    ;   accepted conn:        190460
    ;   listen queue:         0
    ;   max listen queue:     1
    ;   listen queue len:     42
    ;   idle processes:       4
    ;   active processes:     11
    ;   total processes:      15
    ;   max active processes: 12
    ;   max children reached: 0
    ;
    ; By default the status page output is formatted as text/plain. Passing either
    ; 'html', 'xml' or 'json' in the query string will return the corresponding
    ; output syntax. Example:
    ;   http://www.foo.bar/status
    ;   http://www.foo.bar/status?json
    ;   http://www.foo.bar/status?html
    ;   http://www.foo.bar/status?xml
    ;
    ; By default the status page only outputs short status. Passing 'full' in the
    ; query string will also return status for each pool process.
    ; Example: 
    ;   http://www.foo.bar/status?full
    ;   http://www.foo.bar/status?json&full
    ;   http://www.foo.bar/status?html&full
    ;   http://www.foo.bar/status?xml&full
    ; The Full status returns for each process:
    ;   pid                  - the PID of the process;
    ;   state                - the state of the process (Idle, Running, ...);
    ;   start time           - the date and time the process has started;
    ;   start since          - the number of seconds since the process has started;
    ;   requests             - the number of requests the process has served;
    ;   request duration     - the duration in µs of the requests;
    ;   request method       - the request method (GET, POST, ...);
    ;   request URI          - the request URI with the query string;
    ;   content length       - the content length of the request (only with POST);
    ;   user                 - the user (PHP_AUTH_USER) (or '-' if not set);
    ;   script               - the main script called (or '-' if not set);
    ;   last request cpu     - the %cpu the last request consumed
    ;                          it's always 0 if the process is not in Idle state
    ;                          because CPU calculation is done when the request
    ;                          processing has terminated;
    ;   last request memory  - the max amount of memory the last request consumed
    ;                          it's always 0 if the process is not in Idle state
    ;                          because memory calculation is done when the request
    ;                          processing has terminated;
    ; If the process is in Idle state, then informations are related to the
    ; last request the process has served. Otherwise informations are related to
    ; the current request being served.
    ; Example output:
    ;   ************************
    ;   pid:                  31330
    ;   state:                Running
    ;   start time:           01/Jul/2011:17:53:49 +0200
    ;   start since:          63087
    ;   requests:             12808
    ;   request duration:     1250261
    ;   request method:       GET
    ;   request URI:          /test_mem.php?N=10000
    ;   content length:       0
    ;   user:                 -
    ;   script:               /home/fat/web/docs/php/test_mem.php
    ;   last request cpu:     0.00
    ;   last request memory:  0
    ;
    ; Note: There is a real-time FPM status monitoring sample web page available
    ;       It's available in: /usr/local/Cellar/php@5.6/5.6.36/share/php/fpm/status.html
    ;
    ; Note: The value must start with a leading slash (/). The value can be
    ;       anything, but it may not be a good idea to use the .php extension or it
    ;       may conflict with a real PHP file.
    ; Default Value: not set 
    ;pm.status_path = /status
     
    ; The ping URI to call the monitoring page of FPM. If this value is not set, no
    ; URI will be recognized as a ping page. This could be used to test from outside
    ; that FPM is alive and responding, or to
    ; - create a graph of FPM availability (rrd or such);
    ; - remove a server from a group if it is not responding (load balancing);
    ; - trigger alerts for the operating team (24/7).
    ; Note: The value must start with a leading slash (/). The value can be
    ;       anything, but it may not be a good idea to use the .php extension or it
    ;       may conflict with a real PHP file.
    ; Default Value: not set
    ;ping.path = /ping
    
    ; This directive may be used to customize the response of a ping request. The
    ; response is formatted as text/plain with a 200 response code.
    ; Default Value: pong
    ;ping.response = pong
    
    ; The access log file
    ; Default: not set
    ;access.log = log/$pool.access.log
    
    ; The access log format.
    ; The following syntax is allowed
    ;  %%: the '%' character
    ;  %C: %CPU used by the request
    ;      it can accept the following format:
    ;      - %{user}C for user CPU only
    ;      - %{system}C for system CPU only
    ;      - %{total}C  for user + system CPU (default)
    ;  %d: time taken to serve the request
    ;      it can accept the following format:
    ;      - %{seconds}d (default)
    ;      - %{miliseconds}d
    ;      - %{mili}d
    ;      - %{microseconds}d
    ;      - %{micro}d
    ;  %e: an environment variable (same as $_ENV or $_SERVER)
    ;      it must be associated with embraces to specify the name of the env
    ;      variable. Some exemples:
    ;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
    ;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
    ;  %f: script filename
    ;  %l: content-length of the request (for POST request only)
    ;  %m: request method
    ;  %M: peak of memory allocated by PHP
    ;      it can accept the following format:
    ;      - %{bytes}M (default)
    ;      - %{kilobytes}M
    ;      - %{kilo}M
    ;      - %{megabytes}M
    ;      - %{mega}M
    ;  %n: pool name
    ;  %o: output header
    ;      it must be associated with embraces to specify the name of the header:
    ;      - %{Content-Type}o
    ;      - %{X-Powered-By}o
    ;      - %{Transfert-Encoding}o
    ;      - ....
    ;  %p: PID of the child that serviced the request
    ;  %P: PID of the parent of the child that serviced the request
    ;  %q: the query string 
    ;  %Q: the '?' character if query string exists
    ;  %r: the request URI (without the query string, see %q and %Q)
    ;  %R: remote IP address
    ;  %s: status (response code)
    ;  %t: server time the request was received
    ;      it can accept a strftime(3) format:
    ;      %d/%b/%Y:%H:%M:%S %z (default)
    ;  %T: time the log has been written (the request has finished)
    ;      it can accept a strftime(3) format:
    ;      %d/%b/%Y:%H:%M:%S %z (default)
    ;  %u: remote user
    ;
    ; Default: "%R - %u %t \"%m %r\" %s"
    ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
     
    ; The log file for slow requests
    ; Default Value: not set
    ; Note: slowlog is mandatory if request_slowlog_timeout is set
    ;slowlog = log/$pool.log.slow
     
    ; The timeout for serving a single request after which a PHP backtrace will be
    ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_slowlog_timeout = 0
     
    ; The timeout for serving a single request after which the worker process will
    ; be killed. This option should be used when the 'max_execution_time' ini option
    ; does not stop script execution for some reason. A value of '0' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_terminate_timeout = 0
     
    ; Set open file descriptor rlimit.
    ; Default Value: system defined value
    ;rlimit_files = 1024
     
    ; Set max core size rlimit.
    ; Possible Values: 'unlimited' or an integer greater or equal to 0
    ; Default Value: system defined value
    ;rlimit_core = 0
     
    ; Chroot to this directory at the start. This value must be defined as an
    ; absolute path. When this value is not set, chroot is not used.
    ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
    ; of its subdirectories. If the pool prefix is not set, the global prefix
    ; will be used instead.
    ; Note: chrooting is a great security feature and should be used whenever 
    ;       possible. However, all PHP paths will be relative to the chroot
    ;       (error_log, sessions.save_path, ...).
    ; Default Value: not set
    ;chroot = 
     
    ; Chdir to this directory at the start.
    ; Note: relative path can be used.
    ; Default Value: current directory or / when chroot
    ;chdir = /var/www
     
    ; Redirect worker stdout and stderr into main error log. If not set, stdout and
    ; stderr will be redirected to /dev/null according to FastCGI specs.
    ; Note: on highloaded environement, this can cause some delay in the page
    ; process time (several ms).
    ; Default Value: no
    ;catch_workers_output = yes
    
    ; Clear environment in FPM workers
    ; Prevents arbitrary environment variables from reaching FPM worker processes
    ; by clearing the environment in workers before env vars specified in this
    ; pool configuration are added.
    ; Setting to "no" will make all environment variables available to PHP code
    ; via getenv(), $_ENV and $_SERVER.
    ; Default Value: yes
    ;clear_env = no
    
    ; Limits the extensions of the main script FPM will allow to parse. This can
    ; prevent configuration mistakes on the web server side. You should only limit
    ; FPM to .php extensions to prevent malicious users to use other extensions to
    ; exectute php code.
    ; Note: set an empty value to allow all extensions.
    ; Default Value: .php
    ;security.limit_extensions = .php .php3 .php4 .php5
     
    ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
    ; the current environment.
    ; Default Value: clean env
    ;env[HOSTNAME] = $HOSTNAME
    ;env[PATH] = /usr/local/bin:/usr/bin:/bin
    ;env[TMP] = /tmp
    ;env[TMPDIR] = /tmp
    ;env[TEMP] = /tmp
    
    ; Additional php.ini defines, specific to this pool of workers. These settings
    ; overwrite the values previously defined in the php.ini. The directives are the
    ; same as the PHP SAPI:
    ;   php_value/php_flag             - you can set classic ini defines which can
    ;                                    be overwritten from PHP call 'ini_set'. 
    ;   php_admin_value/php_admin_flag - these directives won't be overwritten by
    ;                                     PHP call 'ini_set'
    ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
    
    ; Defining 'extension' will load the corresponding shared extension from
    ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
    ; overwrite previously defined php.ini values, but will append the new value
    ; instead.
    
    ; Note: path INI options can be relative and will be expanded with the prefix
    ; (pool, global or /usr/local/Cellar/php@5.6/5.6.36)
    
    ; Default Value: nothing is defined by default except the values in php.ini and
    ;                specified at startup with the -d argument
    ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
    ;php_flag[display_errors] = off
    ;php_admin_value[error_log] = /var/log/fpm-php.www.log
    ;php_admin_flag[log_errors] = on
    ;php_admin_value[memory_limit] = 32M
    
    php_value[mbstring.http_input]  = pass
    php_value[mbstring.http_output]  = pass
    php_value[always_populate_raw_post_data] = -1
          
        
  6. Start the PHP 5.6:

          
    sudo brew services start php@5.6
          
        
  7. Create Nginx's microcache directory:

          
    mkdir -p /usr/local/var/cache/nginx/microcache
          
        
  8. Edit the file /usr/local/etc/nginx/nginx.conf and add the following scripts inside http {} above this line of code include servers/*;:

          
    ## Modify HTTP header
    include opt/mod_header.conf;
    ## Include the map to block HTTP methods.
    include opt/block_http_methods.conf;
    ## Support the X-Forwarded-Proto header for fastcgi.
    include opt/x_forwarded_proto.conf;
    ## Include the caching setup. 
    ## Needed for using Drupal with an external cache.
    include opt/apps/drupal/external_cache.conf;
    ## Include the upstream servers.
    include opt/upstream_tcp.conf;
    ## Microcache zone definition.
    include opt/microcache_zone.conf;
          
        
  9. Create opt/apps/drupal directory inside nginx folder:

          
    mkdir -p /usr/local/etc/nginx/opt/apps/drupal
          
        
  10. Create the file /usr/local/etc/nginx/opt/block_http_methods.conf and copy the following scripts to this file:

          
    ## This file contains a map directive that is used to block the
    ## invocation of HTTP methods. Out of the box it allows for HEAD, GET and POST.
    
    map $request_method $not_allowed_method {
      default 1;
      GET 0;
      HEAD 0;
      POST 0;
    }
          
        
  11. Create the file /usr/local/etc/nginx/opt/hotlinking_protection_allowed_hosts.conf and copy the following scripts to this file:

          
    ## Hotlinking protection for images. Include it in any context you
    ## want. Adjust the list of allowed referrers to your liking.
    valid_referers none blocked 
      ph.search.yahoo.com
      www.yahoo.com 
      www.google.com.ph 
      www.google.com 
      www.facebook.com
      twitter.com
      plus.google.com
      www.instagram.com
      www.linkedin.com
      www.pinterest.com
      drupal6site.test;
    
    if ($invalid_referer) {
      return 200 "No image hotlinking allowed!\n";
    }
          
        
  12. Create the file /usr/local/etc/nginx/opt/microcache_auth.conf and copy the following scripts to this file:

          
    ## The cache zone referenced.
    fastcgi_cache microcache;
    ## The cache key.
    fastcgi_cache_key $cache_uid@$scheme$request_method$host$request_uri;
    
    ## For 200 and 301 make the cache valid for 10s.
    fastcgi_cache_valid 200 301 10s;
    ## For 302 make it valid for 1 minute.
    fastcgi_cache_valid 302 1m;
    ## For 404 make it valid 1 second.
    fastcgi_cache_valid 404 1s;
    ## If there are any upstream errors or the item has expired use
    ## whatever it is available.
    fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503 off;
    ## The Cache-Control and Expires headers should be delivered untouched
    ## from the upstream to the client.
    fastcgi_ignore_headers Cache-Control Expires;
    fastcgi_pass_header Set-Cookie;
    fastcgi_pass_header Cookie;
    ## Bypass the cache.
    fastcgi_cache_bypass $no_auth_cache;
    fastcgi_no_cache $no_auth_cache;
    
    ## To avoid any interaction with the cache control headers we expire
    ## everything on this location immediately.
    expires epoch;
    
    ## Cache locking mechanism for protecting the backend of too many
    ## simultaneous requests.
    fastcgi_cache_lock on;
    ## The default timeout, i.e., the time to way before forwarding the
    ## second request upstream if no reply as arrived in the meantime is 5s.
    fastcgi_cache_lock_timeout 5000; # in miliseconds.
          
        
  13. Create the file /usr/local/etc/nginx/opt/microcache_zone.conf and copy the following scripts to this file:

          
    ## Defining the FastCGI cache zone for the microcache as presented at:
    ## http://fennb.com/microcaching-speed-your-app-up-250x-with-no-n.
    
    ## If youre using a Nginx version greater than 1.1.1 then you can
    ## tweak the Tweaking of the cache loader parameters.
    ## Cf. http://forum.nginx.org/read.php?21,213197,213209#msg-213209 for
    ## rationale.
    fastcgi_cache_path /usr/local/var/cache/nginx/microcache levels=1:2 keys_zone=microcache:5M max_size=1G inactive=2h loader_threshold=2592000000 loader_sleep=1 loader_files=100000;
          
        
  14. Create the file /usr/local/etc/nginx/opt/mod_header.conf and copy the following scripts to this file:

          
    ## Modify HTTP header
    
    ## Enable the builtin cross-site scripting (XSS) filter available
    ## in modern browsers.  Usually enabled by default we just
    ## reinstate in case it has been somehow disabled for this
    ## particular server instance.
    ## https://www.owasp.org/index.php/List_of_useful_HTTP_headers.
    add_header X-XSS-Protection '1; mode=block';
    
    ## Enable clickjacking protection in modern browsers. Available in
    ## IE8 also. See
    ## https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header
    ## This may conflicts with pseudo streaming (at least with Nginx version 1.0.12).
    ## Uncomment the line below if you're not using media streaming.
    ## For sites being framing on the same domain uncomment the line below.
    add_header X-Frame-Options SAMEORIGIN;
    ## For sites accepting to be framed in any context comment the
    ## line below.
    #add_header X-Frame-Options DENY;
    
    ## When serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header,
    ## to disable content-type sniffing on some browsers.
    ## https://www.owasp.org/index.php/List_of_useful_HTTP_headers
    ## currently suppoorted in IE > 8 http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx
    ## http://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx
    ## 'soon' on Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=471020
    ## Block MIME type sniffing on IE.
    add_header X-Content-Options nosniff;
    
    ## Add a cache miss/hit status header. This can be disabled if not including
    ## any of the apps/drupal/microcache* files.
    add_header X-Micro-Cache $upstream_cache_status;
          
        
  15. Create the file /usr/local/etc/nginx/opt/php_handler.conf and copy the following scripts to this file:

          
    ## PHP handler
    
    include opt/php_pass.conf;
    include opt/microcache_auth.conf;
          
        
  16. Create the file /usr/local/etc/nginx/opt/php_pass.conf and copy the following scripts to this file:

          
    ## Fastcgi configuration
    
    ## 1. Parameters.
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    
    fastcgi_param SCRIPT_NAME /index.php;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
    
    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    ## PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param REDIRECT_STATUS 200;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTP_HTTPS $https;
    fastcgi_param HTTPS $https;
    fastcgi_pass $phppass;
    
    ## 2. Nginx FCGI specific directives.
    fastcgi_buffers 256 4k;
    fastcgi_intercept_errors on;
    ## Allow 4 hrs - pass timeout responsibility to upstream.
    fastcgi_read_timeout 14400;
    fastcgi_index index.php;
    ## Hide the X-Drupal-Cache header provided by Pressflow.
    fastcgi_hide_header 'X-Drupal-Cache';
    ## Hide the Drupal 7 header X-Generator.
    fastcgi_hide_header 'X-Generator';
          
        
  17. Create the file /usr/local/etc/nginx/opt/upstream_tcp.conf and copy the following scripts to this file:

          
    ## Upstream configuration for PHP FastCGI.
    
    ## Add as many servers as needed:
    ## Cf. http://wiki.nginx.org/HttpUpstreamModule.
    ## Note that this configuration assumes by default that keepalive
    ## upstream connections are supported and that you have a Nginx
    ## version with the fair load balancer.
    
    ## Add as many servers as needed. Cf. http://wiki.nginx.org/HttpUpstreamModule.
    upstream drupal6 {
      ## Use the least connection algorithm for load balancing. This
      ## algorithm was introduced in versions 1.3.1 and 1.2.2.
      least_conn;
    
      server 127.0.0.1:9001;
      server 127.0.0.1:9002;
      ## Create a backend connection cache. Note that this requires
      ## Nginx version greater or equal to 1.1.4.
      ## Cf. http://nginx.org/en/CHANGES.
      keepalive 5;
    }
    
    ## The upstreams below are used only for monitoring php-fpm status,
    
    ## The PHP TCP upstream that corresponds to the first pool: www1.
    upstream www1 {
      server 127.0.0.1:9001;
    }
    
    ## The PHP TCP upstream that corresponds to the second pool: www2.
    upstream www2 {
      server 127.0.0.1:9002;
    }
          
        
  18. Create the file /usr/local/etc/nginx/opt/x_forwarded_proto.conf and copy the following scripts to this file:

          
    ## Support the X-Forwarded-Proto header for fastcgi.
    map $http_x_forwarded_proto $fastcgi_https {
      default $https;
      http '';
      https on;
    }
          
        
  19. Create the file /usr/local/etc/nginx/opt/apps/drupal/boost.conf and copy the following scripts to this file:

          
    ## Boost configuration
    gzip_static on;
    
    ## Error page handler for the case where $no_boost_cache is 1, POST
    ## request or authenticated.
    error_page 418 = @drupal;
    
    ## If $no_boost_cache is 1 then it means that Boost session cookie
    ## is present or uri has wrong dir. So serve the dynamic page.
    if ($no_boost_cache) {
      return 418; # I'm a teapot/I can't get no cachifaction
    }
    
    ## No caching for POST requests.
    if ($request_method = POST) {
      return 418;
    }
    
    ## Now for some header tweaking. We use a date that differs
    ## from stock Drupal.
    add_header Expires "Tue, 25 Dec 1977 03:45:00 GMT";
    ## We bypass all delays in the post-check and pre-check
    ## parameters of Cache-Control. Both set to 0.
    add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
    add_header X-DCache "Boost";
    ## Inheritance Rules for add_header Directives
    ## Because this 'server' block contains another 'add_header' directive,
    ## we must redeclare the 'add_header' from 'http' context
    include opt/mod_header.conf;
    ## Boost doesn't set a charset.
    charset utf-8;
          
        
  20. Create the file /usr/local/etc/nginx/opt/apps/drupal/core.conf and copy the following scripts to this file:

          
    ## Nginx configuration for Drupal. This configuration makes use of
    ## drush (http:///drupal.org/project/drush) for site maintenance
    ## and like tasks:
    ##
    ## 1. Run the cronjobs.
    ## 2. Run the DB and code updates: drush up or drush upc followed by
    ##    drush updb to run any DB updates required by the code upgrades
    ##    that were performed.
    ## 3. Disabling of xmlrpc.xml and update.php: all updates are now
    ##    handled through drush.
    
    ## Named location
    include opt/apps/drupal/named_location.conf;
    
    ## The 'default' location.
    location / {
      ## Make Drupal handle any 404 errors.
      error_page 404 /index.php;
    
      ## Drupal generated static files
      include opt/apps/drupal/static_files_handler.conf;
      
      try_files $uri $uri/ @cache;
    }
    
    ## Drupal index.
    location = /index.php {
      include opt/apps/drupal/boost.conf;
      ## We try each boost URI in succession, if every one of them
      ## fails then hand it to Drupal.
      try_files /cache/normal/$host/_${args}.html /cache/normal/$host/_${args}.html.gz /cache/$host/0.html /cache/$host/0/index.html @drupal;
    }
    
    ## Drupal install.
    location = /install.php {
      include opt/php_handler.conf;
    }
    
    ## Boost stats.
    location = /boost_stats.php {
      include opt/php_handler.conf;
    }
    
    ## Any other attempt to access PHP files returns a 404.
    location ~* ^.+\.php$ {
      return 404;
    }
          
        
  21. Create the file /usr/local/etc/nginx/opt/apps/drupal/external_cache.conf and copy the following scripts to this file:

          
    ## Testing if we should be serving content from cache or not. This is
    ## needed for any Drupal setup that uses an external cache.
    
    ## Let Ajax calls go through.
    map $uri $no_cache_ajax {
      default 0;
      /system/ajax 1;
    }
    
    ## Test Boost session cookie being present. If there is, then no
    ## caching is to be done.
    map $http_cookie $no_boost_cache_cookie {
      default 0;
      #~DRUPAL_UID 1;
      ~nocache=1 1; # Custom logged in/out indicator
    }
    ## Boost URI watch list
    map $request_uri $no_boost_cache_uri {
      default 0;
      ~*^/(admin|cache|misc|modules|sites|system|openid|themes|node/add|comment/reply)|(/(edit|user|user/(login|password|register)))$ 1;
    }
    ## Combine both results to get the cache bypassing mapping.
    map $no_boost_cache_cookie$no_boost_cache_uri $no_boost_cache {
      default 1;
      00 0;
    }
    
    ## Testing for the session cookie being present. If there is, then no
    ## caching is to be done. Note that this is for someone using either
    ## Drupal 7 pressflow or stock Drupal 6 core with no_anon
    ## (http://drupal.org/project/no_anon).
    map $http_cookie $no_cache_cookie {
      default 0;
      #~SESS 1; # PHP session cookie
      ~nocache=1 1; # Custom logged in/out indicator
    }
    
    ## Combine both results to get the cache bypassing mapping.
    map $no_cache_ajax$no_cache_cookie $no_auth_cache {
      default 1;
      00 0;
    }
    
    ## Cache bypassing mapping (auth).
    map $no_cache_ajax $no_cache {
      default 0;
      1 1;
    }
    
    ## Set a cache_uid variable for authenticated users.
    map $http_cookie $cache_uid {
      default nil;
      ~SESS[[:alnum:]]+=(?[[:graph:]]+) $session_id;
    }
          
        
  22. Create the file /usr/local/etc/nginx/opt/apps/drupal/named_location.conf and copy the following scripts to this file:

          
    ## Restrict access to the strictly necessary PHP files. Reducing the
    ## scope for exploits. Handling of PHP code and the Drupal event loop.
    location @drupal {
      include opt/php_handler.conf;
    }
    
    ## We define a named location for the Boost cache.
    location @cache {
      include opt/apps/drupal/boost.conf;
      ## We try each boost URI in succession, if every one of them
      ## fails then hand it to Drupal.
      try_files /cache/normal/$host${uri}_${args}.html /cache/normal/$host${uri}_${args}.xml /cache/normal/$host${uri}_${args}.json /cache/normal/$host${uri}_${args}.html.gz /cache/normal/$host${uri}_${args}.xml.gz /cache/normal/$host${uri}_${args}.json.gz /cache/perm/$host${uri}_.css /cache/perm/$host${uri}_.js /cache/$host/0$uri.html /cache/$host/0${uri}/index.html @drupal;
    }
    
    ## Return an in memory 1x1 transparent GIF.
    location @empty {
      expires 30d;
      empty_gif;
    }
    
    ## Redirect Pagespeed optimized resources that returns 404 to 
    ## original resource.
    location @orig-resource {
      return 302 $scheme://$server_name$orig_resource_uri;
    }
          
        
  23. Create the file /usr/local/etc/nginx/opt/apps/drupal/static_files_handler.conf and copy the following scripts to this file:

          
    ## Using a nested location is the 'correct' way to use regexes.
    
    ## Pagespeed optimized resources that returns 404, redirect to original resource
    location ~* (.+)/x(.+),(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
      ## Handle resources with query string and Pagespeed optimized resources with
      ## file name prefixed with x (eg. xMyImage.png,qitok=qwer.pagespeed.asdf.webp)
      error_page 404 = @orig-resource;
      set $orig_resource_uri $1/$2?$3;
      try_files $uri $uri/ $orig_resource_uri;
    }
    location ~* (.+),q(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
      ## Handle Pagespeed optimized resources with file name qcache_bypass=123
      ## (eg. MyImage.png,qcache_bypass=1472891719.pagespeed.ce.asdf.png)
      error_page 404 = @orig-resource;
      set $orig_resource_uri $1?$2;
      try_files $uri $uri/ $orig_resource_uri;
    }
    location ~* (.+),(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
      ## Handle resources with query string
      error_page 404 = @orig-resource;
      set $orig_resource_uri $1?$2;
      try_files $uri $uri/ $orig_resource_uri;
    }
    location ~* (.+)/x(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
      ## Handle Pagespeed optimized resources with file name prefixed with x
      ## (eg. xMyImage.png.pagespeed.asdf.webp)
      error_page 404 = @orig-resource;
      set $orig_resource_uri $1/$2;
      try_files $uri $uri/ $orig_resource_uri;
    }
    location ~* (.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
      ## Default handler
      error_page 404 = @orig-resource;
      set $orig_resource_uri $1;
      try_files $uri $uri/ $orig_resource_uri;
    }
    
    ## Regular private file serving (i.e. handled by Drupal).
    location ^~ /system/files/ {
      include opt/php_pass.conf;
    
      ## For not signalling a 404 in the error log whenever the
      ## system/files directory is accessed add the line below.
      ## Note that the 404 is the intended behaviour.
      log_not_found off;
    }
    
    ## Trying to access private files directly returns a 404.
    location ^~ /sites/[\.\-[:alnum:]]+/files/private/ {
      internal;
    }
    location ^~ /sites/[\.\-[:alnum:]]+/private/ {
      internal;
    }
    
    ## Support for the file_force module
    ## http://drupal.org/project/file_force.
    location ^~ /system/files_force/ {
      include opt/php_pass.conf;
    
      ## For not signalling a 404 in the error log whenever the
      ## system/files directory is accessed add the line below.
      ## Note that the 404 is the intended behaviour.
      log_not_found off;
    }
    
    ## If accessing an image generated by Drupal 6 imagecache, serve it
    ## directly if available, if not relay the request to Drupal to (re)generate
    ## the image.
    location ~* /imagecache/ {
      ## Image hotlinking protection. If you want hotlinking
      ## protection for your images uncomment the following line.
      include opt/hotlinking_protection_allowed_hosts.conf;
    
      access_log off;
      expires 30d;
      try_files $uri $uri/ @drupal;
    }
    
    ## Drupal 7 generated image handling, i.e., imagecache in core. See:
    ## http://drupal.org/node/371374.
    location ~* /files/styles/ {
      ## Image hotlinking protection. If you want hotlinking
      ## protection for your images uncomment the following line.
      include opt/hotlinking_protection_allowed_hosts.conf;
    
      access_log off;
      expires 30d;
      try_files $uri $uri/ @drupal;
    }
    
    ## Advanced Aggregation module CSS/JS
    ## support. http://drupal.org/project/advagg.
    location ~ ^/sites/[\.\-[:alnum:]]+/files/advagg_(?:css|js)/ {  
      location ~* (?:css|js)[_\-[:alnum:]]+\.(?:css|js)(\.gz)?$ {
        access_log off;
        expires max;
        gzip_static on;
        #gzip_http_version 1.0;
        #add_header Accept-Encoding 'gzip';
        #add_header Last-Modified 'Wed, 20 Jan 1988 04:20:42 GMT';
        add_header ETag '';
        add_header Accept-Ranges '';
        ## Set a far future Cache-Control header to 52 weeks and add no-transform
        ## to make Pagespeed bypass these CSS/JS optimized by advagg module
        add_header Cache-Control 'max-age=31449600, no-transform, public';
        ## Inheritance Rules for add_header Directives
        ## Because this 'server' block contains another 'add_header' directive,
        ## we must redeclare the 'add_header' from 'http' context
        include opt/mod_header.conf;
    
        try_files $uri $uri/ @drupal;
      }
    }
    
    ## All static files will be served directly.
    location ~* ^.+\.(?:css|cur|json|js|jpe?g|gif|htc|ico|png|txt|otf|ttf|eot|woff|svg|webp|webm|zip|gz|tar|rar)$ {
      set $test_http_origin a;
      if ($http_origin != "") {
        set $test_http_origin x;
      }
      if ($http_origin != "${scheme}://${host}") {
        set $test_http_origin "${test_http_origin}x";
      }
      if ($test_http_origin = xx) {
        add_header "Access-Control-Allow-Origin" "*";
      }
      access_log off;
      expires 30d;
      ## No need to bleed constant updates. Send the all shebang in one
      ## fell swoop.
      tcp_nodelay off;
      ## Set the OS file cache.
      open_file_cache max=3000 inactive=120s;
      open_file_cache_valid 45s;
      open_file_cache_min_uses 2;
      open_file_cache_errors off;
      try_files $uri $uri/ @cache;
    }
    
    ## PDFs and powerpoint files handling.
    location ~* ^.+\.(?:pdf|pptx?)$ {
      access_log off;
      expires 30d;
      ## No need to bleed constant updates. Send the all shebang in one
      ## fell swoop.
      tcp_nodelay off;
      try_files $uri $uri/ @drupal;
    }
    
    ## MP3 and Ogg/Vorbis files are served using AIO when supported. Your OS must support it.
    location ~ ^/sites/[\.\-[:alnum:]]+/files/audio/mp3 {
      location ~* .*\.mp3$ {
        access_log off;
        directio 4k; ## for XFS
        ## If you're using ext3 or similar uncomment the line below and comment the above.
        #directio 512; ## for ext3 or similar (block alignments)
        tcp_nopush off;
        #aio on;
        output_buffers 1 2M;
        try_files $uri $uri/ @drupal;
      }
    }
    
    location ~ ^/sites/[\.\-[:alnum:]]+/files/audio/ogg {
      location ~* .*\.ogg$ {
        access_log off;
        directio 4k; # for XFS
        ## If you're using ext3 or similar uncomment the line below and comment the above.
        #directio 512; ## for ext3 or similar (block alignments)
        tcp_nopush off;
        #aio on;
        output_buffers 1 2M;
        try_files $uri $uri/ @drupal;
      }
    }
    
    ## Pronunciation MP3 and Ogg/Vorbis files handling.
    location ~ ^/sites/[\.[:alnum:]]+/files/audio/pronunciation {
      location ~* ^.+\.(?:mp3|ogg?)$ {
        access_log off;
        directio 4k; ## for XFS
        ## If you're using ext3 or similar uncomment the line below and comment the above.
        #directio 512; ## for ext3 or similar (block alignments)
        tcp_nopush off;
        #aio on;
        output_buffers 1 2M;
        try_files $uri $uri/ @drupal;
      }
    }
    
    ## Pseudo streaming of FLV files:
    ## http://wiki.nginx.org/HttpFlvStreamModule.
    ## If pseudo streaming isn't working, try to comment
    ## out in nginx.conf line with:
    ## add_header X-Frame-Options SAMEORIGIN;
    location ~ ^/sites/[\.\-[:alnum:]]+/files/video/flv {
      location ~* .*\.flv$ {
        access_log off;
        flv;
        try_files $uri $uri/ @drupal;
      }
    }
    
    ## Pseudo streaming of H264/AAC files. This requires an Nginx
    ## version greater or equal to 1.0.7 for the stable branch and
    ## greater or equal to 1.1.3 for the development branch.
    ## Cf. http://nginx.org/en/docs/http/ngx_http_mp4_module.html.
    location ~ ^/sites/[\.\-[:alnum:]]+/files/video/mp4 { # videos
      location ~* .*\.(?:mp4|mov)$ {
        access_log off;
        mp4;
        mp4_buffer_size 1M;
        mp4_max_buffer_size 5M;
        try_files $uri $uri/ @drupal;
      }
    }
    
    location ~ ^/sites/[\.\-[:alnum:]]+/files/audio/m4a { # audios
      location ~* .*\.m4a$ {
        access_log off;
        mp4;
        mp4_buffer_size 1M;
        mp4_max_buffer_size 5M;
        try_files $uri $uri/ @drupal;
      }
    }
    
    ## Advanced Help module makes each module provided README available.
    location ^~ /help/ {
      location ~* ^/help/[^/]*/README\.txt$ {
        access_log off;
        include opt/php_pass.conf;
      }
    }
    
    ## Replicate the Apache  directive of Drupal standard
    ## .htaccess. Disable access to any code files. Return a 404 to curtail
    ## information disclosure. Hide also the text files.
    location ~* ^(?:.+\.(?:htaccess|gitignore|txt|engine|inc|info|install|make|module|profile|test|po|sh|.*sql|test|theme|twig|tpl(?:\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(/\.(?!well-known).*|/code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template|/composer\.(json|lock))$|^#.*#$|/.*\.php(\.sw[op]|\.bak|\.orig|\.save)+)$ {
      return 404;
    }
    
    ## Disallow access to .bzr, .git, .hg, .svn, .cvs directories:
    ## return 404 as not to disclose information.
    location ^~ /.bzr {
      return 404;
    }
    location ^~ /.git {
      return 404;
    }
    location ^~ /.hg {
      return 404;
    }
    location ^~ /.svn {
      return 404;
    }
    location ^~ /.cvs {
      return 404;
    }
    
    ## Disallow access to patches directory.
    location ^~ /patches {
      return 404;
    }
    
    ## Disallow access to drush backup directory.
    location ^~ /backup {
      return 404;
    }
    
    ## Disable access logs for robots.txt.
    location = /robots.txt {
      access_log off;
      ## Add support for the robotstxt module
      ## http://drupal.org/project/robotstxt.
      try_files $uri $uri/ @drupal;
    }
    
    ## Ads.txt support via site_verify module.
    ## http://drupal.org/project/site_verify.
    location = /ads.txt {
      access_log off;
      try_files $uri $uri/ @drupal;
    }
    
    ## RSS feed support.
    location = /rss.xml {
      try_files $uri $uri/ @drupal;
    }
    
    ## XML Sitemap support.
    location = /sitemap.xml {
      try_files $uri $uri/ @drupal;
    }
    
    ## Support for favicon. Return an 1x1 transparent GIF if it
    ## doesn't exist.
    location = /favicon.ico {
      expires 30d;
      try_files /favicon.png @empty;
    }
          
        
  24. Create the file /usr/local/etc/nginx/opt/servers/drupal6site.test.conf and copy the following scripts to this file:

          
    server {
      listen 80;
      server_name drupal6site.test;
      
      ## Logs
      access_log off;
      log_not_found off;
      error_log /Users/webfoobar/.valet/Log/nginx-error.log error;
    
      ## Filesystem root of the site and index.
      root /Users/webfoobar/Documents/htdocs/drupal6;
      index index.php;
      set $phppass drupal6;
    
      ## Configuration for Drupal.
      include opt/apps/drupal/core.conf;
    }
          
        

    Note: If you have other test domain sites for your legacy projects that needs to add, just repeat this step and rename the drupal6site.test to your other test domain site name.

  25. Restart nginx:

          
    sudo brew services restart nginx
          
        
  26. You can now run your Drupal 6 project without problem:

    Drupal 6 Install Page

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.