Transferred from
Http://yansu.org/2013/12/11/lamp-in-mac.html
It is easy to build a lamp development environment under Mac, with a XAMPP and mamp integrated environment. But the integrated environment is cumbersome for developers who often need to customize some configurations, and the Mac itself comes with Apache and PHP, which is easy to manually build with the help of brew, and is highly controllable brew
Brew for Mac, just like Apt-get for Ubuntu, the good helper to install software, not more convenient ...
Brew is installed in the following ways:
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
Apache | | Nginx
Apache
Apache's use of the Mac with the basic is enough, my system is 10.9, you can use the following command to control Apache
sudo apachectl start
sudo apachectl restart
sudo apachectl stop
The only thing to change is the home directory, where the Mac defaults to a sites (site) directory under the Web, and the access path is
Http://localhost/~user_name
This is not suitable for development, modify/etc/apache2/httpd.conf content
DocumentRoot "/users/username/sites"
<directory/>
Options Indexes multiviews
All Order
Allow,deny
Allow from all
</Directory>
So the Sites directory is the site root directory, the code is dropped to this head Nginx
To use Nginx is also more convenient, first install
Brew Install Nginx
The command to start shutdown Nginx is as follows (if you want to listen on port 80, you must run as an administrator)
#打开 nginx
sudo nginx
#重新加载配置 | reboot | stop | exit nginx
nginx-s reload|reopen|stop|quit
#测试配置是否有语法错误
nginx -T
Configure Nginx
cd/usr/local/etc/nginx/
mkdir CONF.D
modifying Nginx configuration Files
Vim nginx.conf
The main modification location is the final 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 ;
include/usr/local/etc/nginx/conf.d/*.conf;
}
Modify a custom file
Vim./conf.d/default.conf
Add a listening port
server {
listen ;
server_name localhost;
root/users/username/sites/; # The item to be modified for you to store the relevant page path
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
}
}
The PHP site cannot be accessed at this time because the PHP-FPM is not yet open.
Although Mac 10.9 has its own php-fpm, because we use the latest php,php with PHP-FPM, we can use the PHP-FPM in PHP to guarantee a consistent version.
The commands here are executed after installing the next PHP
sudo nginx
sudo php-fpm-d
PHP
PHP is installed by default under Mac, but it is not easy to control version, Brew can be installed with the latest version of 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 # Nginx
Brew Install Php55 #Apache
Then modify the PHP CLI path and the PHP module used by Apache. Add the following in the. bashrc or ZSHRC.