Skip to content

Instantly share code, notes, and snippets.

@gonzaloserrano
Created February 9, 2015 15:18
Show Gist options
  • Save gonzaloserrano/04e269fa5911d093cb1e to your computer and use it in GitHub Desktop.
Save gonzaloserrano/04e269fa5911d093cb1e to your computer and use it in GitHub Desktop.
require 'formula'
class UnsupportedPhpApiError < RuntimeError
def initialize
super "Unsupported PHP API Version"
end
end
class InvalidPhpizeError < RuntimeError
def initialize(installed_php_version, required_php_version)
super <<-EOS.undent
Version of phpize (PHP#{installed_php_version}) in $PATH does not support building this extension
version (PHP#{required_php_version}). Consider installing with the `--without-homebrew-php` flag.
EOS
end
end
class AbstractPhpExtension < Formula
def initialize(*)
super
if build.without? 'homebrew-php'
installed_php_version = nil
i = IO.popen("#{phpize} -v")
out = i.readlines.join("")
i.close
{ 53 => 20090626, 54 => 20100412, 55 => 20121113 }.each do |v, api|
installed_php_version = v.to_s if out.match(/#{api}/)
end
raise UnsupportedPhpApiError.new if installed_php_version.nil?
required_php_version = php_branch.sub('.', '').to_s
unless installed_php_version == required_php_version
raise InvalidPhpizeError.new(installed_php_version, required_php_version)
end
end
end
def self.init
depends_on 'autoconf' => :build
option 'without-homebrew-php', "Ignore homebrew PHP and use default instead"
option 'without-config-file', "Do not install extension config file"
end
def php_branch
class_name = self.class.name.split("::").last
matches = /^Php5([3-9]+)/.match(class_name)
if matches
"5." + matches[1]
else
raise "Unable to guess PHP branch for #{class_name}"
end
end
def php_formula
'php' + php_branch.sub('.', '')
end
def safe_phpize
ENV["PHP_AUTOCONF"] = "#{Formula["autoconf"].opt_bin}/autoconf"
ENV["PHP_AUTOHEADER"] = "#{Formula["autoconf"].opt_bin}/autoheader"
system phpize
end
def phpize
if build.without? 'homebrew-php'
"phpize"
else
"#{Formula[php_formula].opt_bin}/phpize"
end
end
def phpini
if build.without? 'homebrew-php'
"php.ini presented by \"php --ini\""
else
"#{Formula[php_formula].config_path}/php.ini"
end
end
def phpconfig
if build.without? 'homebrew-php'
""
else
"--with-php-config=#{Formula[php_formula].opt_bin}/php-config"
end
end
def extension
class_name = self.class.name.split("::").last
matches = /^Php5[3-9](.+)/.match(class_name)
if matches
matches[1].downcase
else
raise "Unable to guess PHP extension name for #{class_name}"
end
end
def extension_type
# extension or zend_extension
"extension"
end
def module_path
prefix / "#{extension}.so"
end
def config_file
begin
<<-EOS.undent
[#{extension}]
#{extension_type}="#{module_path}"
EOS
rescue Exception
nil
end
end
def caveats
caveats = [ "To finish installing #{extension} for PHP #{php_branch}:" ]
if build.without? "config-file"
caveats << " * Add the following line to #{phpini}:\n"
caveats << config_file
else
caveats << " * #{config_scandir_path}/#{config_filename} was created,"
caveats << " do not forget to remove it upon extension removal."
end
caveats << <<-EOS
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the #{extension} module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run "php -i" (command-line "phpinfo()")
* - Look for the info on the #{extension} module.
* - If you see it, you have been successful!
EOS
caveats.join("\n")
end
def config_path
etc / "php" / php_branch
end
def config_scandir_path
config_path / "conf.d"
end
def config_filename
"ext-" + extension + ".ini"
end
def config_filepath
config_scandir_path / config_filename
end
def write_config_file
if config_filepath.file?
inreplace config_filepath do |s|
s.gsub!(/^(;)?(\s*)(zend_)?extension=.+$/, "\\1\\2#{extension_type}=\"#{module_path}\"")
end
elsif config_file
config_scandir_path.mkpath
config_filepath.write(config_file)
end
end
end
class AbstractPhp53Extension < AbstractPhpExtension
include AbstractPhpVersion::Php53Defs
def self.init opts=[]
super()
depends_on "php53" => opts if build.with?('homebrew-php')
end
end
class AbstractPhp54Extension < AbstractPhpExtension
include AbstractPhpVersion::Php54Defs
def self.init opts=[]
super()
depends_on "php54" => opts if build.with?('homebrew-php')
end
end
class AbstractPhp55Extension < AbstractPhpExtension
include AbstractPhpVersion::Php55Defs
def self.init opts=[]
super()
depends_on "php55" => opts if build.with?('homebrew-php')
end
end
class AbstractPhp56Extension < AbstractPhpExtension
include AbstractPhpVersion::Php56Defs
def self.init opts=[]
super()
depends_on "php56" => opts if build.with?('homebrew-php')
end
end
class AbstractPhpVersion < Formula
module PhpdbgDefs
PHPDBG_SRC_TARBAL = 'https://github.com/krakjoe/phpdbg/archive/v0.3.2.tar.gz'
PHPDBG_CHECKSUM = {
:md5 => '84255abff00fb31e338d03564c3cc4e4',
:sha1 => 'c57174ab235ec69997e1a37e6d2afe3e4edfb749',
:sha256 => 'feab6e29ef9a490aa53332fe014e8026d89d970acc5105f37330b2f31e711bbd',
}
end
module Php53Defs
PHP_SRC_TARBALL = 'https://www.php.net/get/php-5.3.29.tar.bz2/from/this/mirror'
PHP_GITHUB_URL = 'https://github.com/php/php-src.git'
PHP_VERSION = '5.3.29'
PHP_BRANCH = 'PHP-5.3'
PHP_CHECKSUM = {
:md5 => '9469e240cbe6ac865aeaec89b253dd30',
:sha1 => '6e9e492c6d5853d063ddb9a4dbef60b8e5d87444',
:sha256 => 'c4e1cf6972b2a9c7f2777a18497d83bf713cdbecabb65d3ff62ba441aebb0091',
}
end
module Php54Defs
PHP_SRC_TARBALL = 'https://www.php.net/get/php-5.4.37.tar.bz2/from/this/mirror'
PHP_GITHUB_URL = 'https://github.com/php/php-src.git'
PHP_VERSION = '5.4.37'
PHP_BRANCH = 'PHP-5.4'
PHP_CHECKSUM = {
:md5 => '1962086593e8e39342674be0483db439',
:sha1 => '608e00a730e9674e1a2e2627175e7a27f4add18f',
:sha256 => '857bf6675eeb0ae9c3cd6f9ccdb2a9b7bf89dcfda7f0a80857638fe023f3a8ad',
}
end
module Php55Defs
PHP_SRC_TARBALL = 'https://www.php.net/get/php-5.5.21.tar.bz2/from/this/mirror'
PHP_GITHUB_URL = 'https://github.com/php/php-src.git'
PHP_VERSION = '5.5.21'
PHP_BRANCH = 'PHP-5.5'
PHP_CHECKSUM = {
:md5 => '8fe631ac52a3df9d6429faad81cf2562',
:sha1 => 'a6251bb3565f144593df4329fd15bedd70ae13a8',
:sha256 => '62e9429975c4ca5d7067a5052d5388fbf2ac8c51eeee581d59b04cc5a8da83fe',
}
end
module Php56Defs
PHP_SRC_TARBALL = 'https://www.php.net/get/php-5.6.5.tar.bz2/from/this/mirror'
PHP_GITHUB_URL = 'https://github.com/php/php-src.git'
PHP_VERSION = '5.6.5'
PHP_BRANCH = 'PHP-5.6'
PHP_CHECKSUM = {
:md5 => '64d0debf42bfff537d891e1fe1a4b65c',
:sha1 => 'a523a13110a66f020c36f088089d2c5c7de9f6a9',
:sha256 => 'adab4c0775512a5ca0ae74e08efdc941d92529b75283e0f44d3f53822cdfd06d',
}
end
end
#encoding: utf-8
class AbstractPhp < Formula
def self.init
homepage 'https://php.net'
# So PHP extensions don't report missing symbols
skip_clean 'bin', 'sbin'
head do
depends_on 'autoconf' => :build
depends_on 're2c' => :build
depends_on 'flex' => :build
depends_on 'homebrew/versions/bison27' => :build
end
depends_on 'curl' if build.include?('with-homebrew-curl') || MacOS.version < :lion
depends_on 'enchant' => :optional
depends_on 'freetds' if build.include?('with-mssql')
depends_on 'freetype'
depends_on 'gettext'
depends_on 'gmp' => :optional
depends_on 'icu4c'
depends_on 'imap-uw' if build.include?('with-imap')
depends_on 'jpeg'
depends_on 'libpng'
depends_on 'libxml2' unless MacOS.version >= :lion
depends_on 'openssl' if build.include?('with-homebrew-openssl')
depends_on 'homebrew/dupes/tidy' if build.include?('with-tidy')
depends_on 'unixodbc'
depends_on 'homebrew/dupes/zlib'
depends_on 'libtool' => :build if build.without? 'disable-opcache'
deprecated_option "with-pgsql" => "with-postgresql"
depends_on :postgresql => :optional
# Sanity Checks
if build.include?('with-cgi') && build.include?('with-fpm')
raise "Cannot specify more than one executable to build."
end
option 'homebrew-apxs', 'Build against apxs in Homebrew prefix'
option 'with-homebrew-curl', 'Include Curl support via Homebrew'
option 'with-debug', 'Compile with debugging symbols'
option 'with-libmysql', 'Include (old-style) libmysql support instead of mysqlnd'
option 'without-mysql', 'Remove MySQL/MariaDB support'
option 'with-mssql', 'Include MSSQL-DB support'
option 'with-pdo-oci', 'Include Oracle databases (requries ORACLE_HOME be set)'
option 'with-cgi', 'Enable building of the CGI executable (implies --without-apache)'
option 'with-fpm', 'Enable building of the fpm SAPI executable (implies --without-apache)'
option 'with-phpdbg', 'Enable building of the phpdbg SAPI executable (PHP 5.4 and above)'
option 'with-apache', 'Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache'
option 'with-imap', 'Include IMAP extension'
option 'without-pear', 'Build without PEAR'
option 'with-tidy', 'Include Tidy support'
option 'with-thread-safety', 'Build with thread safety'
option 'with-homebrew-openssl', 'Include OpenSSL support via Homebrew'
option 'with-homebrew-libxslt', 'Include LibXSLT support via Homebrew'
option 'without-bz2', 'Build without bz2 support'
option 'without-snmp', 'Build without SNMP support'
option 'without-pcntl', 'Build without Process Control support'
option 'disable-opcache', 'Build without Opcache extension'
end
# Fixes the pear .lock permissions issue that keeps it from operating correctly.
# Thanks mistym & #machomebrew
skip_clean 'lib/php/.lock'
def config_path
etc+"php"+php_version
end
def home_path
File.expand_path("~")
end
def build_apache?
build.with?('apache') || !(build.with?('cgi') || build.with?('fpm'))
end
def php_version
raise "Unspecified php version"
end
def php_version_path
raise "Unspecified php version path"
end
def install
# Ensure this php has a version specified
php_version
php_version_path
# Not removing all pear.conf and .pearrc files from PHP path results in
# the PHP configure not properly setting the pear binary to be installed
config_pear = "#{config_path}/pear.conf"
user_pear = "#{home_path}/pear.conf"
config_pearrc = "#{config_path}/.pearrc"
user_pearrc = "#{home_path}/.pearrc"
if File.exist?(config_pear) || File.exist?(user_pear) || File.exist?(config_pearrc) || File.exist?(user_pearrc)
opoo "Backing up all known pear.conf and .pearrc files"
opoo <<-INFO
If you have a pre-existing pear install outside
of homebrew-php, or you are using a non-standard
pear.conf location, installation may fail.
INFO
mv(config_pear, "#{config_pear}-backup") if File.exist? config_pear
mv(user_pear, "#{user_pear}-backup") if File.exist? user_pear
mv(config_pearrc, "#{config_pearrc}-backup") if File.exist? config_pearrc
mv(user_pearrc, "#{user_pearrc}-backup") if File.exist? user_pearrc
end
begin
_install
rm_f("#{config_pear}-backup") if File.exist? "#{config_pear}-backup"
rm_f("#{user_pear}-backup") if File.exist? "#{user_pear}-backup"
rm_f("#{config_pearrc}-backup") if File.exist? "#{config_pearrc}-backup"
rm_f("#{user_pearrc}-backup") if File.exist? "#{user_pearrc}-backup"
rescue Exception
mv("#{config_pear}-backup", config_pear) if File.exist? "#{config_pear}-backup"
mv("#{user_pear}-backup", user_pear) if File.exist? "#{user_pear}-backup"
mv("#{config_pearrc}-backup", config_pearrc) if File.exist? "#{config_pearrc}-backup"
mv("#{user_pearrc}-backup", user_pearrc) if File.exist? "#{user_pearrc}-backup"
raise
end
end
def apache_apxs
if build.include? 'homebrew-apxs'
['sbin', 'bin'].each do |dir|
if File.exist?(location = "#{HOMEBREW_PREFIX}/#{dir}/apxs")
return location
end
end
else
'/usr/sbin/apxs'
end
end
def default_config
"./php.ini-development"
end
def skip_pear_config_set?
build.without? 'pear'
end
def patches
# Bug in PHP 5.x causes build to fail on OSX 10.5 Leopard due to
# outdated system libraries being first on library search path:
# https://bugs.php.net/bug.php?id=44294
"https://gist.github.com/ablyler/6579338/raw/5713096862e271ca78e733b95e0235d80fed671a/Makefile.global.diff" if MacOS.version == :leopard
end
def install_args
args = [
"--prefix=#{prefix}",
"--localstatedir=#{var}",
"--sysconfdir=#{config_path}",
"--with-config-file-path=#{config_path}",
"--with-config-file-scan-dir=#{config_path}/conf.d",
"--with-iconv-dir=/usr",
"--enable-dba",
"--with-ndbm=/usr",
"--enable-exif",
"--enable-intl",
"--enable-soap",
"--enable-wddx",
"--enable-ftp",
"--enable-sockets",
"--enable-zip",
"--enable-shmop",
"--enable-sysvsem",
"--enable-sysvshm",
"--enable-sysvmsg",
"--enable-mbstring",
"--enable-mbregex",
"--enable-bcmath",
"--enable-calendar",
"--with-zlib=#{Formula['zlib'].opt_prefix}",
"--with-ldap",
"--with-ldap-sasl=/usr",
"--with-xmlrpc",
"--with-kerberos=/usr",
"--with-gd",
"--enable-gd-native-ttf",
"--with-freetype-dir=#{Formula['freetype'].opt_prefix}",
"--with-icu-dir=#{Formula['icu4c'].opt_prefix}",
"--with-jpeg-dir=#{Formula['jpeg'].opt_prefix}",
"--with-png-dir=#{Formula['libpng'].opt_prefix}",
"--with-gettext=#{Formula['gettext'].opt_prefix}",
"--with-libedit",
"--with-unixODBC=#{Formula['unixodbc'].opt_prefix}",
"--with-pdo-odbc=unixODBC,#{Formula['unixodbc'].opt_prefix}",
"--mandir=#{man}",
"--with-mhash",
]
if build.include?('with-homebrew-curl') || MacOS.version < :lion
args << "--with-curl=#{Formula['curl'].opt_prefix}"
else
args << "--with-curl"
end
if build.with? 'snmp'
if MacOS.version >= :yosemite && (build.include?('with-thread-safety') || build.include?('with-homebrew-openssl'))
raise "Please add --without-snmp if you wish to use --with-thread-safety or --with-homebrew-openssl on >= Yosemite. See issue #1311 (http://git.io/NBAOvA) for details."
end
args << "--with-snmp=/usr"
else
args << "--without-snmp"
end
unless MacOS.version >= :lion
args << "--with-libxml-dir=#{Formula['libxml2'].opt_prefix}"
end
if build.with? 'bz2'
args << '--with-bz2=/usr'
end
if build.with? 'debug'
args << "--enable-debug"
else
args << "--disable-debug"
end
if build.with? 'homebrew-openssl'
args << "--with-openssl=" + Formula['openssl'].opt_prefix.to_s
else
args << "--with-openssl=/usr"
end
if build.with? 'homebrew-libxslt'
args << "--with-xsl=" + Formula['libxslt'].opt_prefix.to_s
else
args << "--with-xsl=/usr"
end
if build.with? 'fpm'
args << "--enable-fastcgi"
args << "--enable-fpm"
args << "--with-fpm-user=_www"
args << "--with-fpm-group=_www"
(prefix+'var/log').mkpath
touch prefix+'var/log/php-fpm.log'
plist_path.write plist
plist_path.chmod 0644
elsif build.with? 'cgi'
args << "--enable-cgi"
end
# Build Apache module by default
if build_apache?
args << "--with-apxs2=#{apache_apxs}"
args << "--libexecdir=#{libexec}"
end
if build.with? 'enchant'
args << "--with-enchant=#{Formula['enchant'].opt_prefix}"
end
if build.with? 'gmp'
args << "--with-gmp=#{Formula['gmp'].opt_prefix}"
end
if build.with? 'imap'
args << "--with-imap=#{Formula['imap-uw'].opt_prefix}"
if build.with? 'homebrew-openssl'
args << "--with-imap-ssl=" + Formula['openssl'].opt_prefix.to_s
else
args << "--with-imap-ssl=/usr"
end
end
if build.with? 'mssql'
args << "--with-mssql=#{Formula['freetds'].opt_prefix}"
args << "--with-pdo-dblib=#{Formula['freetds'].opt_prefix}"
end
if build.with? 'libmysql'
args << "--with-mysql-sock=/tmp/mysql.sock"
args << "--with-mysqli=#{HOMEBREW_PREFIX}/bin/mysql_config"
args << "--with-mysql=#{HOMEBREW_PREFIX}"
args << "--with-pdo-mysql=#{HOMEBREW_PREFIX}"
elsif build.with? 'mysql'
args << "--with-mysql-sock=/tmp/mysql.sock"
args << "--with-mysqli=mysqlnd"
args << "--with-mysql=mysqlnd"
args << "--with-pdo-mysql=mysqlnd"
end
if build.with? 'postgresql'
if Formula['postgresql'].opt_prefix.directory?
args << "--with-pgsql=#{Formula['postgresql'].opt_prefix}"
args << "--with-pdo-pgsql=#{Formula['postgresql'].opt_prefix}"
else
args << "--with-pgsql=#{`pg_config --includedir`}"
args << "--with-pdo-pgsql=#{`which pg_config`}"
end
end
if build.with? 'pdo-oci'
if ENV.has_key?('ORACLE_HOME')
args << "--with-pdo-oci=#{ENV['ORACLE_HOME']}"
else
raise "Environmental variable ORACLE_HOME must be set to use --with-pdo-oci option."
end
end
if build.with? 'tidy'
args << "--with-tidy=#{Formula['tidy'].opt_prefix}"
end
if build.without? 'pear'
args << "--without-pear"
end
if build.with? 'thread-safety'
args << "--enable-maintainer-zts"
end
if build.with? 'pcntl'
args << "--enable-pcntl"
end
if build.with? 'phpdbg'
args << "--enable-phpdbg"
end
return args
end
def _install
system "./buildconf" if build.head?
system "./configure", *install_args()
if build_apache?
# Use Homebrew prefix for the Apache libexec folder
inreplace "Makefile",
/^INSTALL_IT = \$\(mkinstalldirs\) '([^']+)' (.+) LIBEXECDIR=([^\s]+) (.+)$/,
"INSTALL_IT = $(mkinstalldirs) '#{libexec}/apache2' \\2 LIBEXECDIR='#{libexec}/apache2' \\4"
end
inreplace 'Makefile' do |s|
s.change_make_var! "EXTRA_LIBS", "\\1 -lstdc++"
end
system "make"
ENV.deparallelize # parallel install fails on some systems
system "make install"
unless File.exist? config_path+"php.ini"
config_path.install default_config => "php.ini"
if (!build.include? 'disable-opcache') && php_version.start_with?('5.5', '5.6')
inreplace config_path+"php.ini" do |s|
s.sub!(/^(\[opcache\].*)$/, "\\1\n; Load the opcache extension\nzend_extension=opcache.so\n")
s.gsub!(/^;?opcache\.enable\s*=.+$/,'opcache.enable=0')
end
end
end
chmod_R 0775, lib+"php"
system bin+"pear", "config-set", "php_ini", config_path+"php.ini", "system" unless skip_pear_config_set?
# remove intl.ini, since it is now always compiled into php
intl_config = config_path + "conf.d/ext-intl.ini"
if intl_config.file?
File.delete intl_config
end
if build.with? 'fpm'
if File.exist?('sapi/fpm/init.d.php-fpm')
sbin.install 'sapi/fpm/init.d.php-fpm' => "php#{php_version_path}-fpm"
end
if File.exist?('sapi/cgi/fpm/php-fpm')
sbin.install 'sapi/cgi/fpm/php-fpm' => "php#{php_version_path}-fpm"
end
if !File.exist?(config_path+"php-fpm.conf")
if File.exist?('sapi/fpm/php-fpm.conf')
config_path.install 'sapi/fpm/php-fpm.conf'
end
if File.exist?('sapi/cgi/fpm/php-fpm.conf')
config_path.install 'sapi/cgi/fpm/php-fpm.conf'
end
inreplace config_path+"php-fpm.conf" do |s|
s.sub!(/^;?daemonize\s*=.+$/,'daemonize = no')
s.sub!(/^;include\s*=.+$/,";include=#{config_path}/fpm.d/*.conf")
s.sub!(/^;?listen\.mode\s*=.+$/,'listen.mode = 0666')
s.sub!(/^;?pm\.max_children\s*=.+$/,'pm.max_children = 10')
s.sub!(/^;?pm\.start_servers\s*=.+$/,'pm.start_servers = 3')
s.sub!(/^;?pm\.min_spare_servers\s*=.+$/,'pm.min_spare_servers = 2')
s.sub!(/^;?pm\.max_spare_servers\s*=.+$/,'pm.max_spare_servers = 5')
end
end
end
end
def caveats
s = []
if build_apache?
if MacOS.version <= :leopard
s << <<-EOS.undent
For 10.5 and Apache:
Apache needs to run in 32-bit mode. You can either force Apache to start
in 32-bit mode or you can thin the Apache executable.
EOS
end
s << <<-EOS.undent
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module #{HOMEBREW_PREFIX}/opt/php#{php_version_path}/libexec/apache2/libphp5.so
EOS
end
s << <<-EOS.undent
The php.ini file can be found in:
#{config_path}/php.ini
EOS
if build.with? 'pear'
s << <<-EOS.undent
✩✩✩✩ PEAR ✩✩✩✩
If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
chmod -R ug+w #{lib}/php
pear config-set php_ini #{etc}/php/#{php_version}/php.ini system
EOS
end
s << <<-EOS.undent
✩✩✩✩ Extensions ✩✩✩✩
If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing #{HOMEBREW_PREFIX}/bin before /usr/sbin in your PATH:
PATH="#{HOMEBREW_PREFIX}/bin:$PATH"
PHP#{php_version_path} Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
EOS
s << <<-EOS.undent
✩✩✩✩ 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/php#{php_version.gsub('.','')})/bin:$PATH"
EOS
if build.include?('with-mcrypt')
s << <<-EOS.undent
✩✩✩✩ Mcrypt ✩✩✩✩
mcrypt is no longer included by default, install it as a separate extension:
brew install php#{php_version_path}-mcrypt
EOS
end
if build.include?('with-fpm')
s << <<-EOS.undent
✩✩✩✩ FPM ✩✩✩✩
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp #{opt_prefix}/#{plist_name}.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/#{plist_name}.plist
The control script is located at #{opt_sbin}/php#{php_version_path}-fpm
EOS
if MacOS.version >= :mountain_lion
s << <<-EOS.undent
Mountain Lion comes with php-fpm pre-installed, to ensure you are using the brew version you need to make sure #{HOMEBREW_PREFIX}/sbin is before /usr/sbin in your PATH:
PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"
EOS
end
s << <<-EOS.undent
You may also need to edit the plist to use the correct "UserName".
Please note that the plist was called 'homebrew-php.josegonzalez.php#{php_version.gsub('.','')}.plist' in old versions
of this formula.
EOS
end
s.join "\n"
end
def test
if build.include?('with-fpm')
system "#{sbin}/php-fpm -y #{config_path}/php-fpm.conf -t"
end
end
def plist; <<-EOPLIST.undent
<?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>
<true/>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_sbin}/php-fpm</string>
<string>--fpm-config</string>
<string>#{config_path}/php-fpm.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>LaunchOnlyOnce</key>
<true/>
<key>UserName</key>
<string>#{`whoami`.chomp}</string>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{opt_prefix}/var/log/php-fpm.log</string>
</dict>
</plist>
EOPLIST
end
end
class Php55Redis < AbstractPhp55Extension
init
homepage 'https://github.com/phpredis/phpredis'
url 'https://github.com/phpredis/phpredis/archive/2.2.6.tar.gz'
sha1 'df3d6c9c4d48bf5c1dbcfc64947f7cec828b5014'
head 'https://github.com/phpredis/phpredis.git'
option 'with-igbinary', "Build with igbinary support"
depends_on 'php55-igbinary' if build.with? "igbinary"
def install
ENV.universal_binary if build.universal?
args = []
args << "--enable-redis-igbinary" if build.with? 'igbinary'
safe_phpize
if build.with? 'igbinary'
system "mkdir -p ext/igbinary"
cp "#{Formula['php55-igbinary'].opt_prefix}/include/igbinary.h", "ext/igbinary/igbinary.h"
end
system "./configure", "--prefix=#{prefix}",
phpconfig,
*args
system "make"
prefix.install "modules/redis.so"
write_config_file if build.with? "config-file"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment