2018-03-29 10:45:46 +00:00
|
|
|
class PhpAT56 < Formula
|
|
|
|
desc "General-purpose scripting language"
|
|
|
|
homepage "https://secure.php.net/"
|
2018-04-26 20:49:25 +00:00
|
|
|
url "https://php.net/get/php-5.6.36.tar.xz/from/this/mirror"
|
|
|
|
sha256 "18f536bf548e909b4e980379d0c4e56d024b2b1eb1c9768fd169360491f1d6dd"
|
2018-03-29 10:45:46 +00:00
|
|
|
|
2018-03-31 19:26:03 +00:00
|
|
|
bottle do
|
2018-04-26 21:07:53 +00:00
|
|
|
sha256 "155b0e18a062c0e752358e6c50f515ca3d1ae34ef3dc75841574de87963f87bc" => :high_sierra
|
|
|
|
sha256 "10c12ba37b930d4d628899248c34185fd496c0d13893f1c7250e4884e967b2e7" => :sierra
|
|
|
|
sha256 "6f708e907c631691f98f4e564bc7aa8cccec0aa287a9790473d9d8c55a01440c" => :el_capitan
|
2018-03-31 19:26:03 +00:00
|
|
|
end
|
|
|
|
|
2018-03-29 10:45:46 +00:00
|
|
|
keg_only :versioned_formula
|
|
|
|
|
|
|
|
depends_on "httpd" => [:build, :test]
|
|
|
|
depends_on "pkg-config" => :build
|
|
|
|
depends_on "apr"
|
|
|
|
depends_on "apr-util"
|
|
|
|
depends_on "aspell"
|
2018-04-07 15:21:14 +00:00
|
|
|
depends_on "autoconf"
|
2018-03-29 10:45:46 +00:00
|
|
|
depends_on "curl" if MacOS.version < :lion
|
|
|
|
depends_on "freetds"
|
|
|
|
depends_on "freetype"
|
|
|
|
depends_on "gettext"
|
|
|
|
depends_on "glib"
|
|
|
|
depends_on "gmp"
|
|
|
|
depends_on "icu4c"
|
|
|
|
depends_on "jpeg"
|
|
|
|
depends_on "libpng"
|
|
|
|
depends_on "libpq"
|
|
|
|
depends_on "libzip"
|
|
|
|
depends_on "mcrypt"
|
|
|
|
depends_on "openssl"
|
|
|
|
depends_on "pcre"
|
|
|
|
depends_on "unixodbc"
|
|
|
|
depends_on "webp"
|
|
|
|
|
|
|
|
needs :cxx11
|
|
|
|
|
|
|
|
def install
|
|
|
|
# Ensure that libxml2 will be detected correctly in older MacOS
|
|
|
|
if MacOS.version == :el_capitan || MacOS.version == :sierra
|
|
|
|
ENV["SDKROOT"] = MacOS.sdk_path
|
|
|
|
end
|
|
|
|
|
|
|
|
inreplace "configure" do |s|
|
|
|
|
s.gsub! "APACHE_THREADED_MPM=`$APXS_HTTPD -V | grep 'threaded:.*yes'`",
|
|
|
|
"APACHE_THREADED_MPM="
|
|
|
|
s.gsub! "APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`",
|
|
|
|
"APXS_LIBEXECDIR='$(INSTALL_ROOT)#{lib}/httpd/modules'"
|
|
|
|
s.gsub! "-z `$APXS -q SYSCONFDIR`",
|
|
|
|
"-z ''"
|
|
|
|
# apxs will interpolate the @ in the versioned prefix: https://bz.apache.org/bugzilla/show_bug.cgi?id=61944
|
|
|
|
s.gsub! "LIBEXECDIR='$APXS_LIBEXECDIR'",
|
|
|
|
"LIBEXECDIR='" + "#{lib}/httpd/modules".gsub("@", "\\@") + "'"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update error message in apache sapi to better explain the requirements
|
|
|
|
# of using Apache http in combination with php if the non-compatible MPM
|
|
|
|
# has been selected. Homebrew has chosen not to support being able to
|
|
|
|
# compile a thread safe version of PHP and therefore it is not
|
|
|
|
# possible to recompile as suggested in the original message
|
|
|
|
inreplace "sapi/apache2handler/sapi_apache2.c",
|
|
|
|
"You need to recompile PHP.",
|
|
|
|
"Homebrew PHP does not support a thread-safe php binary. "\
|
|
|
|
"To use the PHP apache sapi please change "\
|
|
|
|
"your httpd config to use the prefork MPM"
|
|
|
|
|
|
|
|
inreplace "sapi/fpm/php-fpm.conf.in", ";daemonize = yes", "daemonize = no"
|
|
|
|
|
|
|
|
# Required due to icu4c dependency
|
|
|
|
ENV.cxx11
|
|
|
|
|
|
|
|
# icu4c 61.1 compatability
|
|
|
|
ENV.append "CPPFLAGS", "-DU_USING_ICU_NAMESPACE=1"
|
|
|
|
|
|
|
|
config_path = etc/"php/#{php_version}"
|
2018-04-04 03:58:49 +00:00
|
|
|
# Prevent system pear config from inhibiting pear install
|
2018-03-29 10:45:46 +00:00
|
|
|
(config_path/"pear.conf").delete if (config_path/"pear.conf").exist?
|
|
|
|
|
|
|
|
# Prevent homebrew from harcoding path to sed shim in phpize script
|
|
|
|
ENV["lt_cv_path_SED"] = "sed"
|
|
|
|
|
|
|
|
args = %W[
|
|
|
|
--prefix=#{prefix}
|
|
|
|
--localstatedir=#{var}
|
|
|
|
--sysconfdir=#{config_path}
|
|
|
|
--with-config-file-path=#{config_path}
|
|
|
|
--with-config-file-scan-dir=#{config_path}/conf.d
|
2018-04-04 03:58:49 +00:00
|
|
|
--with-pear=#{pkgshare}/pear
|
2018-03-29 10:45:46 +00:00
|
|
|
--enable-bcmath
|
|
|
|
--enable-calendar
|
|
|
|
--enable-dba
|
|
|
|
--enable-exif
|
|
|
|
--enable-ftp
|
|
|
|
--enable-fpm
|
|
|
|
--enable-intl
|
|
|
|
--enable-mbregex
|
|
|
|
--enable-mbstring
|
|
|
|
--enable-mysqlnd
|
|
|
|
--enable-opcache-file
|
|
|
|
--enable-pcntl
|
|
|
|
--enable-phpdbg
|
|
|
|
--enable-phpdbg-webhelper
|
|
|
|
--enable-shmop
|
|
|
|
--enable-soap
|
|
|
|
--enable-sockets
|
|
|
|
--enable-sysvmsg
|
|
|
|
--enable-sysvsem
|
|
|
|
--enable-sysvshm
|
|
|
|
--enable-wddx
|
|
|
|
--enable-zip
|
|
|
|
--with-apxs2=#{Formula["httpd"].opt_bin}/apxs
|
|
|
|
--with-bz2
|
|
|
|
--with-fpm-user=_www
|
|
|
|
--with-fpm-group=_www
|
|
|
|
--with-freetype-dir=#{Formula["freetype"].opt_prefix}
|
|
|
|
--with-gd
|
|
|
|
--with-gettext=#{Formula["gettext"].opt_prefix}
|
|
|
|
--with-gmp=#{Formula["gmp"].opt_prefix}
|
|
|
|
--with-icu-dir=#{Formula["icu4c"].opt_prefix}
|
|
|
|
--with-jpeg-dir=#{Formula["jpeg"].opt_prefix}
|
|
|
|
--with-kerberos
|
|
|
|
--with-layout=GNU
|
|
|
|
--with-ldap
|
|
|
|
--with-ldap-sasl
|
|
|
|
--with-libedit
|
|
|
|
--with-libzip
|
|
|
|
--with-mhash
|
|
|
|
--with-mysql-sock=/tmp/mysql.sock
|
|
|
|
--with-mysqli=mysqlnd
|
|
|
|
--with-mysql=mysqlnd
|
|
|
|
--with-mcrypt=#{Formula["mcrypt"].opt_prefix}
|
|
|
|
--with-ndbm
|
|
|
|
--with-openssl=#{Formula["openssl"].opt_prefix}
|
|
|
|
--with-pdo-dblib=#{Formula["freetds"].opt_prefix}
|
|
|
|
--with-pdo-mysql=mysqlnd
|
|
|
|
--with-pdo-odbc=unixODBC,#{Formula["unixodbc"].opt_prefix}
|
|
|
|
--with-pdo-pgsql=#{Formula["libpq"].opt_prefix}
|
|
|
|
--with-pgsql=#{Formula["libpq"].opt_prefix}
|
|
|
|
--with-pic
|
|
|
|
--with-png-dir=#{Formula["libpng"].opt_prefix}
|
|
|
|
--with-pspell=#{Formula["aspell"].opt_prefix}
|
|
|
|
--with-unixODBC=#{Formula["unixodbc"].opt_prefix}
|
|
|
|
--with-webp-dir=#{Formula["webp"].opt_prefix}
|
|
|
|
--with-xmlrpc
|
|
|
|
--with-xsl
|
|
|
|
--with-zlib
|
|
|
|
]
|
|
|
|
|
|
|
|
if MacOS.version < :lion
|
|
|
|
args << "--with-curl=#{Formula["curl"].opt_prefix}"
|
|
|
|
else
|
|
|
|
args << "--with-curl"
|
|
|
|
end
|
|
|
|
|
|
|
|
system "./configure", *args
|
|
|
|
system "make"
|
|
|
|
system "make", "install"
|
|
|
|
|
|
|
|
# Allow pecl to install outside of Cellar
|
|
|
|
extension_dir = Utils.popen_read("#{bin}/php-config --extension-dir").chomp
|
|
|
|
orig_ext_dir = File.basename(extension_dir)
|
|
|
|
inreplace bin/"php-config", lib/"php", prefix/"pecl"
|
|
|
|
inreplace "php.ini-development", "; extension_dir = \"./\"",
|
|
|
|
"extension_dir = \"#{HOMEBREW_PREFIX}/lib/php/pecl/#{orig_ext_dir}\""
|
|
|
|
|
|
|
|
config_files = {
|
|
|
|
"php.ini-development" => "php.ini",
|
|
|
|
"sapi/fpm/php-fpm.conf" => "php-fpm.conf",
|
|
|
|
}
|
|
|
|
config_files.each_value do |dst|
|
|
|
|
dst_default = config_path/"#{dst}.default"
|
|
|
|
rm dst_default if dst_default.exist?
|
|
|
|
end
|
|
|
|
config_path.install config_files
|
|
|
|
|
|
|
|
unless (var/"log/php-fpm.log").exist?
|
|
|
|
(var/"log").mkpath
|
|
|
|
touch var/"log/php-fpm.log"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_install
|
2018-04-04 03:58:49 +00:00
|
|
|
pear_prefix = pkgshare/"pear"
|
2018-03-29 10:45:46 +00:00
|
|
|
pear_files = %W[
|
|
|
|
#{pear_prefix}/.depdblock
|
|
|
|
#{pear_prefix}/.filemap
|
|
|
|
#{pear_prefix}/.depdb
|
|
|
|
#{pear_prefix}/.lock
|
|
|
|
]
|
|
|
|
|
|
|
|
%W[
|
|
|
|
#{pear_prefix}/.channels
|
|
|
|
#{pear_prefix}/.channels/.alias
|
|
|
|
].each do |f|
|
|
|
|
chmod 0755, f
|
|
|
|
pear_files.concat(Dir["#{f}/*"])
|
|
|
|
end
|
|
|
|
|
|
|
|
chmod 0644, pear_files
|
|
|
|
|
|
|
|
# Custom location for extensions installed via pecl
|
|
|
|
pecl_path = HOMEBREW_PREFIX/"lib/php/pecl"
|
|
|
|
ln_s pecl_path, prefix/"pecl" unless (prefix/"pecl").exist?
|
|
|
|
extension_dir = Utils.popen_read("#{bin}/php-config --extension-dir").chomp
|
|
|
|
php_basename = File.basename(extension_dir)
|
|
|
|
php_ext_dir = opt_prefix/"lib/php"/php_basename
|
|
|
|
|
|
|
|
# fix pear config to install outside cellar
|
2018-04-04 03:58:49 +00:00
|
|
|
pear_path = HOMEBREW_PREFIX/"share/pear@#{php_version}"
|
|
|
|
cp_r pkgshare/"pear/.", pear_path
|
2018-03-29 10:45:46 +00:00
|
|
|
{
|
|
|
|
"php_ini" => etc/"php/#{php_version}/php.ini",
|
|
|
|
"php_dir" => pear_path,
|
|
|
|
"doc_dir" => pear_path/"doc",
|
|
|
|
"ext_dir" => pecl_path/php_basename,
|
|
|
|
"bin_dir" => opt_bin,
|
|
|
|
"data_dir" => pear_path/"data",
|
|
|
|
"cfg_dir" => pear_path/"cfg",
|
|
|
|
"www_dir" => pear_path/"htdocs",
|
|
|
|
"man_dir" => HOMEBREW_PREFIX/"share/man",
|
|
|
|
"test_dir" => pear_path/"test",
|
|
|
|
"php_bin" => opt_bin/"php",
|
|
|
|
}.each do |key, value|
|
|
|
|
value.mkpath if key =~ /(?<!bin|man)_dir$/
|
|
|
|
system bin/"pear", "config-set", key, value, "system"
|
|
|
|
end
|
|
|
|
|
2018-04-04 03:58:49 +00:00
|
|
|
system bin/"pear", "update-channels"
|
|
|
|
|
2018-03-29 10:45:46 +00:00
|
|
|
%w[
|
|
|
|
opcache
|
|
|
|
].each do |e|
|
|
|
|
ext_config_path = etc/"php/#{php_version}/conf.d/ext-#{e}.ini"
|
|
|
|
extension_type = (e == "opcache") ? "zend_extension" : "extension"
|
|
|
|
if ext_config_path.exist?
|
|
|
|
inreplace ext_config_path,
|
|
|
|
/#{extension_type}=.*$/, "#{extension_type}=#{php_ext_dir}/#{e}.so"
|
|
|
|
else
|
|
|
|
ext_config_path.write <<~EOS
|
|
|
|
[#{e}]
|
|
|
|
#{extension_type}="#{php_ext_dir}/#{e}.so"
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-27 00:33:17 +00:00
|
|
|
def caveats
|
|
|
|
<<~EOS
|
|
|
|
To enable PHP in Apache add the following to httpd.conf and restart Apache:
|
|
|
|
LoadModule php5_module #{opt_lib}/httpd/modules/libphp5.so
|
|
|
|
|
|
|
|
<FilesMatch \\.php$>
|
|
|
|
SetHandler application/x-httpd-php
|
|
|
|
</FilesMatch>
|
|
|
|
|
|
|
|
Finally, check DirectoryIndex includes index.php
|
|
|
|
DirectoryIndex index.php index.html
|
|
|
|
|
|
|
|
The php.ini and php-fpm.ini file can be found in:
|
|
|
|
#{etc}/php/#{php_version}/
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
2018-03-29 10:45:46 +00:00
|
|
|
def php_version
|
|
|
|
version.to_s.split(".")[0..1].join(".")
|
|
|
|
end
|
|
|
|
|
|
|
|
plist_options :manual => "php-fpm"
|
|
|
|
|
|
|
|
def plist; <<~EOS
|
|
|
|
<?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>--nodaemonize</string>
|
|
|
|
</array>
|
|
|
|
<key>RunAtLoad</key>
|
|
|
|
<true/>
|
|
|
|
<key>WorkingDirectory</key>
|
|
|
|
<string>#{var}</string>
|
|
|
|
<key>StandardErrorPath</key>
|
|
|
|
<string>#{var}/log/php-fpm.log</string>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
test do
|
|
|
|
assert_match /^Zend OPcache$/, shell_output("#{bin}/php -i"), "Zend OPCache extension not loaded"
|
|
|
|
system "#{sbin}/php-fpm", "-t"
|
|
|
|
system "#{bin}/phpdbg", "-V"
|
|
|
|
system "#{bin}/php-cgi", "-m"
|
|
|
|
# Prevent SNMP extension to be added
|
|
|
|
assert_no_match /^snmp$/, shell_output("#{bin}/php -m"), "SNMP extension doesn't work reliably with Homebrew on High Sierra"
|
|
|
|
begin
|
|
|
|
require "socket"
|
|
|
|
|
|
|
|
server = TCPServer.new(0)
|
|
|
|
port = server.addr[1]
|
|
|
|
server_fpm = TCPServer.new(0)
|
|
|
|
port_fpm = server_fpm.addr[1]
|
|
|
|
server.close
|
|
|
|
server_fpm.close
|
|
|
|
|
|
|
|
expected_output = /^Hello world!$/
|
|
|
|
(testpath/"index.php").write <<~EOS
|
|
|
|
<?php
|
|
|
|
echo 'Hello world!';
|
|
|
|
EOS
|
|
|
|
main_config = <<~EOS
|
|
|
|
Listen #{port}
|
|
|
|
ServerName localhost:#{port}
|
|
|
|
DocumentRoot "#{testpath}"
|
|
|
|
ErrorLog "#{testpath}/httpd-error.log"
|
|
|
|
ServerRoot "#{Formula["httpd"].opt_prefix}"
|
|
|
|
PidFile "#{testpath}/httpd.pid"
|
|
|
|
LoadModule authz_core_module lib/httpd/modules/mod_authz_core.so
|
|
|
|
LoadModule unixd_module lib/httpd/modules/mod_unixd.so
|
|
|
|
LoadModule dir_module lib/httpd/modules/mod_dir.so
|
|
|
|
DirectoryIndex index.php
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(testpath/"httpd.conf").write <<~EOS
|
|
|
|
#{main_config}
|
|
|
|
LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so
|
|
|
|
LoadModule php5_module #{lib}/httpd/modules/libphp5.so
|
2018-04-18 12:54:28 +00:00
|
|
|
<FilesMatch \\.(php|phar)$>
|
2018-03-29 10:45:46 +00:00
|
|
|
SetHandler application/x-httpd-php
|
|
|
|
</FilesMatch>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(testpath/"fpm.conf").write <<~EOS
|
|
|
|
[global]
|
|
|
|
daemonize=no
|
|
|
|
[www]
|
|
|
|
listen = 127.0.0.1:#{port_fpm}
|
|
|
|
pm = dynamic
|
|
|
|
pm.max_children = 5
|
|
|
|
pm.start_servers = 2
|
|
|
|
pm.min_spare_servers = 1
|
|
|
|
pm.max_spare_servers = 3
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(testpath/"httpd-fpm.conf").write <<~EOS
|
|
|
|
#{main_config}
|
|
|
|
LoadModule mpm_event_module lib/httpd/modules/mod_mpm_event.so
|
|
|
|
LoadModule proxy_module lib/httpd/modules/mod_proxy.so
|
|
|
|
LoadModule proxy_fcgi_module lib/httpd/modules/mod_proxy_fcgi.so
|
2018-04-18 12:54:28 +00:00
|
|
|
<FilesMatch \\.(php|phar)$>
|
2018-03-29 10:45:46 +00:00
|
|
|
SetHandler "proxy:fcgi://127.0.0.1:#{port_fpm}"
|
|
|
|
</FilesMatch>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
pid = fork do
|
|
|
|
exec Formula["httpd"].opt_bin/"httpd", "-X", "-f", "#{testpath}/httpd.conf"
|
|
|
|
end
|
|
|
|
sleep 3
|
|
|
|
|
|
|
|
assert_match expected_output, shell_output("curl -s 127.0.0.1:#{port}")
|
|
|
|
|
|
|
|
Process.kill("TERM", pid)
|
|
|
|
Process.wait(pid)
|
|
|
|
|
|
|
|
fpm_pid = fork do
|
|
|
|
exec sbin/"php-fpm", "-y", "fpm.conf"
|
|
|
|
end
|
|
|
|
pid = fork do
|
|
|
|
exec Formula["httpd"].opt_bin/"httpd", "-X", "-f", "#{testpath}/httpd-fpm.conf"
|
|
|
|
end
|
|
|
|
sleep 3
|
|
|
|
|
|
|
|
assert_match expected_output, shell_output("curl -s 127.0.0.1:#{port}")
|
|
|
|
ensure
|
|
|
|
if pid
|
|
|
|
Process.kill("TERM", pid)
|
|
|
|
Process.wait(pid)
|
|
|
|
end
|
|
|
|
if fpm_pid
|
|
|
|
Process.kill("TERM", fpm_pid)
|
|
|
|
Process.wait(fpm_pid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|