OS X上的Nginx和PHP-FPM

前端之家收集整理的这篇文章主要介绍了OS X上的Nginx和PHP-FPM前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我一直想用PHP-FPM试用Nginx.我通过Macports安装了Nginx.我读到PHP 5.3.3包含PHP-FPM,但Macports上的PHP 5.3.3配置无法启用它.

任何人都可以解释或推荐我如何在OS X上使用PHP-FPM为Nginx安装PHP 5.3.3的教程吗?我想将它放在/ opt中,其中Nginx是为了远离我在/usr/local中使用Apache的PHP.

我是命令行的新手.请原谅我的无知.

最佳答案
我能够把@Struder的答案带到上面并且大部分都能让它起作用,但就像@Seth我得到了“无法统计sapi / cgi / php-cgi错误.

我最终对Portfile进行了一些额外的调整:仅在使用fastcgi变体时添加enable-fpm,摆脱“无法统计错误,并将默认的PHP-fpm配置文件复制到位.配置文件仍然需要由用户自定义,但是这个端口文件将启动并运行PHP5.3.3.

# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 71588 2010-09-17 05:21:24Z ryandesign@macports.org $

PortSystem              1.0

name                    PHP5
conflicts               PHP5-devel PHP52
# Update revision of PHP5-eaccelerator when updating version of PHP5
epoch                   1
version                 5.3.3
revision                2
set major               [lindex [split ${version} .] 0]
set my_name             PHP${major}
dist_subdir             ${my_name}
categories              lang PHP www
maintainers             ryandesign jwa
homepage                http://www.PHP.net/
master_sites            PHP
distname                PHP-${version}
use_bzip2               yes
platforms               darwin freebsd
use_parallel_build      yes

description \
    PHP: Hypertext Preprocessor

long_description \
    PHP is a widely-used general-purpose scripting language \
    that is especially suited for developing web sites,but can also \
    be used for command-line scripting.

checksums \
    [suffix ${distname}] \
    md5     21ceeeb232813c10283a5ca1b4c87b48 \
    sha1    9f66716b341119e4e4f8fe3d81b7d0a5daf3cbc8 \
    rmd160  9edb51663feac9b787f8382012893f1ac98fec6a

depends_build \
    port:pkgconfig \
    port:autoconf213

depends_lib \
    path:bin/gsed:gsed \
    port:libtool \
    port:libxml2 \
    port:bzip2 \
    port:mhash \
    port:pcre \
    port:readline \
    port:zlib

# Use -p1 to accommodate the Suhosin patch
patch.pre_args          -p1
patchfiles              patch-scripts-PHP-config.in.diff \
                        patch-ext-MysqLnd-MysqLnd.h.diff

use_autoconf            yes
autoconf.cmd            ${prefix}/bin/autoconf213

set PHPinidir           ${prefix}/etc/${my_name}
set extraPHPinidir      ${prefix}/var/db/${my_name}

destroot.keepdirs       ${destroot}${extraPHPinidir}

configure.args \
    --mandir=${prefix}/share/man \
    --infodir=${prefix}/share/info \
    --with-config-file-path=${PHPinidir} \
    --with-config-file-scan-dir=${extraPHPinidir} \
    --disable-all \
    --enable-bcmath \
    --enable-ctype \
    --enable-dom \
    --enable-fileinfo \
    --enable-filter \
    --enable-hash \
    --enable-json \
    --enable-libxml \
    --enable-pdo \
    --enable-phar \
    --enable-session \
    --enable-simplexml \
    --enable-tokenizer \
    --enable-xml \
    --enable-xmlreader \
    --enable-xmlwriter \
    --with-bz2=${prefix} \
    --with-mhash=${prefix} \
    --with-pcre-regex=${prefix} \
    --with-readline=${prefix} \
    --with-libxml-dir=${prefix} \
    --with-zlib=${prefix} \
    --without-pear \
    --disable-cgi

# PHP5-MysqL +MysqLnd needs MysqLnd support compiled into PHP
configure.env-append    PHP_MysqLND_ENABLED=yes

configure.universal_args-delete --disable-dependency-tracking

platform darwin 10 {
    configure.env-append \
        LIBS=-lresolv
}

variant no_web conflicts apache apache2 fastcgi description {Don't include any web server support} {}

# Build an Apache 1 module. On Mac OS X,it uses Apple's provided Apache 1 server.
# On other platforms,the MacPorts apache port is used. Keep the options here
# in sync with those in the relevant part of the post-destroot phase.
variant apache conflicts apache2 no_web description {Add Apache 1 web server module} {
    if { ! [variant_isset macosx] && (![info exists os.subplatform] || ${os.subplatform} != "macosx") } {
        depends_lib-append \
            port:apache
        configure.args-append \
            --with-apxs=${prefix}/sbin/apxs
    } else {
        destroot.violate_mtree yes
        configure.args-append \
            --with-apxs=/usr/sbin/apxs
    }
}

# Build an Apache 2.2 module. Keep the options here in sync with those in the
# relevant part of the post-destroot phase.
variant apache2 conflicts apache no_web description {Add Apache 2.2 web server module} {
    pre-configure {
        # Checking for mod_cgi.so is a convenient way to verify apache2 is using its
        # +preforkmpm variant. (+eventmpm and +workermpm instead provide mod_cgid.so.)
        if {![file exists ${prefix}/apache2/modules/mod_cgi.so]} {
            ui_error "To use ${name} with the +apache2 variant,apache2 must be installed with the +preforkmpm variant."
            return -code error "incompatible apache2 installation"
        }
    }
    destroot.violate_mtree yes
    depends_lib-append \
        port:apache2
    configure.args-append \
        --with-apxs2=${prefix}/apache2/bin/apxs
}

# Build a FastCGI binary. Keep the options here in sync with those in the
# relevant part of the post-destroot phase.
variant fastcgi conflicts no_web description {Add FastCGI web server binary} {
    if { ![variant_isset apache] && ![variant_isset apache2] } {
        configure.args-delete \
            --disable-cgi
        configure.args-append \
            --enable-fpm \
            --enable-cgi
    }
}

foreach {old_variant new_port} {
    gmp             gmp
    imap            imap
    macports_snmp   snmp
    mssql           mssql
    MysqL4          MysqL
    MysqL5          MysqL
    MysqLnd         MysqL
    oracle          oracle
    pcntl           pcntl
    postgresql82    postgresql
    postgresql83    postgresql
    pspell          pspell
    snmp            snmp
    sockets         sockets
    sqlite          sqlite
    tidy            tidy
} {
    eval [subst {
        variant ${old_variant} description "Obsolete; install ${my_name}-${new_port} port instead" {
            pre-configure {
                ui_msg "The +${old_variant} variant is obsolete. Please install the ${my_name}-${new_port} port instead."
            }
        }
    }]
}

variant ipc description {Add semaphore,shared memory and IPC functions} {
    configure.args-append \
        --enable-shmop \
        --enable-sysvsem \
        --enable-sysvshm \
        --enable-sysvmsg
}

if {![variant_isset apache] && ![variant_isset apache2] && ![variant_isset fastcgi] && ![variant_isset no_web]} {
    default_variants +apache2
}

variant pear description {Add PEAR} {
    configure.args-delete \
        --without-pear
    configure.args-append \
        --with-pear=${prefix}/lib/PHP
    destroot.target-append \
        install-pear
    destroot.args-append \
        PHP_PEAR_INSTALL_DIR=${prefix}/lib/PHP
    post-destroot {
        #nuke pear-stuff in ${destroot}
        system "cd ${destroot} && rm -rf .channels .depdb .depdblock .filemap .lock"

        system "if \[ -f ${prefix}/lib/PHP/.depdblock \]; then rm -f ${destroot}${prefix}/lib/PHP/.depdblock; fi"
        system "if \[ -f ${prefix}/lib/PHP/.depdb \]; then rm -f ${destroot}${prefix}/lib/PHP/.depdb; fi"
        system "if \[ -f ${prefix}/lib/PHP/.filemap \]; then rm -f ${destroot}${prefix}/lib/PHP/.filemap; fi"
        system "if \[ -f ${prefix}/lib/PHP/.lock \]; then rm -f ${destroot}${prefix}/lib/PHP/.lock; fi"
        system "if \[ -d ${prefix}/lib/PHP/.channels \]; then rm -rf ${destroot}${prefix}/lib/PHP/.channels; fi"
    }
}

variant suhosin description {Add Suhosin patch} {
    pre-fetch {
        if {"darwin" == ${os.platform} && ${os.major} < 9} {
            ui_error "The suhosin variant requires Mac OS X 10.5 or greater."
            return -code error "incompatible Mac OS X version"
        }
    }
    set suhosin_patch_version   ${version}-0.9.10
    set suhosin_patch           suhosin-patch-${suhosin_patch_version}.patch.gz
    patch_sites-append          http://download.suhosin.org/
    patchfiles-append           ${suhosin_patch}
    checksums-append \
        ${suhosin_patch} \
            md5     b66b27c43b1332400ef8982944c3b95b \
            sha1    76675242cfdeff763767900213346af622002490 \
            rmd160  8dcd8b51ea0357b6cc51e70e495e18f341c62f7c
}

destroot.args \
    INSTALL_ROOT=${destroot}

destroot.target \
    install-cli install-build install-headers install-programs

post-destroot {
    # Copy the Apache 1 module.
    if { [variant_isset apache] } {
        xinstall -m 755 -d ${destroot}${prefix}/libexec/apache \
            ${destroot}${prefix}/etc/apache/extra
        xinstall -m 755 ${worksrcpath}/libs/libPHP5.so ${destroot}${prefix}/libexec/apache/
        xinstall -m 755 -c ${filespath}/mod_PHP.conf ${destroot}$prefix/etc/apache/extra
    }

    # Copy the Apache 2.2 module.
    if { [variant_isset apache2] } {
        xinstall -m 755 -d ${destroot}${prefix}/apache2/modules \
            ${destroot}${prefix}/apache2/conf/extra
        xinstall -m 755 ${worksrcpath}/libs/libPHP5.so ${destroot}${prefix}/apache2/modules/
        xinstall -m 755 -c ${filespath}/mod_PHP.conf ${destroot}${prefix}/apache2/conf/extra
    }

    if { [variant_isset fastcgi] } {
        # If we've built an Apache module (any version) then the FastCGI binary
        # will not have been built,so we need to run through the whole process
        # again and build just the FastCGI binary. Keep the options here in sync
        # with the options specified in the apache and apache2 variants.
        if { [variant_isset apache] } {
            if { ![variant_isset macosx] && (![info exists os.subplatform] || ${os.subplatform} != "macosx") } {
                configure.args-delete \
                    --with-apxs=${prefix}/sbin/apxs
            } else {
                configure.args-delete \
                    --with-apxs=/usr/sbin/apxs
            }
        }
        if { [variant_isset apache2] } {
            configure.args-delete \
                --with-apxs2=${prefix}/apache2/bin/apxs
        }

        # Run the build again to get the FastCGI binary. Keep the options here
        # in sync with those in the fastcgi variant.
        if { [variant_isset apache] || [variant_isset apache2] } {
            configure.args-delete \
                --disable-cgi
            configure.args-append \
                --enable-fpm \
                --enable-cgi
            ui_msg "$UI_PREFIX Configuring ${name} again for fastcgi"
            command_exec configure
            ui_msg "$UI_PREFIX Building ${name} again for fastcgi"
            command_exec build
            ui_msg "$UI_PREFIX Staging ${name} fastcgi into destroot"
        }

        # Copy the FastCGI binary to the bin dir under a new name so it doesn't
        # conflict with the cli version.
        if {[file exists ${worksrcpath}/sapi/cgi/php-cgi]} {
            xinstall -m 755 ${worksrcpath}/sapi/cgi/php-cgi ${destroot}${prefix}/bin
        }

        # Copy the default FastCGI config
        xinstall -m 644 ${worksrcpath}/sapi/fpm/PHP-fpm.conf ${destroot}${prefix}/etc/
    }

    #file rename ${destroot}${prefix}/etc/pear.conf ${destroot}${prefix}/etc/pear.conf.sample

    # Copy the default PHP.ini files.
    xinstall -m 755 -d ${destroot}${PHPinidir}
    xinstall -m 644 -W ${worksrcpath} \
        PHP.ini-development \
        PHP.ini-production \
        ${destroot}${PHPinidir}

    # Copy MysqLnd headers.
    xinstall -d ${destroot}${prefix}/include/PHP/ext/MysqLnd
    eval xinstall -m 644 [glob ${worksrcpath}/ext/MysqLnd/*.h] ${destroot}${prefix}/include/PHP/ext/MysqLnd
}

pre-activate {
    set filepath ${extraPHPinidir}/.turd_${name}
    if {[file exists ${filepath}]} {
        delete ${filepath}
    }
}

post-activate {
    if {[file exists ${prefix}/etc/PHP.ini] && ![file exists ${PHPinidir}/PHP.ini]} {
        move ${prefix}/etc/PHP.ini ${PHPinidir}
        ui_msg "Your ${prefix}/etc/PHP.ini has been moved to ${PHPinidir}/PHP.ini"
        ui_msg ""
    }
    if {![file exists ${PHPinidir}/PHP.ini]} {
        ui_msg "To customize PHP,copy"
        ui_msg "${PHPinidir}/PHP.ini-development (if this is a development server) or"
        ui_msg "${PHPinidir}/PHP.ini-production (if this is a production server) to"
        ui_msg "${PHPinidir}/PHP.ini and then make changes."
    } else {
        ui_msg "You may need to update your PHP.ini for any changes that have been made"
        ui_msg "in this version of PHP. Compare ${PHPinidir}/PHP.ini with"
        ui_msg "${PHPinidir}/PHP.ini-development (if this is a development server) or"
        ui_msg "${PHPinidir}/PHP.ini-production (if this is a production server)."
    }

    if {![variant_isset no_web]} {
        ui_msg ""
        ui_msg "If this is your first install,you need to activate PHP in your web server."
        if {![variant_isset fastcgi]} {
            if {[variant_isset apache]} {
                set moduledir ${prefix}/libexec/modules
                set apxs ${prefix}/apache/bin/apxs
            }
            if {[variant_isset apache2]} {
                set moduledir ${prefix}/apache2/modules
                set apxs ${prefix}/apache2/bin/apxs
            }
            ui_msg ""
            ui_msg "To enable PHP in Apache,run"
            ui_msg "  cd ${moduledir}"
            ui_msg "  ${apxs} -a -e -n \"${my_name}\" lib${my_name}.so"
        }
    }

    #ui_msg "* copy  ${prefix}/etc/pear.conf.sample to  ${prefix}/etc/pear.conf"
}

variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {
    configure.args-append   --enable-debug
}

test.run                yes

livecheck.type          regex
livecheck.url           ${homepage}downloads.PHP
livecheck.regex         get/PHP-(5\\.\[0-9.\]+)\\.tar
原文链接:https://www.f2er.com/nginx/435295.html

猜你在找的Nginx相关文章