Skip to content

Instantly share code, notes, and snippets.

@jfreites
Last active August 9, 2023 09:27
Show Gist options
  • Save jfreites/40861d0b261ff89dace2 to your computer and use it in GitHub Desktop.
Save jfreites/40861d0b261ff89dace2 to your computer and use it in GitHub Desktop.
MEMP Stack: setup Nginx, PHP and MySQL on Mac

Setup a MEMP Stack

MacOSX + Nginx + MySQL + PHP. Tested with El Capitan

Install Homebrew:

run on terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew doctor
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

Install Nginx:

run on terminal: brew install nginx

once it's finished, edit the configuration file wherever you like sudo vim /usr/local/etc/nginx/nginx.conf

Install MySQL:

download mysql installer from here: mysql downloads version Mac OS X (x86, 64-bit), DMG Archive. Once downloaded, click on the package and carried out the installation process.

cd /usr/local/mysql
sudo chown -R mysql data/
sudo ./bin/mysqld_safe & /usr/local/mysql/bin/mysql test
cd /var
sudo mkdir mysql
cd mysql/
sudo ln -s /private/tmp/mysql.sock mysql.sock
/usr/local/mysql/bin/mysql test
cd /usr/local/mysql
sudo echo
sudo ./bin/mysqld_safe & /usr/local/mysql/bin/mysql test

Optional add some aliases

vim ~/.bash_profile

alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
alias mystart="sudo /usr/local/mysql/support-files/mysql.server start"
alias mystop="sudo /usr/local/mysql/support-files/mysql.server stop"

Install PHP 5.6 and PHP 7.0

brew install php56 --with-mysql --with-fpm --with-xdebug
brew unlink php56
brew install php70 --with-mysql --with-fpm --with-xdebug
brew unlink php70
cp -v $(brew --prefix)/Cellar/php56/5.6.*/homebrew.mxcl.php5*.plist ~/Library/LaunchAgents/
cp -v $(brew --prefix)/Cellar/php70/7.0.*/homebrew.mxcl.php7*.plist ~/Library/LaunchAgents/
```

Add this lines in your .bash_profile
```
vim ~/.bash_profile
alias php-switch='~/.bin/php-switch/phpsw'
PHP_HOME=""
export PATH=$PHP_HOME:$PATH
PATH="/usr/local/sbin:$PATH"
```
## Create the PHP switcher file
Use this gist: [PHP-SW](https://gist.github.com/jfreites/791f5c43ecdc73fe8c76)
```
mkdir -p ~/.bin/php-switch
> ~/.bin/php-switch/phpsw
chmod +x ~/.bin/php-switch/phpsw
```

Usage
```
php-switch 56 # loads php 5.6.*
php-switch 70 # loads php 7.0.*
php-switch 0  # unloads all versions of PHP
```

## Enjoy!
@gintechsystems
Copy link

This is a great start to installing all of these but is there a recent example of setting up a project using port 8080, wordpress with a vhost?

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