Skip to content

Instantly share code, notes, and snippets.

@jpalala
Last active September 9, 2022 14:52
Show Gist options
  • Save jpalala/c293ed671fc1f86805d9b09f7f6989ff to your computer and use it in GitHub Desktop.
Save jpalala/c293ed671fc1f86805d9b09f7f6989ff to your computer and use it in GitHub Desktop.
How to get nginx php-fpm on your mac machine

https://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/

Homebrew

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

If installed already: brew update && brew upgrade

PHP-FPM

brew tap homebrew/dupes
brew tap homebrew/php

Install it:

brew install --without-apache --with-fpm --with-mysql php56

Symlink / alias php

BASH: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile && . ~/.bash_profile

ZSH: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc && . ~/.zshrc

Automatically start up

Create dir: mkdir -p ~/Library/LaunchAgents

Symlink to your LaunchAgents: ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/

Start it: launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

Check it's running: lsof -Pni4 | grep LISTEN | grep php

Mysql

Brew install: brew install mysql

Run the setup security program: mysql_secure_installation

Auto starting: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

phpMyAdmin

Install autoconf, which is needed for the installation of phpMyAdmin:

brew install autoconf

And set the $PHP_AUTOCONF environment variable:

If you use BASH: 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.bash_profile && . ~/.bash_profile

or ZSH:echo 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.zshrc && . ~/.zshrc

Since now you're all set, you can finish this part with the actual installation of phpMyAdmin:

brew install phpmyadmin

Nginx

brew install nginx

#Since you want to use port 80 (default HTTP port), you have to run the Nginx process with root privileges:

sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Start nginx: sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Test: curl -IL http://127.0.0.1:8080

You're done. Nginx runs on 8080. TO configure further

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

Remove the current nginx.conf (which is also available as /usr/local/etc/nginx/nginx.conf.default in case you want to restore the defaults) and download my custom from GitHub:

rm /usr/local/etc/nginx/nginx.conf

Get Jonas Friedmann's nginx conf curl -L https://gist.github.com/frdmn/7853158/raw/nginx.conf -o /usr/local/etc/nginx/nginx.conf

Get his php-fpm configuration as well curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm

Setup example virtual hosts

curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default -o /usr/local/etc/nginx/sites-available/default

curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default-ssl -o /usr/local/etc/nginx/sites-available/default-ssl

curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_phpmyadmin -o /usr/local/etc/nginx/sites-available/phpmyadmin

Clone Jonas's example virtual hosts (including 404/403 error pages and a phpinfo() status site) using git:

git clone http://git.frd.mn/frdmn/nginx-virtual-host.git /var/www rm -rf /var/www/.git

And remove the .git folder so your content won't get tracked by git.

@Aldus83
Copy link

Aldus83 commented Jul 5, 2018

Hi. Seems like homebrew/php is deprecated now... tapping core doesn't seem to fix missing options (--with-fpm etc.). How to do?

@sshymko
Copy link

sshymko commented Jul 13, 2018

Successfully installed PHP 7.1 with PHP-FPM like so:

brew install php71

@cuteapoot
Copy link

Homebrew recently changed how they do PHP versions; now you'd want to do brew install php@7.1

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