189 lines
6.6 KiB
Ruby
189 lines
6.6 KiB
Ruby
class Httpd < Formula
|
|
desc "Apache HTTP server"
|
|
homepage "https://httpd.apache.org/"
|
|
url "https://www.apache.org/dyn/closer.lua?path=httpd/httpd-2.4.46.tar.bz2"
|
|
mirror "https://archive.apache.org/dist/httpd/httpd-2.4.46.tar.bz2"
|
|
sha256 "740eddf6e1c641992b22359cabc66e6325868c3c5e2e3f98faf349b61ecf41ea"
|
|
license "Apache-2.0"
|
|
revision 2
|
|
|
|
bottle do
|
|
sha256 arm64_big_sur: "35357c35f6be07c0f3e60d64c88eae200158dca6e390a341569a9f0296ed33fb"
|
|
sha256 big_sur: "5a979ae3affd408b4ab51f917ef34e662a9cb85eb3918e56e05e1bcfac1aedac"
|
|
sha256 catalina: "c540cd4ba596ff6f0df9d772c41487c26201f548a3756ee7a02108c70fee147e"
|
|
sha256 mojave: "b88153894953fa0c976f0f74bec8abf2646b320424cc92a5cbdebb6a493ab729"
|
|
end
|
|
|
|
depends_on "apr"
|
|
depends_on "apr-util"
|
|
depends_on "brotli"
|
|
depends_on "nghttp2"
|
|
depends_on "openssl@1.1"
|
|
depends_on "pcre"
|
|
|
|
uses_from_macos "zlib"
|
|
|
|
def install
|
|
# fixup prefix references in favour of opt_prefix references
|
|
inreplace "Makefile.in",
|
|
'#@@ServerRoot@@#$(prefix)#', '#@@ServerRoot@@'"##{opt_prefix}#"
|
|
inreplace "docs/conf/extra/httpd-autoindex.conf.in",
|
|
"@exp_iconsdir@", "#{opt_pkgshare}/icons"
|
|
inreplace "docs/conf/extra/httpd-multilang-errordoc.conf.in",
|
|
"@exp_errordir@", "#{opt_pkgshare}/error"
|
|
|
|
# fix default user/group when running as root
|
|
inreplace "docs/conf/httpd.conf.in", /(User|Group) daemon/, "\\1 _www"
|
|
|
|
# use Slackware-FHS layout as it's closest to what we want.
|
|
# these values cannot be passed directly to configure, unfortunately.
|
|
inreplace "config.layout" do |s|
|
|
s.gsub! "${datadir}/htdocs", "${datadir}"
|
|
s.gsub! "${htdocsdir}/manual", "#{pkgshare}/manual"
|
|
s.gsub! "${datadir}/error", "#{pkgshare}/error"
|
|
s.gsub! "${datadir}/icons", "#{pkgshare}/icons"
|
|
end
|
|
|
|
system "./configure", "--enable-layout=Slackware-FHS",
|
|
"--prefix=#{prefix}",
|
|
"--sbindir=#{bin}",
|
|
"--mandir=#{man}",
|
|
"--sysconfdir=#{etc}/httpd",
|
|
"--datadir=#{var}/www",
|
|
"--localstatedir=#{var}",
|
|
"--enable-mpms-shared=all",
|
|
"--enable-mods-shared=all",
|
|
"--enable-authnz-fcgi",
|
|
"--enable-cgi",
|
|
"--enable-pie",
|
|
"--enable-suexec",
|
|
"--with-suexec-bin=#{opt_bin}/suexec",
|
|
"--with-suexec-caller=_www",
|
|
"--with-port=8080",
|
|
"--with-sslport=8443",
|
|
"--with-apr=#{Formula["apr"].opt_prefix}",
|
|
"--with-apr-util=#{Formula["apr-util"].opt_prefix}",
|
|
"--with-brotli=#{Formula["brotli"].opt_prefix}",
|
|
"--with-libxml2=#{MacOS.sdk_path_if_needed}/usr",
|
|
"--with-mpm=prefork",
|
|
"--with-nghttp2=#{Formula["nghttp2"].opt_prefix}",
|
|
"--with-ssl=#{Formula["openssl@1.1"].opt_prefix}",
|
|
"--with-pcre=#{Formula["pcre"].opt_prefix}",
|
|
"--with-z=#{MacOS.sdk_path_if_needed}/usr",
|
|
"--disable-lua",
|
|
"--disable-luajit"
|
|
system "make"
|
|
system "make", "install"
|
|
|
|
# suexec does not install without root
|
|
bin.install "support/suexec"
|
|
|
|
# remove non-executable files in bin dir (for brew audit)
|
|
rm bin/"envvars"
|
|
rm bin/"envvars-std"
|
|
|
|
# avoid using Cellar paths
|
|
inreplace %W[
|
|
#{include}/httpd/ap_config_layout.h
|
|
#{lib}/httpd/build/config_vars.mk
|
|
] do |s|
|
|
s.gsub! "#{lib}/httpd/modules", "#{HOMEBREW_PREFIX}/lib/httpd/modules"
|
|
end
|
|
|
|
inreplace %W[
|
|
#{bin}/apachectl
|
|
#{bin}/apxs
|
|
#{include}/httpd/ap_config_auto.h
|
|
#{include}/httpd/ap_config_layout.h
|
|
#{lib}/httpd/build/config_vars.mk
|
|
#{lib}/httpd/build/config.nice
|
|
] do |s|
|
|
s.gsub! prefix, opt_prefix
|
|
end
|
|
|
|
inreplace "#{lib}/httpd/build/config_vars.mk" do |s|
|
|
pcre = Formula["pcre"]
|
|
s.gsub! pcre.prefix.realpath, pcre.opt_prefix
|
|
s.gsub! "${prefix}/lib/httpd/modules",
|
|
"#{HOMEBREW_PREFIX}/lib/httpd/modules"
|
|
end
|
|
end
|
|
|
|
def post_install
|
|
(var/"cache/httpd").mkpath
|
|
(var/"www").mkpath
|
|
end
|
|
|
|
def caveats
|
|
<<~EOS
|
|
DocumentRoot is #{var}/www.
|
|
|
|
The default ports have been set in #{etc}/httpd/httpd.conf to 8080 and in
|
|
#{etc}/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
|
|
EOS
|
|
end
|
|
|
|
plist_options manual: "apachectl start"
|
|
|
|
def plist
|
|
<<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_bin}/httpd</string>
|
|
<string>-D</string>
|
|
<string>FOREGROUND</string>
|
|
</array>
|
|
<key>EnvironmentVariables</key>
|
|
<dict>
|
|
<key>PATH</key>
|
|
<string>#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
|
</dict>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
# Ensure modules depending on zlib and xml2 have been compiled
|
|
assert_predicate lib/"httpd/modules/mod_deflate.so", :exist?
|
|
assert_predicate lib/"httpd/modules/mod_proxy_html.so", :exist?
|
|
assert_predicate lib/"httpd/modules/mod_xml2enc.so", :exist?
|
|
|
|
begin
|
|
port = free_port
|
|
|
|
expected_output = "Hello world!"
|
|
(testpath/"index.html").write expected_output
|
|
(testpath/"httpd.conf").write <<~EOS
|
|
Listen #{port}
|
|
ServerName localhost:#{port}
|
|
DocumentRoot "#{testpath}"
|
|
ErrorLog "#{testpath}/httpd-error.log"
|
|
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
|
|
LoadModule mpm_prefork_module #{lib}/httpd/modules/mod_mpm_prefork.so
|
|
EOS
|
|
|
|
pid = fork do
|
|
exec bin/"httpd", "-X", "-f", "#{testpath}/httpd.conf"
|
|
end
|
|
sleep 3
|
|
|
|
assert_match expected_output, shell_output("curl -s 127.0.0.1:#{port}")
|
|
ensure
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|