这篇文章主要介绍了Mac系统下使用brew搭建PHP(LNMP/LAMP)开发环境,本文讲解了使用Brew手动搭建PHP的开发环境,包括Apache、Nginx、PHP、MySQL、MongoDB、PHPMyAdm
Mac下搭建lamp开发环境很容易,有xampp和mamp现成的集成环境。但是集成环境对于经常需要自定义一些配置的开发者来说会非常麻烦,而且Mac本身自带apache和php,在brew的帮助下非常容易手动搭建,可控性很高。
Brew
brew对于mac,就像apt-get对于ubuntu,安装软件的好帮手,不能方便更多…
brew的安装方式如下:
复制代码 代码如下:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
brew常用选项
复制代码 代码如下:
brew install xxx
brew uninstall xxx
brew list
brew update xxx
Apache || Nginx
Apache
Apache的话使用mac自带的基本就够了,我的系统是10.9,可以使用以下命令控制Apache
复制代码 代码如下:
sudo apachectl start
sudo apachectl restart
sudo apachectl stop
唯一要改的是主目录,mac默认在home下有个sites(站点)目录,访问路径是
复制代码 代码如下:
~user_name
这样很不适合做开发用,修改/etc/apache2/httpd.conf内容
复制代码 代码如下:
DocumentRoot "/Users/username/Sites"
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
这样sites目录就是网站根目录了,代码都往这个下头丢
Nginx
要使用Nginx也比较方便,首先安装
复制代码 代码如下:
brew install nginx
启动关闭Nginx的命令如下(如果想要监听80端口,必须以管理员身份运行)
复制代码 代码如下:
#打开 nginx
sudo nginx
#重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
#测试配置是否有语法错误
nginx -t
配置Nginx
复制代码 代码如下:
cd /usr/local/etc/nginx/
mkdir conf.d
修改Nginx配置文件
复制代码 代码如下:
vim nginx.conf
主要修改位置是最后的include
复制代码 代码如下:
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log warn;
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"';
access_log /usr/local/var/log/nginx/access.log main;
port_in_redirect off;
sendfile on;
keepalive_timeout 65;
include /usr/local/etc/nginx/conf.d/*.conf;
}
修改自定义文件
复制代码 代码如下:
vim ./conf.d/default.conf
增加一个监听端口
复制代码 代码如下:
server {
listen 80;
server_name localhost;
root /Users/username/Sites/; # 该项要修改为你准备存放相关网页的路径
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;
}
}
这个时候还不能访问php站点,因为还没有开启php-fpm。
虽然mac 10.9自带了php-fpm,但是由于我们使用了最新的PHP,PHP中自带php-fpm,所以使用PHP中的php-fpm可以保证版本的一致。
这里的命令在安装完下一步的php后再执行
复制代码 代码如下:
sudo nginx
sudo php-fpm -D
PHP
PHP在mac下默认安装了,但是不好控制版本,利用brew可以再mac下安装最新版本,甚至是多个版本,,我装了php5.5
复制代码 代码如下:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment