阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Mac OSX 10.9搭建Nginx+MySQL+php-fpm环境

118次阅读
没有评论

共计 8614 个字符,预计需要花费 22 分钟才能阅读完成。

Mac OSX 10.9 搭建 Nginx+MySQL+php-fpm 环境

推荐阅读

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 搭建视频点播服务器(仿真专业流媒体软件)http://www.linuxidc.com/Linux/2012-08/69151.htm

我的电脑配置
 
系统版本:10.9.1
 
安装 homebrew
 
homebrew 是 mac 下非常好用的包管理器,会自动安装相关的依赖包,将你从繁琐的软件依赖安装中解放出来。安装 homebrew 也非常简单,只要在终端中输入:
 
ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”
 
homebrew 的常用命令:
 •brew update #更新可安装包的最新信息,建议每次安装前都运行下
•brew search pkg_name #搜索相关的包信息
•brew install pkg_name #安装包
 
安装 nginx
 
安装
 
brew search nginx
 brew install nginx
 
配置文件(已存在 /usr/local/etc/nginx/nginx.conf)
 
cd /usr/local/etc/nginx/ vim nginx.conf
 
现在我把成功的配置文件贴出来
 
user  hugo staff(这里修成为跟文件一样的用户 /Users/hugo/Documents/PHP 文件);
 
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;
 

 

server {
 
    listen      8080;
 
    server_name  localhost;
 
    root  /Users/hugo/Documents/PHP(这个是我自己定义的文件路径,index.php 所在);
 
    index  index.html index.htm index.php;
 

 

 

    #charset koi8-r;
 

 

    #access_log  logs/host.access.log  main;
 

 

    location / {
 
        #root  html;
 
        #root  /Users/hugo/Documents/PHP;
 
        #index  index.html index.htm index.php;
 
        # $uri /index.php?$query_string;
 

 

    }
 

 

    #location ~ \.php$ {
 

 

      # fastcgi_pass  127.0.0.1:9000;
 
        #fastcgi_index  index.php;
 
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 
        #include fastcgi_params;
 

 

    #}
 
    #location ~ (/\.){
 
    #        deny all;
 
    #}
 
    location ~ .*\.php$
 
    {
 
            include fastcgi.conf;
 
            fastcgi_pass  127.0.0.1:9000;
 
            fastcgi_index index.php;
 
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 
            include fastcgi_params;
 

 

            expires off;
 
    }
 

 

    #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  /Users/hugo/Documents/PHP;
 
    }
 

 

    # 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$ {
 
    #    root          html;
 
    #    fastcgi_pass  127.0.0.1:9000;
 
    #    fastcgi_index  index.php;
 
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
 
    #}
 
}
 

 

 

# 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 ssl;
 
#    server_name  localhost;
 

 

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

 

#    ssl_session_cache    shared:SSL:1m;
 
#    ssl_session_timeout  5m;
 

 

#    ssl_ciphers  HIGH:!aNULL:!MD5;
 
#    ssl_prefer_server_ciphers  on;
 

 

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

 

}

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-05/101451p2.htm

安装 php-fpm

Mac OSX 10.9 的系统自带了 PHP、php-fpm,省去了安装 php-fpm 的麻烦。这里需要简单地修改下 php-fpm 的配置,否则运行 php-fpm 会报错。

sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf vim /private/etc/php-fpm.conf

修改 php-fpm.conf 文件中的 error_log 项,默认该项被注释掉,这里需要去注释并且修改为 error_log = /usr/local/var/log/php-fpm.log。如果不修改该值,运行 php-fpm 的时候会提示 log 文件输出路径不存在的错误。

另外,这个很重要的修改:把配置文件的 user 和 group 都修改跟 nginx 的用户一样
user = hugo
group = staff

如果保存不了修改后的 php-fpm.conf 的文件,那就在进入编辑之前的命令前加入 sudo,就是 sudo vim

安装 MySQL

安装

brew install mysql

常用命令
mysql.server start #启动 mysql 服务
mysql.server stop #关闭 mysql 服务

配置

在终端运行 mysql_secure_installation 脚本,该脚本会一步步提示你设置一系列安全性相关的参数,包括:设置 root 密码,关闭匿名访问,不允许 root 用户远程访问,移除 test 数据库。当然运行该脚本前记得先启动 mysql 服务。

测试 nginx 服务

在之前 nginx 配置文件 default.conf 中设置的 root 项对应的文件夹下创建测试文件 index.php:
<?php phpinfo(); ?>

然后:

  • 启动 nginx 服务,sudo nginx;
  • 修改配置文件,重启 nginx 服务,sudo nginx -s reload
  • 启动 php 服务,sudo php-fpm(重启这个服务的命令找了很久:SystemStarter php54-fpm restart,如果不行,可以重启电脑。因为在这里当你开启这个服务后再去修改 user 和 group 的信息,这时候就一定要重启,不然访问 index.php 就报错 file not found);
  • 在浏览器地址栏中输入 localhost:8080,如果配置正确地话,应该能看到 PHP 相关信息的页面。

附加:

可能会用到的命令:

ps aux|grep nginx(看服务的进程)

ls -ld 文件地址(查看这个地址的用户和用户组的信息)

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

Mac OSX 10.9 搭建 Nginx+MySQL+php-fpm 环境

推荐阅读

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 搭建视频点播服务器(仿真专业流媒体软件)http://www.linuxidc.com/Linux/2012-08/69151.htm

我的电脑配置
 
系统版本:10.9.1
 
安装 homebrew
 
homebrew 是 mac 下非常好用的包管理器,会自动安装相关的依赖包,将你从繁琐的软件依赖安装中解放出来。安装 homebrew 也非常简单,只要在终端中输入:
 
ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”
 
homebrew 的常用命令:
 •brew update #更新可安装包的最新信息,建议每次安装前都运行下
•brew search pkg_name #搜索相关的包信息
•brew install pkg_name #安装包
 
安装 nginx
 
安装
 
brew search nginx
 brew install nginx
 
配置文件(已存在 /usr/local/etc/nginx/nginx.conf)
 
cd /usr/local/etc/nginx/ vim nginx.conf
 
现在我把成功的配置文件贴出来
 
user  hugo staff(这里修成为跟文件一样的用户 /Users/hugo/Documents/PHP 文件);
 
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;
 

 

server {
 
    listen      8080;
 
    server_name  localhost;
 
    root  /Users/hugo/Documents/PHP(这个是我自己定义的文件路径,index.php 所在);
 
    index  index.html index.htm index.php;
 

 

 

    #charset koi8-r;
 

 

    #access_log  logs/host.access.log  main;
 

 

    location / {
 
        #root  html;
 
        #root  /Users/hugo/Documents/PHP;
 
        #index  index.html index.htm index.php;
 
        # $uri /index.php?$query_string;
 

 

    }
 

 

    #location ~ \.php$ {
 

 

      # fastcgi_pass  127.0.0.1:9000;
 
        #fastcgi_index  index.php;
 
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 
        #include fastcgi_params;
 

 

    #}
 
    #location ~ (/\.){
 
    #        deny all;
 
    #}
 
    location ~ .*\.php$
 
    {
 
            include fastcgi.conf;
 
            fastcgi_pass  127.0.0.1:9000;
 
            fastcgi_index index.php;
 
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 
            include fastcgi_params;
 

 

            expires off;
 
    }
 

 

    #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  /Users/hugo/Documents/PHP;
 
    }
 

 

    # 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$ {
 
    #    root          html;
 
    #    fastcgi_pass  127.0.0.1:9000;
 
    #    fastcgi_index  index.php;
 
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
 
    #}
 
}
 

 

 

# 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 ssl;
 
#    server_name  localhost;
 

 

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

 

#    ssl_session_cache    shared:SSL:1m;
 
#    ssl_session_timeout  5m;
 

 

#    ssl_ciphers  HIGH:!aNULL:!MD5;
 
#    ssl_prefer_server_ciphers  on;
 

 

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

 

}

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-05/101451p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计8614字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中