Home > Backend Development > PHP Tutorial > Use brew to build an LNMP development environment on Mac

Use brew to build an LNMP development environment on Mac

巴扎黑
Release: 2016-11-11 09:35:05
Original
1151 people have browsed it

Brew

brew is for mac, just like apt-get is for ubuntu. It is a good helper for installing software and it cannot be more convenient...

brew is installed as follows:

ruby -e "$(curl -fsSL https: //raw.github.com/mxcl/homebrew/go/install)"

brew common options

brew install xxx
brew uninstall xxx
brew list
brew update xxx

Nginx

It is also more convenient to use Nginx , first install

brew install nginx

Auto-start settings

To reload nginx after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load ~/Library/LaunchAgents/homebrew. mxcl.nginx.plist

The command to start and shut down Nginx is as follows (if you want to listen to port 80, you must run it as an administrator)

#Open nginx
sudo nginx
#Reload configuration | Restart | Stop | Exit nginx
nginx -s reload|reopen|stop|quit
#Test whether the configuration has syntax errors
nginx -t

Configure Nginx

cd /usr/local/etc/nginx/
mkdir conf.d

Modify Nginx configuration File

vim nginx.conf

The main modification location is the last include

worker_processes 1;
error_log /usr/local/var/log/nginx/error.log warn;
pid /usr/local/var/run /nginx.pid;
events {
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" '
                                                                                                                                        port_in_redirect off;
sendfile on;
keepalive_timeout ;
server {
listen 80;
server_name localhost;

root /Users/username/Sites/; # This item needs to be modified to the path where you want to store the relevant web pages

location / {

index index.php;

autoindex on;
}

#proxy the php scripts to php-fpm

location ~ .php$ {

include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}

}


You cannot access the php site at this time because php-fpm has not been turned on.

PHP

PHP is installed by default on mac, but it is difficult to control the version. You can use brew to install the latest version on mac, or even multiple versions. I installed php5.5

brew update
brew tap homebrew/ dupes
brew tap josegonzalez/homebrew-php
brew install php55 --with-fpm

Then modify the cli path of php and the php module used by apache. Add the following content to .bashrc or .zshrc

vi ~/.bashrc

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

Replace the system with the just installed php The default php version of cli.


Self -starting setting oTO RELOAD PHP55 After An UPGrade:
Launchctl Unload ~/library/Launchagents/Homebrew.mxCl.php55.Plist
Chctl load ~/library/laa Unchagents/Homebrew.mxCl.php55.plist

behind Mongo and mysql will be used, so you can directly use the following command to install the php module. Other modules are similar

#brew install php55-mysql #This no longer needs to be installed
brew install php55-mongo

MySQL

mac If you don’t come with mysql, you need to reinstall it. The method is still very simple

brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/ tmp
sudo chown -R 777 /usr/local/var/mysql/

The first sentence is to install, and the following is to ensure normal use. Then the startup command

mysql.server start

Self-start settings

To reload mysql after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/ homebrew.mxcl.mysql.plist

It is best to set a password for mysql. The method is as follows

mysqladmin -u root password 'xxx'

If you want to modify the configuration of mysql, create one under /usr/local/etc my.cnf, for example, add log

[mysqld]
general-log
general_log_file = /usr/local/var/log/mysqld.log

MongoDB

MongoDB can be said to be the simplest one, execute it directly

brew install mongodb

Startup method

mongod --fork


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template