mac安装nginx、php和postgresql

本文详细介绍了如何在Mac操作系统中使用homebrew安装和配置高性能Web服务器nginx,后端开发语言php70,以及开源数据库postgresql。包括安装过程、配置修改、启动服务以及设置开机启动的方法。
摘要由CSDN通过智能技术生成

mac安装nginx、php和postgresql

概述

nginx:以高性能著称的web服务器。
php:流行的web后端开发语言。
postgresql:号称最高级的开源数据库。

本文介绍了在mac下安装nginx + php + postgresql的过程。

homebrew

homebrew(后文简称brew)是mac下很方便的包管理器,类似的还有macportsfink,利用brew可以很方便的安装nginx和PHP 。

命令行执行:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

即可安装brew。

以下是几个常用的brew命令:
brew install 安装软件包
brew uninstall 卸载软件包
brew reinstall 重新安装软件包
brew search 搜索软件包
brew options 查看软件包安装选项

nginx

安装nginx只需执行命令:brew install nginx
通过brew options nginx可以查看更多的安装选项,以下命令增加了gunzip,http2等的支持:

brew install nginx --with-gunzip --with-http2

笔者使用的是上述带http2支持的命令,当前nginx版本1.10.1。

安装后的nginx位于/usr/local/opt/nginx目录(其实是一个链接),配置文件位于/usr/local/etc/nginx

打开配置文件nginx.conf,作如下修改:

  1. 根据需要修改监听端口(可选),原配置文件里的内容这里 使用##注释掉 (下同),也可以直接删掉,标记为绿色的是新增的内容:

    server {
    ## listen 8080;
    listen 80 default_server;
    listen 8080 default_server;

    server_name localhost;

  2. 修改文档根目录及增加php页面支持,这里的/Web/www是笔者本地的目录,需要修改为相应的目录:

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

    root /Web/www;
    index index.php index.html index.htm;
    autoindex on; ## optional, Index of /

    }

    这里增加的autoindex on(可选)用于访问文件系统,假设文档根目录下有一个autoindex_test的文件夹,里面放一个autoindex_works的文件,没有启用autoindex时访问http://localhost/autoindex_test浏览器返回:

    403 Forbidden

    nginx/1.10.1

    启用时返回:

    Index of /autoindex_test/

    ../
    autoindex_works 29-Jan-2016 11:40 0

  3. 增加php支持:

    location ~ .php$ {
    ## root html;
    root /Web/www;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    #### fastcgi_param SCRIPT_FILENAME /scripts $fastcgi_script_name;
    ## fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name;
    ## include fastcgi_params;

    fastcgi_intercept_errors on; ## optional
    include fastcgi.conf;
    }

    include的部分也可以简单的只是把/scripts改成$document_root
    fastcgi_intercept_errors on选项是可选的。

将nginx加入path,打开~/.bash_profile,输入:

export NGINX_PATH=/usr/local/opt/nginx
export NGINX_CONF_PATH=/usr/local/etc/nginx

export PATH=$NGINX_PATH/bin:$PATH

警告:export PATH=$NGINX_PATH/bin:$PATH一定要把:$PATH添加回去,不然后果很严重。

启动nginx:

打开iTerm等命令行工具,输入source ~/.bash_profile更新配置文件,再输入sudo nginx即可启动nginx。

增加nginx的开机启动支持:

打开TextMate之类的文本编辑器,输入:

<?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">
    <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值