Installing homebrew
Recent work Environment switch to Mac, so take OS X Yosemite (10.10.1) as an example to record the process of installing a LNMP environment from scratch with a Mac
Make sure that the system has Xcode installed, and then install the Dependency management tool using a single line of commands homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After that, you can use
brew install FORMULA
To install the required dependencies.
The naming of brew (meaning wine) is interesting and all uses the materials/utensils used in the brewing process, and the nouns correspond to the following concepts:
- Formula (recipe) package definition, essentially a RB file
- Installation path of the KEG (bucket) package
- Cellar (Cellar) root directory for all packages (buckets)
- The source of the tap (TAP) package
- Bottle (bottle) compile packaged packages
The final compilation and installation of the program is a barrel of brewing good wine
For more detailed information refer to the official cookbook of Homebrew
So the common process for using homebrew is:
- Add a program source (add a tap)
brew tap homebrew/php
- Update program Source
brew update
- Install package (according to recipe brewing)
brew install git
- View the configuration
brew config
to see that the package is installed by default /usr/local/Cellar
(wine barrels are placed in the cellar)
Mounting PHP5.6 (FPM mode)
First of all, join the official homebrew of several software sources
brew tap homebrew/dupesbrew tap homebrew/versionsbrew tap homebrew/php
PHP if installed by default configuration, will compile the mod_php
module and only run in the Apache environment, in order to use Nginx, here need to compile php-fpm and disable Apache, mainly through the parameters --without-fpm --without-apache
to implement. The Complete installation instructions are
brew install php56 --without-snmp --without-apache --with-debug --with-fpm --with-intl --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-openssl --with-imap --with-mysql --with-tidy
Since OSX has its own PHP environment, it is necessary to modify the system path and first run the brew installation version, ~/.bashrc
adding:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
If you want to install a new PHP extension, you can install it directly without recompiling PHP every time, all extensions can be
brew search php56
See, here is the extension I need to support the Phalcon framework:
brew install php56-gearman php56-msgpack php56-memcache php56-memcached php56-mongo php56-phalcon php56-redis php56-xdebug
Load and start of PHP-FPM
After installation, you can start and stop php-fpm with the following command
php-fpm -Dkillall php-fpm
At the same time, PHP-FPM can be added to boot
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgentslaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
Installing Nginx
brew install nginx
After the installation is complete, you can
nginxnginx -s quit
Startup and shutdown, and also support for operations such as overloading configuration files
nginx -s reload|reopen|stop|quit
Nginx installs the default listener 8080 port, can access the http://localhost:8080
viewing state. If you want to listen on port 80 requires root access, run
sudo chown root:wheel /usr/local/Cellar/nginx/1.6.2/bin/nginxsudo chmod u+s /usr/local/Cellar/nginx/1.6.2/bin/nginx
and start with root privileges
sudo nginx
Boot up
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgentslaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Nginx + PHP-FPM Configuration
Nginx typically runs multiple domain names, so here is a reference to the @fish method, according to the Ubuntu folder structure to store Nginx configuration files
mkdir -p /usr/local/var/logs/nginxmkdir -p /usr/local/etc/nginx/sites-availablemkdir -p /usr/local/etc/nginx/sites-enabledmkdir -p /usr/local/etc/nginx/conf.dmkdir -p /usr/local/etc/nginx/ssl
Edit Nginx Global Configuration
vim /usr/local/etc/nginx/nginx.conf
worker_processes 1;error_log /usr/local/var/logs/nginx/error.log debug;pid /usr/local/var/run/nginx.pid;events { worker_connections 256;}http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] ‘ ‘"$request" $status $body_bytes_sent ‘ ‘"$http_referer" "$http_user_agent" ‘ ‘"$http_x_forwarded_for" $host $request_time $upstream_response_time $scheme ‘ ‘$cookie_evalogin‘; access_log /usr/local/var/logs/access.log main; sendfile on; keepalive_timeout 65; port_in_redirect off; include /usr/local/etc/nginx/sites-enabled/*;}
In this way, you can first put some reusable configuration independent /usr/local/etc/nginx/conf.d
, such as the fastcgi settings can be independent
vim /usr/local/etc/nginx/conf.d/php-fpm
Content is
location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/nginx/fastcgi.conf;}
Then the /usr/local/etc/nginx/sites-enabled
directory can be a file corresponding to a domain name configuration, such as the Web server directory is/opt/htdocs
vim /usr/local/etc/nginx/sites-enabled/default
server { listen 80; server_name localhost; root /opt/htdocs/; location / { index index.html index.htm index.php; include /usr/local/etc/nginx/conf.d/php-fpm; }}
When the PHP-FPM is started and nginx is activated, you can http://localhost
run the PHP program.
Install MySQL
brew install mysql
can be done by
mysql.server startmysql.server stop
To start/stop, the default should be a blank password after startup, you can set a password via mysqladmin
mysqladmin -uroot password "mypassword"
However, when the operation of the empty password can not be logged in the situation, and ultimately only through the Mysqld_safe to set
sudo mysqld_safe --skip-grant-tablesmysql -u rootmysql> UPDATE mysql.user SET Password=PASSWORD(‘mypassword‘) WHERE User=‘root‘;mysql> FLUSH PRIVILEGES;
Finally, MySQL is added to boot.
cp /usr/local/Cellar/mysql/5.6.22/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
Memcache
brew install memcached
Start/Stop command
memcached -dkillall memcached
Join boot Start
cp /usr/local/Cellar/memcached/1.4.20/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
Redis
brew install redis
The Redis default profile does not allow Deamon to run, so you need to modify the configuration file first
vim /usr/local/etc/redis.conf
Modify the Daemonize to Yes and then load the configuration file to enable background process startup
redis-server /usr/local/etc/redis.conf
Join boot Start
Setting aliases
Finally, you can set the alias for all services to start and stop. Easy operation
vim ~/.bash_profile
Join
Alias nginx.start= ' launchctl load-w ~/library/launchagents/homebrew.mxcl.nginx.plist ' Alias nginx.stop= ' Launchctl Unload-w ~/library/launchagents/homebrew.mxcl.nginx.plist ' Alias nginx.restart= ' nginx.stop && nginx.start ' Alias php-fpm.start= "Launchctl load-w ~/library/launchagents/homebrew.mxcl.php55.plist" Alias php-fpm.stop= " Launchctl unload-w ~/library/launchagents/homebrew.mxcl.php55.plist "Alias php-fpm.restart= ' Php-fpm.stop && Php-fpm.start ' Alias mysql.start= ' launchctl load-w ~/library/launchagents/homebrew.mxcl.mysql.plist ' Alias mysql.stop= "Launchctl unload-w ~/library/launchagents/homebrew.mxcl.mysql.plist" Alias Mysql.restart= ' Mysql.stop && Mysql.start ' Alias redis.start= ' launchctl load-w ~/library/launchagents/homebrew.mxcl.redis.plist ' Alias redis.stop= "Launchctl unload-w ~/library/launchagents/homebrew.mxcl.redis.plist" Alias Redis.restart= ' Redis.stop && Redis.start ' Alias memcached.start= ' Launchctl load-w ~/library/launchagents/homebrew.mxcl.Memcached.plist "Alias memcached.stop=" Launchctl unload-w ~/library/launchagents/homebrew.mxcl.memcached.plist " Alias memcached.restart= ' memcached.stop && memcached.start '
Install additional project support
brew install composer node
Install Oh My Zsh
brew install zsh-completionschsh -s /usr/local/bin/zshvim ~/.zshenv
Join content
export PATH=/usr/local/bin:$PATH
And then
vim ~/.zshrc
Join content
fpath=(/usr/local/share/zsh-completions $fpath)autoload -Uz compinitcompinit -u
Last Run
rm -f ~/.zcompdump; compinit
View the shell being used
dscl localhost -read Local/Default/Users/$USER UserShell
Install Oh My Zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
Reference
- New Installation of Mac OSX Developer environment
Install LNMP (nginx+php5.6) environment under Mac (GO)