184 lines
6.7 KiB
Ruby
184 lines
6.7 KiB
Ruby
class Httpd < Formula
|
|
desc "Apache HTTP server"
|
|
homepage "https://httpd.apache.org/"
|
|
url "https://dlcdn.apache.org/httpd/httpd-2.4.54.tar.bz2"
|
|
mirror "https://downloads.apache.org/httpd/httpd-2.4.54.tar.bz2"
|
|
sha256 "eb397feeefccaf254f8d45de3768d9d68e8e73851c49afd5b7176d1ecf80c340"
|
|
license "Apache-2.0"
|
|
revision 1
|
|
|
|
bottle do
|
|
rebuild 1
|
|
sha256 arm64_ventura: "5b05f3b3d84cb151fee1473739562a90a83f15f625e4dbcf5e2273f7230f3204"
|
|
sha256 arm64_monterey: "9d85f7b82b56bd61ed5b221f5dba12c8640cbc550a29cf153f43a7e86369d9ef"
|
|
sha256 arm64_big_sur: "c63d874e61e0bb223aa6b6ac858d64be4b07477f55fd9901f25cd879dd4b2e71"
|
|
sha256 ventura: "b18e8c2f61762c33a44f97bf76188b950b344ead47ba4486b14c7d15745b5409"
|
|
sha256 monterey: "6c02a8f4cdb49d7533b2c30e6b7929464869c143fc38fb8adec954897341c22e"
|
|
sha256 big_sur: "4c35b11646b61c4a0d840af5dad931a7fce9cd96f1ccb64a2310f8b49ada7570"
|
|
sha256 catalina: "75a45c116889fed37f2c7e5e840e766353dcc26b8da4f5c5b887d869123da33d"
|
|
sha256 x86_64_linux: "99f72a4f2bb270bf86752715c6232f4b921b8d68331075d5fb264ed9c2e263a1"
|
|
end
|
|
|
|
depends_on "apr"
|
|
depends_on "apr-util"
|
|
depends_on "brotli"
|
|
depends_on "libnghttp2"
|
|
depends_on "openssl@1.1"
|
|
depends_on "pcre2"
|
|
|
|
uses_from_macos "libxml2"
|
|
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
|
|
|
|
libxml2 = "#{MacOS.sdk_path_if_needed}/usr"
|
|
libxml2 = Formula["libxml2"].opt_prefix if OS.linux?
|
|
zlib = if OS.mac?
|
|
"#{MacOS.sdk_path_if_needed}/usr"
|
|
else
|
|
Formula["zlib"].opt_prefix
|
|
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=#{libxml2}",
|
|
"--with-mpm=prefork",
|
|
"--with-nghttp2=#{Formula["libnghttp2"].opt_prefix}",
|
|
"--with-ssl=#{Formula["openssl@1.1"].opt_prefix}",
|
|
"--with-pcre=#{Formula["pcre2"].opt_prefix}/bin/pcre2-config",
|
|
"--with-z=#{zlib}",
|
|
"--disable-lua",
|
|
"--disable-luajit"
|
|
system "make"
|
|
ENV.deparallelize if OS.linux?
|
|
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["pcre2"]
|
|
s.gsub! pcre.prefix.realpath, pcre.opt_prefix
|
|
s.gsub! "${prefix}/lib/httpd/modules", HOMEBREW_PREFIX/"lib/httpd/modules"
|
|
s.gsub! Superenv.shims_path, HOMEBREW_PREFIX/"bin"
|
|
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
|
|
|
|
service do
|
|
run [opt_bin/"httpd", "-D", "FOREGROUND"]
|
|
environment_variables PATH: std_service_path_env
|
|
run_type :immediate
|
|
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}")
|
|
|
|
# Check that `apxs` can find `apu-1-config`.
|
|
system bin/"apxs", "-q", "APU_CONFIG"
|
|
ensure
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|