macbook Apache安装(为了做Perl CGI服务)

  1. brew安装httpd
 [192:Downloads sixiaodong$ brew install httpd
Error: homebrew-core is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core. We don't do this for you automatically to avoid
repeatedly performing an expensive unshallow operation in CI systems (which
should instead be fixed to not use shallow clones). Sorry for the inconvenience!
==> Downloading https://homebrew.bintray.com/bottles/apr-1.7.0.catalina.bottle.t
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/277c42fcf2f5ca298a142
####################                                                      27.9%
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: Failed to download resource "apr"
:
:
==> Installing dependencies for httpd: apr, apr-util, brotli, c-ares, jansson, jemalloc, libev, libevent, nghttp2 and pcre
==> Installing httpd dependency: apr
==> Pouring apr-1.7.0.catalina.bottle.tar.gz
tar: Error opening archive: Failed to open '/Users/sixiaodong/Library/Caches/Homebrew/downloads/12c59f6d0c9e4d92797535ec10508dbac5daf0302e1e1b2cf2ba30ef04fb5bed--apr-1.7.0.catalina.bottle.tar.gz'
Error: Failure while executing; `tar xof /Users/sixiaodong/Library/Caches/Homebrew/downloads/12c59f6d0c9e4d92797535ec10508dbac5daf0302e1e1b2cf2ba30ef04fb5bed--apr-1.7.0.catalina.bottle.tar.gz -C /var/folders/t4/n208jw9x18317lhh71g47pl00000gn/T/d20201212-39525-8cfnjm` exited with 1. Here's the output:
tar: Error opening archive: Failed to open '/Users/sixiaodong/Library/Caches/Homebrew/downloads/12c59f6d0c9e4d92797535ec10508dbac5daf0302e1e1b2cf2ba30ef04fb5bed--apr-1.7.0.catalina.bottle.tar.gz'

Warning: Bottle installation failed: building from source.
Error: Your CLT does not support macOS 11.
It is either outdated or was modified.
Please update your CLT or delete it if no updates are available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you an update run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/more/.

Error: An exception occurred within a child process:
  SystemExit: exit
  1. 安装失败

按着上边的错误信息提示执行下记命令

[192:Downloads sixiaodong$ sudo rm -rf /Library/Developer/CommandLineTools
[Password:
[192:Downloads sixiaodong$ sudo xcode-select --install
xcode-select: note: install requested for command line developer tools
[192:Downloads sixiaodong$ 

弹出画面
点击安装
等待

  1. 再次brew安装httpd
192:Downloads sixiaodong$  brew install httpd
Error: homebrew-core is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core. We don't do this for you automatically to avoid
repeatedly performing an expensive unshallow operation in CI systems (which
should instead be fixed to not use shallow clones). Sorry for the inconvenience!
==> Downloading https://homebrew.bintray.com/bottles/apr-1.7.0.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/277c42fcf2f5ca298a14279d1325f58da89ee4ec2132b3ccca9bf8dfd
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/apr-util-1.6.1_3.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/65801d38b40f5e689c5ff72870fdb73f04cf14eeaa9499393e2339ffa6baae75--apr-util-1.6.1_3.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/brotli-1.0.9.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/35dcf47191046196cb4e3514d450f6d9e2d81dbf6aff86f6de137ea56dc9ee0f--brotli-1.0.9.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/c-ares-1.16.1.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/c6c385f24e32d32bf8dcb960e207052d98083f7bd43a2c418b73d4e4e99f1974--c-ares-1.16.1.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/jansson-2.13.1.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/89db34850add4fec0052737854d56f6602610544de3ec6cc46eaeaf96e471d0f--jansson-2.13.1.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/jemalloc-5.2.1_1.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/dc9654699a1655295a1319ee956e64a6318387e860c95b5c7ed43b71af05a47d--jemalloc-5.2.1_1.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/libev-4.33.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/25986a407604060b345a80ce81f51c69f9632ef16de0474e2efcfc69aaf83f2e--libev-4.33.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/libevent-2.1.12.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/c8f3769ad847d95db9fae33b1a021fa1cf05ec204fd2cf583fc73aa0772e3a19--libevent-2.1.12.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/nghttp2-1.41.0.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/282ed9c5fb8974ec43492d4a6f3d0eec6d9cb66a8f2200c20da19700bae4fcd9--nghttp2-1.41.0.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.44.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/6176d92bec825f2d0092ff0a534e9f74a0175cc0694c4f43959512ea9515c97f--pcre-8.44.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/httpd-2.4.46.catalina.bottle.tar.gz
Already downloaded: /Users/sixiaodong/Library/Caches/Homebrew/downloads/12f2b34766a6294d2f77314f62892a2a604ffe76fc056c1eb8af3217dcf03e7d--httpd-2.4.46.catalina.bottle.tar.gz
==> Installing dependencies for httpd: apr, apr-util, brotli, c-ares, jansson, jemalloc, libev, libevent, nghttp2 and pcre
==> Installing httpd dependency: apr
==> Pouring apr-1.7.0.catalina.bottle.tar.gz
==> Caveats
apr is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT provides apr.

If you need to have apr first in your PATH run:
  echo 'export PATH="/usr/local/opt/apr/bin:$PATH"' >> /Users/sixiaodong/.bash_profile

==> Summary
🍺  /usr/local/Cellar/apr/1.7.0: 59 files, 1.4MB
==> Installing httpd dependency: apr-util
==> Pouring apr-util-1.6.1_3.catalina.bottle.tar.gz
==> Caveats
apr-util is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT provides apr (but not apr-util).

If you need to have apr-util first in your PATH run:
  echo 'export PATH="/usr/local/opt/apr-util/bin:$PATH"' >> /Users/sixiaodong/.bash_profile

==> Summary
🍺  /usr/local/Cellar/apr-util/1.6.1_3: 54 files, 785.8KB
==> Installing httpd dependency: brotli
==> Pouring brotli-1.0.9.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/brotli/1.0.9: 25 files, 2.3MB
==> Installing httpd dependency: c-ares
==> Pouring c-ares-1.16.1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/c-ares/1.16.1: 74 files, 525.7KB
==> Installing httpd dependency: jansson
==> Pouring jansson-2.13.1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/jansson/2.13.1: 11 files, 169KB
==> Installing httpd dependency: jemalloc
==> Pouring jemalloc-5.2.1_1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/jemalloc/5.2.1_1: 16 files, 2MB
==> Installing httpd dependency: libev
==> Pouring libev-4.33.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/libev/4.33: 12 files, 454.7KB
==> Installing httpd dependency: libevent
==> Pouring libevent-2.1.12.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/libevent/2.1.12: 57 files, 1.9MB
==> Installing httpd dependency: nghttp2
==> Pouring nghttp2-1.41.0.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/nghttp2/1.41.0: 26 files, 2.7MB
==> Installing httpd dependency: pcre
==> Pouring pcre-8.44.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.44: 204 files, 5.5MB
==> Installing httpd
==> Pouring httpd-2.4.46.catalina.bottle.tar.gz
==> Caveats
DocumentRoot is /usr/local/var/www.

The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To have launchd start httpd now and restart at login:
  brew services start httpd
Or, if you don't want/need a background service you can just run:
  apachectl start
==> Summary
🍺  /usr/local/Cellar/httpd/2.4.46: 1,658 files, 27.9MB
==> `brew cleanup` has not been run in 30 days, running now...
:
Removing: /Users/sixiaodong/Library/Logs/Homebrew/autoconf... (5 files, 31.2KB)
Removing: /Users/sixiaodong/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/sixiaodong/Library/Logs/Homebrew/leptonica... (64B)
Removing: /Users/sixiaodong/Library/Logs/Homebrew/jpeg... (64B)
Removing: /Users/sixiaodong/Library/Logs/Homebrew/python@3.8... (3 files, 172.3KB)
Removing: /Users/sixiaodong/Library/Logs/Homebrew/automake... (5 files, 72.8KB)
==> Caveats
==> apr
apr is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT provides apr.

If you need to have apr first in your PATH run:
  echo 'export PATH="/usr/local/opt/apr/bin:$PATH"' >> /Users/sixiaodong/.bash_profile

==> apr-util
apr-util is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT provides apr (but not apr-util).

If you need to have apr-util first in your PATH run:
  echo 'export PATH="/usr/local/opt/apr-util/bin:$PATH"' >> /Users/sixiaodong/.bash_profile

==> httpd
DocumentRoot is /usr/local/var/www.

The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To have launchd start httpd now and restart at login:
  brew services start httpd
Or, if you don't want/need a background service you can just run:
  apachectl start
192:Downloads sixiaodong$ 

  1. 执行localhost:8080
    localhost:8080
  2. 配置httpd.conf

网上都说在这个(/usr/local/etc/apache2/2.4/httpd.conf )目录里,实际上我并没有找到,我是在下边的目录里找到的,这部分配置参照只能找到这一个网站Mac配置apache cgi服务,因为很久远的文章了,开始采坑配置。

[192:httpd sixiaodong$ pwd
/usr/local/etc/httpd
192:httpd sixiaodong$ ls -lt
total 200
drwxr-xr-x   4 sixiaodong  admin    128 12 12 18:28 original
-rw-r--r--   1 sixiaodong  admin  60847 12 12 18:28 mime.types
-rw-r--r--   1 sixiaodong  admin  13064 12 12 18:28 magic
-rw-r--r--   1 sixiaodong  admin  21272 12 12 18:28 httpd.conf
drwxr-xr-x  14 sixiaodong  admin    448 12 12 18:28 extra
192:httpd sixiaodong$ 

现在根据网上有限的资源尝试用vim修改配置

#LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
#20201212 START
LoadModule cgi_module libexec/mod_cgi.so
LoadModule cgid_module libexec/mod_cgid.so
#20201212 END
<IfModule unixd_module>
# symbolic links and aliases may be used to point to other locations.
#
#20201212 START
DocumentRoot "/Users/sixiaodong/Documents/Perl/Sites"
<Directory "/Users/sixiaodong/Documents/Perl/Sites">
#20201212 END
    #
    # Possible values for the Options directive are "None", "All",
#
# "/usr/local/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
#20201212 start
#<Directory "/usr/local/var/www/cgi-bin">
<Directory "/Users/sixiaodong/Documents/Perl/Sites/cgi-bin/">
    AllowOverride None
    #Options None
    Options ExecCGI
    Order allow,deny
    Allow from all 
    #Require all granted
</Directory>
#20201212 end
<IfModule headers_module>
<IfModule mime_module>
    .........省略
    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #20201212 START
    AddHandler cgi-script .cgi .py .pl .sh
    #20201212 END
    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    #20201212 START
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    #20201212 END
</IfModule>

  1. 给Sites和Sites/cgi权限
[192:Sites sixiaodong$ chmod +x /Users/sixiaodong/Documents/Perl/Sites
[192:Sites sixiaodong$ chmod +x /Users/sixiaodong/Documents/Perl/Sites/cgi/
  1. 重启Apache
[192:Sites sixiaodong$ apachectl restart
httpd: Syntax error on line 184 of /usr/local/etc/httpd/httpd.conf: Cannot load libexec/mod_cgi.so into server: dlopen(/usr/local/opt/httpd/libexec/mod_cgi.so, 10): image not found
192:Sites sixiaodong$ 

这个问题发现是配置文件里有配置,把注释解开就可以了,删掉自己在网上拷贝的配置,重启即可。

  1. 重启后正常,没有报错。
  2. 用参照文章的代码测试一下
#!/usr/bin/perl
=head1 DESCRIPTION
printenv — a CGI program that just prints its environment
=cut
print "Content-type: text/html\n\n";
for my $var ( sort keys %ENV ) {
 printf "<h2>%s = \"%s\"<h2>\n", $var, $ENV{$var};
}
~          

因为我也是才看几天Perl,并不太了解是不是这么启动,网上的文章写得也很模糊,我就按自己的理解尝试

192:Sites sixiaodong$ ./test.pl 
Content-type: text/html

<h2>HOME = "/Users/sixiaodong"<h2>
<h2>LANG = "zh_CN.UTF-8"<h2>
<h2>LOGNAME = "sixiaodong"<h2>
<h2>LaunchInstanceID = "D8FE92AC-0B6E-46E2-B922-FF79866CEB60"<h2>
<h2>OLDPWD = "/Users/sixiaodong/Documents/Perl/Sites/cgi"<h2>
<h2>PATH = "/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"<h2>
<h2>PWD = "/Users/sixiaodong/Documents/Perl/Sites"<h2>
<h2>SECURITYSESSIONID = "186a9"<h2>
<h2>SHELL = "/bin/bash"<h2>
<h2>SHLVL = "1"<h2>
<h2>SSH_AUTH_SOCK = "/private/tmp/com.apple.launchd.kY0YC9FEp5/Listeners"<h2>
<h2>TERM = "xterm-256color"<h2>
<h2>TERM_PROGRAM = "Apple_Terminal"<h2>
<h2>TERM_PROGRAM_VERSION = "440"<h2>
<h2>TERM_SESSION_ID = "CBFA5BC5-D3A9-4704-B217-FF0EEAF48CA6"<h2>
<h2>TMPDIR = "/var/folders/t4/n208jw9x18317lhh71g47pl00000gn/T/"<h2>
<h2>USER = "sixiaodong"<h2>
<h2>XPC_FLAGS = "0x0"<h2>
<h2>XPC_SERVICE_NAME = "0"<h2>
<h2>_ = "./test.pl"<h2>
<h2>__CFBundleIdentifier = "com.apple.Terminal"<h2>
<h2>__CF_USER_TEXT_ENCODING = "0x1F5:0x19:0x34"<h2>
192:Sites sixiaodong$ 

看样子没有报错,接下来打开网页

  1. 打开网页http://localhost:8080/cgi-bin/test.pl
    http://localhost:8080/cgi-bin/test.pl
    404错误。。。
    子曰。。
  2. 参照文章里子曾经曰过:404可能是DocumentRoot没有设置对,或者ScriptAlias /cgi-bin/ 没设置对,或者没有对应的文件

检查配置文件,发现ScriptAlias /cgi-bin/这里解开注释后直接把我的路径放在了/cgi-bin的前边,修改/cgi-bin→/cgi

ScriptAlias /cgi-bin/ "/Users/sixiaodong/Documents/Perl/Sites/cgi/"

保存后重启服务

192:Sites sixiaodong$ apachectl restart
192:Sites sixiaodong$ pwd
/Users/sixiaodong/Documents/Perl/Sites
192:Sites sixiaodong$ ./test.pl 
Content-type: text/html

<h2>HOME = "/Users/sixiaodong"<h2>
<h2>LANG = "zh_CN.UTF-8"<h2>
<h2>LOGNAME = "sixiaodong"<h2>
<h2>LaunchInstanceID = "D8FE92AC-0B6E-46E2-B922-FF79866CEB60"<h2>
<h2>OLDPWD = "/Users/sixiaodong/Documents/Perl/Sites/cgi"<h2>
<h2>PATH = "/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"<h2>
<h2>PWD = "/Users/sixiaodong/Documents/Perl/Sites"<h2>
<h2>SECURITYSESSIONID = "186a9"<h2>
<h2>SHELL = "/bin/bash"<h2>
<h2>SHLVL = "1"<h2>
<h2>SSH_AUTH_SOCK = "/private/tmp/com.apple.launchd.kY0YC9FEp5/Listeners"<h2>
<h2>TERM = "xterm-256color"<h2>
<h2>TERM_PROGRAM = "Apple_Terminal"<h2>
<h2>TERM_PROGRAM_VERSION = "440"<h2>
<h2>TERM_SESSION_ID = "CBFA5BC5-D3A9-4704-B217-FF0EEAF48CA6"<h2>
<h2>TMPDIR = "/var/folders/t4/n208jw9x18317lhh71g47pl00000gn/T/"<h2>
<h2>USER = "sixiaodong"<h2>
<h2>XPC_FLAGS = "0x0"<h2>
<h2>XPC_SERVICE_NAME = "0"<h2>
<h2>_ = "./test.pl"<h2>
<h2>__CFBundleIdentifier = "com.apple.Terminal"<h2>
<h2>__CF_USER_TEXT_ENCODING = "0x1F5:0x19:0x34"<h2>
192:Sites sixiaodong$ 

没有错误

再次打开http://localhost:8080/cgi-bin/test.pl

http://localhost:8080/cgi-bin/test.pl

网页能正常访问,面向CGI Perl的环境配置ok,接下来我可以开始学习这门古老的技术了

  1. 最后这部分配置主要参照这篇文章Mac配置apache cgi服务,谢谢前人留下宝贵资源,不然想学习这门古老的技术,可能就先倒在第一步之前了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值