Install LNMP (nginx+php5.6) environment under Mac

Source: Internet
Author: User
Tags root access install redis

Install LNMP (nginx+php5.6) environment under MAC installation 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:

    1. Add a program source (add a tap)brew tap homebrew/php
    2. Update program Sourcebrew update
    3. Install package (according to recipe brewing)brew install git
    4. 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

--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_processes1;error_log/usr/local/var/logs/nginx/error.log debug;pid/usr/local/< span class= "keyword" >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 ' 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

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

cp /usr/local/Cellar/redis/2.8.19/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/ 
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

Install LNMP (nginx+php5.6) environment under Mac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.