全新Mac配置PHP开发环境教程(4)


brew install composer
#检查一下情况
composer --version
Composer version 1.0.0-alpha8 2014-01-06 18:39:59


redis memcached这些软件brew 已经自动依赖安装上,如果想开机自动启动,或者查看使用说明 brew info redis即可。另外,composer的中文文档:猛戳这里
安装Nginx

brew install nginx --with-http_geoip_module
Nginx启动关闭命令:

复制代码 代码如下:


#测试配置是否有语法错误
nginx -t

#打开 nginx
sudo nginx

#重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit

#也可以使用Mac的launchctl来启动|停止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

Nginx开机启动

复制代码 代码如下:


ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist


Nginx监听80端口需要root权限执行,因此:

复制代码 代码如下:


sudo chown root:wheel /usr/local/Cellar/nginx/1.6.0_1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.6.0_1/bin/nginx


配置nginx.conf
创建需要用到的目录:

复制代码 代码如下:


mkdir -p /usr/local/var/logs/nginx
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl
sudo mkdir -p /var/www
sudo chown :staff /var/www
sudo chmod 775 /var/www

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"';

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/*;
}


设置nginx php-fpm配置文件

复制代码 代码如下:


vim /usr/local/etc/nginx/conf.d/php-fpm
#proxy the php scripts to php-fpm
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;
}


nginx虚拟主机准备工作

#创建 info.php index.html 404.html 403.html文件到 /var/www 下面

vi /var/www/info.php vi /var/www/index.html vi /var/www/403.html vi /var/www/404.html
创建默认虚拟主机default

vim /usr/local/etc/nginx/sites-available/default

输入:

复制代码 代码如下:


server {
listen 80;
server_name localhost;
root /var/www/;

access_log /usr/local/var/logs/nginx/default.access.log main;

location / {
index index.html index.htm index.php;
autoindex on;
include /usr/local/etc/nginx/conf.d/php-fpm;
}

location = /info {
allow 127.0.0.1;
deny all;
rewrite (.*) /.info.php;
}

error_page 404 /404.html;
error_page 403 /403.html;
}


创建ssl默认虚拟主机default-ssl

vim /usr/local/etc/nginx/sites-available/default-ssl

输入:

复制代码 代码如下:


server {
listen 443;
server_name localhost;
root /var/www/;
access_log /usr/local/var/logs/nginx/default-ssl.access.log main; ssl on;
ssl_certificate ssl/localhost.crt;
ssl_certificate_key ssl/localhost.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
include /usr/local/etc/nginx/conf.d/php-fpm;
}
location = /info {
allow 127.0.0.1;
deny all;
rewrite (.*) /.info.php;
}
error_page 404 /404.html;
error_page 403 /403.html;
}


创建phpmyadmin虚拟主机

vim /usr/local/etc/nginx/sites-available/phpmyadmin
输入以下配置

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c60d4e5a093f9f18a97db158ae7cd135.html