Skip to content

Instantly share code, notes, and snippets.

@hanhpv
Last active November 13, 2024 09:52
Show Gist options
  • Save hanhpv/5e56b39987d19963fd1d9d8d77490956 to your computer and use it in GitHub Desktop.
Save hanhpv/5e56b39987d19963fd1d9d8d77490956 to your computer and use it in GitHub Desktop.
Nginx, PHP-FPM, MySQL on Mac OSX

Xcode

Make sure you have the latest version of XCode installed. Available from the AppStore.

Install the Xcode Command Line Tools:

xcode-select --install

Homebrew

Homebrew is the missing package manager for OSX. Download and install using the following command:

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

Check for any problems:

brew doctor

Update and Upgrade brew formulas:

brew update && brew upgarde

Install nginx

brew install --with-http2 nginx

setup auto start

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

start from command line

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

stop from command line

sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Nginx will listen on port 8080 by default.

Install PHP-FPM

brew tap homebrew/dupes
brew install --without-apache --with-fpm --with-mysql php70

setup auto start

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/php70/7.0.10_1/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/

[Updated]

This can be done using brew services: brew services start php70

start PHP-FPM:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist

verify that PHP-FPM is listening on port 9000:

lsof -Pni4 | grep LISTEN | grep php

Setup MySQL

brew install mysql

setup auto start

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents/

then start the mysql server:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

[Updated]

This can be done using brew: brew services start mysql

If you don't want/need a background service you can just run: mysql.server start

Secure the installation

mysql_secure_installation

Test the connection

mysql -uroot -p

Command aliases

Dowload the aliases:

curl -L https://gist.githubusercontent.com/hanhpv/104cf0ebb9ddd887858543f5b22ac55d/raw/c85c3a931b58de428e9211f61cd610cb166842f7/osx-nginx-phpfpm-mysql-aliases -o /tmp/.aliases

For bash:

cat /tmp/.aliases >> ~/.profile

Close and reopen the terminal or type source ~/.profile to reload the profile.

The following commands are now available:

Nginx

nginx.start
nginx.stop
nginx.restart

PHP-FPM

php-fpm.start
php-fpm.stop
php-fpm.restart

mysql

mysql.start
mysql.stop
mysql.restart

Nginx Logs

nginx.logs.error
nginx.logs.access
nginx.logs.default.access
nginx.logs.default-ssl.access
nginx.logs.phpmyadmin.access
@luongmv-36
Copy link

luongmv-36 commented Aug 31, 2017

You need brew tap homebrew/php

@yashwant-BST
Copy link

Please change the Homebrew install command as it is returning 404.
latest homebrew installation command is

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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