Skip to content

Instantly share code, notes, and snippets.

@abenevaut
Last active March 9, 2024 23:57
Show Gist options
  • Select an option

  • Save abenevaut/c6a70befbe19c545b996febff45cf360 to your computer and use it in GitHub Desktop.

Select an option

Save abenevaut/c6a70befbe19c545b996febff45cf360 to your computer and use it in GitHub Desktop.

Revisions

  1. abenevaut revised this gist Mar 9, 2024. 2 changed files with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions # Install nginx & phpbrew 7.3.10.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Install brew nginx with phpbrew php-fpm 7.3.10 on macOS (this installation allows to run nginx and php-fpm (from phpbrew) as root but chrooted with the current user - take care if there is multiple developper account on mac, that will potentially make trouble between accounts).
    File renamed without changes.
  2. abenevaut revised this gist Dec 10, 2019. No changes.
  3. abenevaut revised this gist Dec 10, 2019. No changes.
  4. abenevaut revised this gist Dec 10, 2019. No changes.
  5. abenevaut revised this gist Dec 10, 2019. No changes.
  6. abenevaut revised this gist Dec 10, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install-nginx-with-phpbrew.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // First follow https://gist.github.com/abenevaut/fd21704ead845e5bc14ca93fa8d0a18f but modify the line 17 like follow
    // and add +fpm to compile php-fpm
    // add +fpm to compile php-fpm
    phpbrew --debug install php-7.3.10 +gd +default +sqlite +mysql +fpm +bz2=/usr/local/Cellar/bzip2/1.0.6_1/ +zlib=/usr/local/Cellar/zlib/1.2.11/ -- --with-gd=shared

    brew install nginx
  7. abenevaut created this gist Dec 10, 2019.
    33 changes: 33 additions & 0 deletions install-nginx-with-phpbrew.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    // First follow https://gist.github.com/abenevaut/fd21704ead845e5bc14ca93fa8d0a18f but modify the line 17 like follow
    // and add +fpm to compile php-fpm
    phpbrew --debug install php-7.3.10 +gd +default +sqlite +mysql +fpm +bz2=/usr/local/Cellar/bzip2/1.0.6_1/ +zlib=/usr/local/Cellar/zlib/1.2.11/ -- --with-gd=shared

    brew install nginx

    sudo emacs /usr/local/etc/nginx/nginx.conf
    sudo emacs /Users/YOUR_MACOS_USERNAME/.phpbrew/php/php-7.1.29/etc/php-fpm.d/www.conf

    // In previous config files, we set user and group to run nginx and php-fpm as setted user and user group (logic)..
    // Now we should run nginx and php-fpm as root
    // So, we need to setup phpbrew for root user
    sudo su
    phpbrew init

    emacs ~/.phpbrew/bashrc
    // add at top of file
    export PHPBREW_HOME=/Users/YOUR_MACOS_USERNAME/.phpbrew
    export PHPBREW_ROOT=/Users/YOUR_MACOS_USERNAME/.phpbrew

    emacs ~/.bash_profile
    // add following line
    [[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc

    source ~/.bash_profile
    // check phpbrew work
    phpbrew --version

    // now leave root user ctrl+C

    // Now we can start nginx and php-fpm as root to run it as setted user
    sudo brew services start|stop|restart nginx
    sudo phpbrew fpm start|stop
    48 changes: 48 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    user YOUR_MACOS_USERNAME YOUR_MACOS_USER_GROUP_NAME;
    worker_processes 16;
    events {
    worker_connections 4096; ## Default: 1024
    }
    http {
    server {
    server_name localhost;
    listen 8000;
    root /COMPLETE_PATH_TO_SYMFONY_PROJECT;

    # If user writes the app_xxx.php into the url, remove it:
    rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;

    location / {
    index app_dev.php;
    rewrite ^/(.*)$ /app_dev.php/$1 last;
    return 403; # If the rewrite was not succesfull, return error.
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
    # fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_pass unix:/Users/YOUR_MACOS_USERNAME/.phpbrew/php/php-7.3.10/var/run/php-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    # When you are using symlinks to link the document root to the
    # current version of your application, you should pass the real
    # application path instead of the path to the symlink to PHP
    # FPM.
    # Otherwise, PHP's OPcache may not properly detect changes to
    # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
    # for more information).
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
    return 404;
    }

    error_log /usr/local/var/log/nginx/api_error.log;
    access_log /usr/local/var/log/nginx/api_access.log;
    }
    }
    4 changes: 4 additions & 0 deletions www.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    // /Users/YOUR_MACOS_USERNAME/.phpbrew/php/php-7.1.29/etc/php-fpm.d/www.conf then change value of :

    user = YOUR_MACOS_USERNAME
    group = YOUR_MACOS_USER_GROUP_NAME