使用homebrew php安装php如何使用自定义的参数

没有更多推荐了,
不良信息举报
举报内容:
Mac下使用homebrew安装php环境
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!mac环境中使用brew安装php5.5.15
mac环境中使用brew安装php5.5.15
Brew 是 Mac 下面的包管理工具,通过 Github 托管适合 Mac 的编译配置以及 Patch,可以方便的安装开发工具。 Mac 自带ruby 所以安装起来很方便,同时它也会自动把git也给你装上。官方网站: http://brew.sh
安装方法:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
使用以下方法可以查看brew是否安装成功,以及目前的版本:
liondeMacBook-Pro:~ lion$ brew -v
Homebrew 0.9.5
添加brew的PHP扩展库:
liondeMacBook-Pro:~ lion$ brew update
liondeMacBook-Pro:~ lion$ brew tap homebrew/dupes
liondeMacBook-Pro:~ lion$ brew tap homebrew/php
liondeMacBook-Pro:~ lion$ brew tap josegonzalez/homebrew-php
可以使用brew options php55命令查看安装时可以有哪些选项,因为我之前安装过curl、libxslt、openssl所以,在选项中会提示是否使用brew安装的相关扩展:
liondeMacBook-Pro:Library lion$ brew options php55
--disable-opcache
Build without Opcache extension
--disable-zend-multibyte
Disable auto-detection of Unicode encoded scripts (PHP 5.2 and 5.3 only)
--homebrew-apxs
Build against apxs in Homebrew prefix
--with-apache
Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache
--with-cgi
Enable building of the CGI executable (implies --without-apache)
--with-debug
Compile with debugging symbols
--with-fpm
Enable building of the fpm SAPI executable (implies --without-apache)
--with-gmp
Build with gmp support
--with-homebrew-curl
Include Curl support via Homebrew
--with-homebrew-libxslt
Include LibXSLT support via Homebrew
--with-homebrew-openssl
Include OpenSSL support via Homebrew
--with-imap
Include IMAP extension
--with-intl
Include internationalization support
--with-libmysql
Include (old-style) libmysql support instead of mysqlnd
--with-mssql
Include MSSQL-DB support
--with-pdo-oci
Include Oracle databases (requries ORACLE_HOME be set)
--with-pgsql
Include PostgreSQL support
--with-phpdbg
Enable building of the phpdbg SAPI executable (PHP 5.4 and above)
--with-thread-safety
Build with thread safety
--with-tidy
Include Tidy support
--without-bz2
Build without bz2 support
--without-mysql
Remove MySQL/MariaDB support
--without-pcntl
Build without Process Control support
--without-pear
Build without PEAR
install HEAD version
开始安装PHP5.5.15,安装后的php-fpm.ini以及php.ini都在目录:/usr/local/etc/php/5.5/下面
liondeMacBook-Pro:Library lion$ brew install php55 --with-mssql --with-homebrew-openssl --with-homebrew-libxslt --with-homebrew-curl --with-fpm --with-debug --with-gmp --with-imap --with-tidy --with-libmysql
==& Installing dependencies for php55: curl, freetds, gmp
==& Installing php55 dependency: curl
==& Downloading https://downloads.sf.net/project/machomebrew/Bottles/curl-7.37.1.mavericks.bottle.tar.gz
######################################################################## 100.0%
==& Pouring curl-7.37.1.mavericks.bottle.tar.gz
==& Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/curl/lib
CPPFLAGS: -I/usr/local/opt/curl/include
==& Summary
/usr/local/Cellar/curl/7.37.1: 285 files, 2.8M
==& Installing php55 dependency: freetds
==& Downloading http://mirrors.ibiblio.org/freetds/stable/freetds-0.91.tar.gz
######################################################################## 100.0%
==& ./configure --prefix=/usr/local/Cellar/freetds/0.91 --with-openssl=/usr/local/opt/openssl --with-tdsver=7.1 --mandir=/usr
==& make install
/usr/local/Cellar/freetds/0.91: 600 files, 9.9M, built in 2.2 minutes
==& Installing php55 dependency: gmp
==& Downloading https://downloads.sf.net/project/machomebrew/Bottles/gmp-6.0.0a.mavericks.bottle.tar.gz
######################################################################## 100.0%
==& Pouring gmp-6.0.0a.mavericks.bottle.tar.gz
/usr/local/Cellar/gmp/6.0.0a: 15 files, 3.2M
==& Installing php55
==& Downloading http://www.php.net/get/php-5.5.15.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php55-5.5.15
==& ./configure --prefix=/usr/local/Cellar/php55/5.5.15 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.5 --
==& make install
==& /usr/local/Cellar/php55/5.5.15/bin/pear config-set php_ini /usr/local/etc/php/5.5/php.ini
==& Caveats
The php.ini file can be found in:
/usr/local/etc/php/5.5/php.ini
✩✩✩✩ PEAR ✩✩✩✩
If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
chmod -R ug+w /usr/local/Cellar/php55/5.5.15/lib/php
pear config-set php_ini /usr/local/etc/php/5.5/php.ini
✩✩✩✩ Extensions ✩✩✩✩
If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
PATH="/usr/local/bin:$PATH"
PHP55 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:
export PATH="$(brew --prefix homebrew/php/php55)/bin:$PATH"
✩✩✩✩ FPM ✩✩✩✩
To launch php-fpm on startup:
* If this is your first install:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/php55/5.5.15/homebrew.mxcl.php55.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
* If this is an upgrade and you already have the homebrew.mxcl.php55.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
cp /usr/local/Cellar/php55/5.5.15/homebrew.mxcl.php55.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
The control script is located at /usr/local/Cellar/php55/5.5.15/sbin/php55-fpm
Mountain Lion comes with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
PATH="/usr/local/sbin:$PATH"
You may also need to edit the plist to use the correct "UserName".
Please note that the plist was called 'homebrew-php.josegonzalez.php55.plist' in old versions
of this formula.
To have launchd start php55 at login:
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
Then to load php55 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
==& Summary
/usr/local/Cellar/php55/5.5.15: 477 files, 43M, built in 3.9 minutes
过程中如果出现configure: error: Cannot find OpenSSL's &evp.h&这样的错误,请执行以下命令,将xcode进行更新:
xcode-select --install
在PHP5安装完成的提示中写到,如何进行PHP5和mac自带的php以及php-fpm替换,执行以下命令后,我们可以看到当前的php版本已经是最新的了:
liondeMacBook-Pro:~ lion$ echo 'export PATH=/usr/local/bin:$PATH' && ~/.bash_profile
liondeMacBook-Pro:~ lion$ echo 'export PATH=/usr/sbin:$PATH' && ~/.bash_profile
liondeMacBook-Pro:~ lion$ echo 'export PATH=/usr/local/sbin:$PATH' && ~/.bash_profile
liondeMacBook-Pro:~ lion$ source ~/.bash_profile
liondeMacBook-Pro:~ lion$ php -v
PHP 5.5.15 (cli) (built: Aug 14 :16) (DEBUG)
Copyright (c)
The PHP Group
Zend Engine v2.5.0, Copyright (c)
Zend Technologies
liondeMacBook-Pro:~ lion$
使用brew search php55-命令,可以查看还有哪些扩展可以安装,然后执行brew install php55-XXX就可以了。
liondeMacBook-Pro:~ lion$ brew search php55-
php55-amqp
php55-igbinary
php55-msgpack
php55-runkit
php55-varnish
php55-apcu
php55-imagick
php55-mysqlnd_ms
php55-scrypt
php55-augmentedtypes
php55-inclued
php55-oauth
php55-snappy
php55-wbxml
php55-binpack
php55-intl
php55-opcache
php55-solr
php55-xcache
php55-blitz
php55-ioncubeloader
php55-parsekit
php55-sphinx
php55-xdebug
php55-boxwood
php55-jsmin
php55-pcntl
php55-spl-types
php55-xhgui
php55-chdb
php55-judy
php55-pdflib
php55-ssh2
php55-couchbase
php55-leveldb
php55-pdo-dblib
php55-stats
php55-xhprof
php55-crypto
php55-libevent
php55-pdo-pgsql
php55-stemmer
php55-xmldiff
php55-dbase
php55-libvirt
php55-phalcon
php55-sundown
php55-dbus
php55-proctitle
php55-dmtx
php55-propro
php55-swoole
php55-yaml
php55-mailparse
php55-protobuf
php55-thrift
php55-gearman
php55-mcrypt
php55-pspell
php55-tidy
php55-geoip
php55-memcache
php55-pthreads
php55-timezonedb
php55-gmagick
php55-memcached
php55-raphf
php55-tokyotyrant
php55-yrmcds
php55-graphdat
php55-midgard2
php55-redis
php55-twig
php55-htscanner
php55-mongo
php55-redland
php55-uploadprogress
php55-zookeeper
php55-http
php55-mosquitto
php55-riak
php55-uuid
我安装的是以下php5.5几个扩展:
liondeMacBook-Pro:~ lion$ brew install php55-imagick php55-igbinary php55-ev php55-gmagick php55-geoip php55-memcache php55-memcached php55-thrift php55-xdebug php55-sphinx composer
接下来我们测试php-fpm的配置是否正确,以及是否正确启动:
#测试php-fpm配置是否正确
liondeMacBook-Pro:bin lion$ php-fpm -t
[14-Aug-:30] NOTICE: configuration file /usr/local/etc/php/5.5/php-fpm.conf test is successful
liondeMacBook-Pro:bin lion$ php-fpm -c /usr/local/etc/php/5.5/php.ini -y /usr/local/etc/php/5.5/php-fpm.conf -t
[14-Aug-:48] NOTICE: configuration file /usr/local/etc/php/5.5/php-fpm.conf test is successful
#启动php-fpm
liondeMacBook-Pro:bin lion$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
#查看9000端口是否在运行
liondeMacBook-Pro:bin lion$ lsof -i:9000
DEVICE SIZE/OFF NODE NAME
php-fpm 51241 lion
8u IPv4 0xce9d0f
0t0 TCP localhost:cslistener (LISTEN)
php-fpm 51243 lion
0u IPv4 0xce9d0f
0t0 TCP localhost:cslistener (LISTEN)
php-fpm 51244 lion
0u IPv4 0xce9d0f
0t0 TCP localhost:cslistener (LISTEN)
php-fpm 51245 lion
0u IPv4 0xce9d0f
0t0 TCP localhost:cslistener (LISTEN)
#关闭掉php-fpm进程,再查看9000端口,没有监听了
liondeMacBook-Pro:bin lion$ ps aux|grep php-fpm|grep -v 'grep'|awk '{print $2}'|xargs kill -9
liondeMacBook-Pro:bin lion$ lsof -i:9000
liondeMacBook-Pro:bin lion$
设置PHP-FPM开机运行(其实在安装完成的提示中,也有说明):
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
Copyright & 2016 phpStudy没有更多推荐了,
不良信息举报
举报内容:
MacOS下homebrew方式安装Apache24、php7、Mysql
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!Mac 下安装与配置 nginx php7.1
Mac 下安装与配置 nginx php7.1
apache和nginx解析的原理
对于apache而言,php是挂在apache下的一个模块,当http请求一个php文件时,apache会调用php模块进行解析,然后返回html给apache。#而nginx必须通过一个FastCGI的进程管理器来启动php解析,也就是php-fpm,当nginx接受php请求时,它会向它监听的fpm发送一个请求,当fpm接收到请求以后,再创建一个子进程来调用php进行解析。当解析完成后,回收线程,返回html给nginx。
查看Apache和PHP的版本号
MacBookPro:~ shuzehttpd?vServerversion:Apache/2.4.25(Unix)Serverbuilt:Feb:10MacBookPro:shuze php -v
PHP 5.6.30 (cli) (built: Feb 7 :37)
Copyright (c)
The PHP Group
Zend Engine v2.6.0, Copyright (c)
Zend Technologies
处理自带的apache
关闭系统自带的apache
sudo apachectl stop
如果apache已经加入了launchctl,这样关闭
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
可以选择直接删除相关的文件
sudo rm /usr/sbin/apachectl sudo rm /usr/sbin/httpd sudo rm -r /etc/apache2/
sudo rm /usr/sbin/httpd
sudo rm-rf/etc/apache2/
安装xcode命令行工具
Xcode-select &install
检查当前环境是否最新符合brew运行
MacBookPro:~ shuze$ brew doctor
Your system is ready to brew.
Homebrew安装
ruby -e &$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&
Homebrew 会将软件包安装到独立目录,并将其文件软链接至 /usr/local 。
Homebrew 不会将文件安装到它本身目录之外,你可将 Homebrew 安装到任意位置。
nginx的安装与配置
MacBookPro:~ shuze$ brew install nginx
如果需要安装nginx的其他版本,可以使用brew edit nginx来修改其内容
sudo nginx #打开
nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx
nginx -t #测试配置是否有语法错误
实际上,nginx服务的启动可以用-c nginx的配置文件参数制定其配置文件,默认加载/usr/local/etc/nginx/nginx.conf文件
启动nginx也可以: sudo brew services start nginx
停止nginx也可以: sudo brew services stop nginx
Check if Nginx is running on default port
curl -IL http://127.0.0.1:8080
curl -IL http://localhost
普通用户登陆时并且监听的端口在1024以下的,例如把默认的8080端口改为了80端口
要 nginx 开机启动的话,需要给予它管理员权限
sudo chown root:wheel /usr/local/opt/nginx/bin/nginx
sudo chmod u+s /usr/local/opt/nginx/bin/nginx
sudo chown root:wheel /usr/local/Cellar/nginx/1.10.0/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.10.0/bin/nginx
开机自启动nginx服务设置(加入launchctl启动控制):
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/nginx/1.10.0/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
打开 nginx 后,默认的访问端口 8080,如果要改为 80 端口,则要修改 &/usr/local/etc/nginx/nginx.conf& 下监听(listen)端口值。
默认的文件访问目录(root)是 &/usr/local/Cellar/nginx/1.2.6/html&(这里的1.2.6是安装的nginx的版本)。
安装之后更改下nginx.conf 的user nginx 的运行用户( #),为之后的运行脚本提供读写权限,以登录用户作为运行用户。
用法详解 nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
-?,-h : 打开帮助信息
-v : 显示版本信息并退出
-V : 显示版本和配置选项信息,然后退出
-t : 检测配置文件是否有语法错误,然后退出
-q : 在检测配置文件期间屏蔽非错误信息
-s signal : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
-p prefix : 设置前缀路径(默认是:/usr/local/Cellar/nginx/1.2.6/)
-c filename : 设置配置文件(默认是:/usr/local/etc/nginx/nginx.conf)
-g directives : 设置配置文件外的全局指令
php的安装和配置
brew 默认没有 php 安装包,引入第三方的php库:
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew tap homebrew/dupes && \ brew tap homebrew/php && \ brew install &without-apache &with-fpm &with- php70
brew search php7 查看一下有什么php7版本可以安装
安装php7.1:
brew install php71 &without-apache &with-fpm
(brew install php56 &with-imap &with-tidy &with-debug &with-pgsql &with-mysql &with-fpm)
brew services start php71
安装过程给出的重要提示
The php.ini file can be found in:
/usr/local/etc/php/7.1/php.ini
If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
PATH=&/usr/local/bin:PATH&IfyouwishtoswapthePHPyouunthecommandline,youshouldaddthefollowingto/.bashrc,/.zshrc,/.profileoryourshell&sequivalentconfigurationfile:exportPATH=&(brew --prefix homebrew/php/php71)/bin:$PATH&
由于Mac系统预装了php以及php-fpm,为了启动的时候能直接启动安装的最新的php,要把php安装的二进制文件所在的路径加入到系统路径中。
如果我们设置了开机的时候自动启动,我们不会发现有什么问题,可是当重新配置了扩展,需要重新启动php-fpm的时候,我们如果直接
使用php-fpm -c /usr/local/etc/php/7.1/php.ini -y /usr/local/ext/php/5.6/php-fpm.conf的时候,我们发现
我们的扩展安装没有起作用,原因是我们使用了/usr/sbin/php-fpm的命令,可以通过which查看。
使用brew安装的php-fpm是在 /usr/local/opt/php71/sbin目录下。
需要修改path,指定 php 的解析路径。
在~/.bashrc(没有则创建)最后加入一行:export PATH=&(brew??prefixphp71)/bin:PATH&
使之生效 source ~/.bashrc
export PATH=&brew??prefixphp71)/bin:PATH&
export PATH=/usr/local/opt/php71/bin:PATH将php路径加入PATHsudovim/.bashprofileexportPATH=&(brew --prefix php71)/bin:$PATH&
source ~/.bash_profile
到此,php以及PHP-fpm已经安装成功
设置php-fpm开机启动(加入launchctl启动控制)
MacBookPro:~ shuzemkdir?p/Library/LaunchAgentsMacBookPro:shuze cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
MacBookPro:~ shuze$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
cp /usr/local/Cellar/php71/7.1.8_20/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
/usr/local/etc/php/7.1/php-fpm.d/www.conf
user = _www
group = _www
user = YOUR_USERNAME
group = YOUR_GROUP || staff
启动php sudo brew services start php71
查看进程 lsof -Pni4 | grep LISTEN | grep php
安装过程很有用的命令:
杀死一个进程的命令:sudo kill -9 pid #pid替换为你的进程号
比如你要杀死php-fpm进程,也可以使用如下命令:sudo killall php-fpm
如何查看进程号:ps -ef | grep php-fpm
nginx后续配置
nginx的配置文件在 /usr/local/etc/nginx/文件中vim nginx.conf然后 根据 自己的需求去配置就行
include servers/*; 引入了servers目录的配置,在servers 里添加server 配置文件
vim phptest.conf #在servers目录添加一个vhost文件, 内容在后面
配置完毕,重载配置文件 sudo nginx -s reload
一切准备妥当,nginx 80 localhost 已经可以显示页面,php-fpm 9000端口已经运行。
下一步 添加host sudo vim /etc/hosts
添加一行 127.0.0.1 phptest.dev
测试一下 ping phptest.dev
配置 Nginx 支持 PHP-FPM
sudo vim /usr/local/etc/nginx/nginx.conf
添加默认首页 php
index index.php index.html index.
取消以下内容的注释,并做修改
location ~ .php{
fastcgi_intercept_
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.
fastcgi_paramSCRIPT_FILENAME/usr/local/Cellar/nginx/1.6.0_1/htmlfastcgi_script_
include /usr/local/etc/nginx/fastcgi_
在访问目录下(默认是/usr/local/Cellar/nginx/1.6.0_1/html)执行 php 文件了。在index.php测试一下 &phpinfo()& 吧
Mac下nginx的配置文件的默认存放路径--/usr/local/etc/nginx/,改文件下包括如下
1. sites-enabled(默认情况下没有sites-enabled这个文件夹,为了方便管理配置的server节点,创建sudo mkdir sites-enabled)
2. fastcgi.conf(提供参数的两个文件是 fastcgi.conf 和 fastcgi_params)
3. fastcgi_params(先有fastcgi_params,后有fastcgi.conf,除了SCRIPT_FILENAME这个参数之外,其他一模一样)
4. nginx.conf
nginx.conf
在server中修改本地服务访问的文件和访问的域名
listen 80;
server_ //访问的域名,修改server_name 不能相同
root /Users/LIAN/Desktop/DIY/trunk/; //本地文件地址,不能出现中文
index index.html index. //访问的文件
一个完整的nginx.conf例子
worker_processes 1;
error_log /Library/Logs/nginx/error.
worker_connections 1024;
include mime.
default_type application/octet-
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 /Library/Logs/nginx/access.
keepalive_timeout 65;
idex index.html index.
include /usr/local/etc/nginx/sites-enabled/*;
修改PHP配置文件
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.1/php-fpm.conf
include=/usr/local/etc/php/7.1/php-fpm.d/*.conf
/usr/local/etc/php/7.1/php-fpm.d/www.conf
listen = 127.0.0.1:9000
每次修改了php.ini文件都要重启php-fpm
sudo killall php-fpm #先停掉所有php-fpm的进程
cd /usr/local/Cellar/php71/7.1.8_20/sbin/
sudo ./php71-fpm start #启动php-fpm
这是一份相对简单的nginx配置
worker_processes 4;
worker_connections 1024;
include mime.
default_type application/octet-
log_format main &remoteaddr?remote_user [timelocal]&request& &
&statusbody_bytes_sent &httpreferer&&&&http_user_agent& &http_x_forwarded_for&&;
access_log/usr/local/var/log/nginx/access.
keepalive_timeout65;
charsetutf-8;
access_log/usr/local/var/log/nginx/localhost.access.
root/var/#你的网站根目录
location/{
indexindex.htmlindex.htmindex.
try_filesuri /ruiindex.php?
error_page 404 /404.
error_page 500 502 503 504 /50x.
location = /50x.html {
location ~ .php{
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.
fastcgi_paramSCRIPT_FILENAME/var/wwwfastcgi_script_
include fastcgi_
location ~ /.ht {
include sites-enabled/nginx-*.
下面给出一份sites-enabled文件夹下的nginx的配置。需要说明的是,上面的配置中的server节点中的内容,包括server,
可以单独拿出来,放在一份单独的配置中,由最后一句的include的命令引入。
phptest.conf
listen 80;
server_name phptest.dev 或 test.com之类;
charset koi8-r;
charset utf-8;
access_log /usr/local/var/log/nginx/phptest.dev.access.
error_log /usr/local/var/log/nginx/phptest.dev.error.
root /var/www/phptest/web根据实际目录;
location / {
try_files uriuri/ /index.php?$ ?????
index index.php index.html index.
error_page 404 /404.
redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.
location = /50x.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_pass127.0.0.1:9000;
fastcgi_indexindex.
fastcgi_paramSCRIPT_FILENAME/var/www/phptest/web(即document_root直接接后面的)$fastcgi_script_
include fastcgi_
try_files $uri =404;
deny access to .htaccess files, if Apache&s document root
concurs with nginx&s one
#location ~ /.ht {
如上,打开浏览器输入http://localhost/访问第一个server节点配置的服务,输入http://test-local.com/访问第二个server节点。
请修改hosts的host配置,打开/etc/hosts文件,加入一行: 127.0.0.1 test-local.com
将TCP改成socket方式的配置方法:
修改php-fpm.conf
vim /usr/local/etc/php/7.1/php-fpm.conf
vim /usr/local/etc/php/7.1/php-fpm.d/www.conf (更改这个文件)
;listen = 127.0.0.1:9000
listen = /var/run/php7.1-fpm.sock
修改nginx配置文件server段(fastcgi_pass 127.0.0.1:9000; to fastcgi_pass unix:/tmp/php5-fpm.sock)
location ~ [^/].php(/|$) {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/dev/shm/php-cgi.
重启php-fpm与nginx
我们要在这个php-fpm文件里面设置nginx的用户主,才不会显示502
listen = /tmp/www.sock
listen.owner = nobody //定义属主
listen.group = nobody //定义属组
版本高于5.4(含5.4) 默认监听的socket文件权限是所有者只读,属组和其他用户没有任何权限。所以,nginx的启动用户(咱们配置的是nobody)就没有办法去读这个socket文件,最终导致502,这个问题可以在nginx的错误日志中发现。解决办法很简单,上面给出的配置文件中就有避免这个问题的配置。
listen.owner = nobody //定义属主
listen.group = nobody //定义属组
这两个配置就是定义socket的属主和属组是谁。除了这个还有一种方法
listen.mode = 777 这样nobody也可以有读取权限了。}

我要回帖

更多关于 homebrew php fpm 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信