mac上php+nginx配置

首先安装mac安装包
brew的安装:
     ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install )”
php安装和配置
brew search php55
brew info php55—查看安装时是否需要带上参数--with-fpm
brew install php55 —with-fpm
brew install php-mcrypt(加密用的,不一定要安装的)
安装之后使用php -v查看版本,如果不是你安装的版本需要更改path
执行下列命令更改:
cd
vim .profile
export PATH=/usr/local/bin:$PATH
以下是对 php-fpm.conf 配置文件的相关修改
1.用户名修改:
     user = zhaoye--用户
     group = staff—用户组
2.端口
     listen = 127.0.0.1:9000=>listen = /opt/run/php.socket(这里的socket是要给以后nginx配置用的)
3.php.ini配置文件修改
     date.timezone = Asia/Shanghai
4.找到homebrew-php.josegonzalez.php55.plist (通过brew info php55查找)
拷贝到~/Library/LaunchAgents,因为是端口大于1024的都不是root启动
mv homebrew-php.josegonzalez.php55.plist php-fpm.plist(修改文件名)
修改php-fpm.plist文件
如下可以作为参考
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" " http://www.apple.com/DTDs/PropertyList-1.0.dtd ">
<plist version="1.0">
<dict>
  <key>KeepAlive</key>
  <false/>( 这里不能为true,否则一直保持 )
  <key>Label</key>
  <string>php-fpm</string>(启动服务的命令名)
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/sbin/php-fpm</string>
    <string>--fpm-config</string>
    <string>/usr/local/etc/php/5.5/php-fpm.conf</string>( 读取配置文件的路径
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>UserName</key>
  <string>mac</string>
  <key>WorkingDirectory</key>
  <string>/usr/local/var</string>
  <key>StandardErrorPath</key>
  <string>/var/log/php/php-fpm.log</string>
</dict>
</plist>

最后通过
launchctl load -w ~/Library/LaunchAgents/php-fpm.plist
launchctl start php-fpm
启动
到这里php就已经OK了

调试:
可以安装brew install php-xdebug+google_xdebug用来调试
cd /etc/php/5.5/conf.d
给ext-xdebug.ini添加xdebug.remote_enable = On开启调试模式


nginx安装和配置
1.brew install nginx
2.修改nginx的启动plist文件
根据brew info nginx可以看到/usr/local/opt/nginx/homebrew.mxcl.nginx.plist
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/nginx.plist
(nginx是80端口是需要root启动的,所以拷贝到根目录下的Library/LaunchDaemons)
修改nginx.plist文件
参考如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" " http://www.apple.com/DTDs/PropertyList-1.0.dtd ">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>nginx</string>(启动服务名)
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>(被杀掉之后自己能启动)
    <key>UserName</key>
    <string>root</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/nginx/bin/nginx</string>(nginx配置路径)
        <string>-g</string>
        <string>daemon off;</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/usr/local</string>
  </dict>
</plist>
3.修改nginx配置文件

cd /usr/local/etc/nginx回到nginx配置文件目录
这里是新建了2个目录site-enabled,site-available用于配置文件(为了升级时减少修改量)
site-available里面存在真正的配置文件,site-enabled里面建链接指向site-available里面的配置文件
具体操作如下:
mkdir sites-enabled
mkdir sites-available
在site-available里面添加配置文件:localhost,test-seekyun.com
修改nginx.conf
参考如下:
user  zhaoye admin;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    include /usr/local/etc/nginx/sites-enabled/*;

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}


里面的 include /usr/local/etc/nginx/sites-enabled/*;标识了
其实际配置是在site-enabled里面,site-enabled里面的
test-seekyun.com -> ../sites-available/test-seekyun.com
是一个软链接指向../sites-available/test-seekyun.com
test-seekyun.com配置文件内容如下:
server {
        listen       80;
     server_name     jk.myseekyun.com ;(这里的服务名等下是要在/etc/hosts加上的)

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

      root /Users/zhaoye/workspace/jkweb;(php代码工程所在的目录)

        location / {
            index  index.html index.htm index.php;
            if (!-f $request_filename) {
                 rewrite ^.*$ /index.php last;
            }
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1 ;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            fastcgi_pass   unix:/opt/run/php.socket;(这个是和上面php-fpm.conf里面的socket)
             include     fastcgi_params;
             fastcgi_index               index.php;
             fastcgi_split_path_info         ^(.+\.php)(.*)$;
             fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
             fastcgi_param PATH_INFO         $fastcgi_path_info;
     }

     location /favicon.ico {
          error_log /dev/null crit;
          return 404;
     }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

localhost配置文件如下:
server {
        listen       80;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

     root /Users/zhaoye/workspace/;(php代码所在的目录)

        location / {
            index  index.html index.htm index.php;
         autoindex on;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1 ;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            fastcgi_pass   unix:/opt/run/php.socket;(这个是和 php-fpm.conf名称配置一致
         fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
cd site-enabled
ln -s site-available/localhost
ln -s site-available/test-seekyun.com
到这里所有的nginx配置都可以了

4.sudo -s(需要root启动)
launchctl load -w /Library/LaunchDaemons/nginx.plist
launchctl start nginx最后通过launchctl启动nginx服务
launchctl stop nginx关闭nginx服务 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值