-
An Intel CPU
-
OS X 10.10 or higher
-
Command Line Tools (CLT) for Xcode:
xcode-select --install
, developer.apple.com/downloads or Xcode -
A Bourne-compatible shell for installation (e.g. bash or zsh)
Homebrew - is a package manager for macOS like apt
for Debian.
To install Homebrew run this command in the terminal:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run brew doctor
and fix all the warnings (outdated Xcode/CLT and unbrewed dylibs are very likely to cause problems) if they will be.
If you already had Homebrew installed, update the existing Homebrew installation as well as the installed packages:
$ brew update && brew upgrade
Homebrew doesn't come with PHP by default, so you'll need to add a repository for it:
$ brew tap homebrew/dupes
$ brew tap homebrew/php
Now you can install php:
$ brew install php71 --without-apache --with-fpm --with-mysql
Update the $PATH
environment variable, if you want to use the PHP CLI:
$ echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile && . ~/.bash_profile
To setup auto start create a directory for the LaunchAgents and add a symlink for the start/stop service:
$ mkdir -p ~/Library/LaunchAgents
$ ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
Now you could launch php-fpm:
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
To install MySQL run this command:
$ brew install mysql
To setup auto start add a symlink for the start/stop service:
$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Run the MySQL-server:
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
To secure your MySQL server you should execute the provided secure_mysql_installation
binary to change the root password:
$ mysql_secure_installation
> Enter current password for root (enter for none):
Press Enter
since you don't have one set.
> Change the root password? [Y/n]
It's up to you ;)
> Remove anonymous users? [Y/n]
They are not necessary, so press Enter
.
> Disallow root login remotely? [Y/n]
Enter
— No need to log in as root from any other IP than 127.0.0.1.
> Remove test database and access to it? [Y/n]
Enter
— You don't need the testing tables.
> Reload privilege tables now? [Y/n]
Enter
— Reload the privilege tables to ensure all of the changes made so far will take effect immediately.
When you done, test mysql:
$ mysql -u root -p
> Enter you password
To install Nginx run this command:
$ brew install nginx
To setup auto start:
$ sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
$ sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
Why sudo
? Because only the root user is allowed to open ports which are < 1024.
Launch the server and test connection:
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
$ curl -IL http://127.0.0.1:8080
Next you need to create few folders, which are necessary for the nginx configuration:
$ 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
There are two ways to store your projects. First is to store them inside separate directory in home
directory:
$ cd ~/projects
The second one is to store you projects in /var/www/
directory:
$ sudo mkdir -p /var/www
$ sudo chown :staff /var/www
$ sudo chmod 775 /var/www
I choose the first way, but it's up to you.
Replace the default nginx.conf
with my custom config from GitHubGist:
$ sudo rm /usr/local/etc/nginx/nginx.conf
$ curl -L https://gist.githubusercontent.com/iggyster/f897571cfd420bc2aa238a0bd7954858/raw/e10bf2808bb09747c334a8573e5ba7320bb6fb70/nginx.conf -o /usr/local/etc/nginx/nginx.conf
Also download my custom PHP-FPM config:
$ curl -L https://gist.githubusercontent.com/iggyster/f897571cfd420bc2aa238a0bd7954858/raw/e10bf2808bb09747c334a8573e5ba7320bb6fb70/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm
And the last step is to setup virtual host. You could do it by your self, or you could download my custom virtual host config and setup it:
$ curl -L https://gist.githubusercontent.com/iggyster/f897571cfd420bc2aa238a0bd7954858/raw/e10bf2808bb09747c334a8573e5ba7320bb6fb70/test -o /usr/local/etc/nginx/sites-available/test
$ ln -sfv /usr/local/etc/nginx/sites-available/test /usr/local/etc/nginx/sites-enabled/
But don't forget to change the path to the root directory of your host and also to add test.php
to the root.
After finishing you should restart nginx:
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
To be easy control of services like nginx, php-fpm & mysql I propose you to download my alias list:
$ curl -L https://gist.githubusercontent.com/iggyster/f897571cfd420bc2aa238a0bd7954858/raw/e10bf2808bb09747c334a8573e5ba7320bb6fb70/bash_aliases -o /tmp/.bash_aliases
$ cat /tmp/.bash_aliases >> ~/.bash_aliases
$ echo "source ~/.bash_aliases" >> ~/.bash_profile && . ~/.bash_profile
All aliases you could find in More commands section.
To update PHP version in future try this commands:
$ brew remove php71
$ brew install php7.X --without-apache --with-mysql --with-fpm
$ rm ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
$ ln -sfv /usr/local/opt/php7X/homebrew.mxcl.php7X.plist ~/Library/LaunchAgents/
And of course update your alias list:
$ sudo nano ~/.bash_aliases
...
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php7X.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php7X.plist"
...
-
brew install [package]
- -
brew list
- Show the list of all installed packages -
brew search [search term]
- List the possible packages that you can install -
brew info [package]
- Display some basic information about the package -
brew remove [package]
- Remove package -
brew update
- Self-update -
brew upgrade [package]
- Update package -
brew doctor
- Self-diagnose -
brew tap [repo]
- Add new Brew repository -
brew help
- List Brew commands -
nginx.start
- Start Nginx service -
nginx.stop
- Stop Nginx service -
nginx.restart
- Restart Nginx service -
php-fpm.start
- Start PHP-FPM service -
php-fpm.stop
- Stop PHP-FPM service -
php-fpm.restart
- Restart PHP-FPM service -
mysql.start
- Start MySQL server -
mysql.stop
- Stop MySQL server -
mysql.restart
- Retstart MySQL server
Great thanks to @frdmn who inspired me to write my own guide.
Hello, its works into php74?