【发布时间】:2017-04-16 08:07:06
【问题描述】:
不知道我的 Mac 附带 Apache2.4 并且没有检查我正在运行的操作系统,我按照本指南使用 Homebrew 在我的机器上获取 Apache/MySQL/PHP:https://echo.co/blog/os-x-109-local-development-environment-apache-php-and-mysql-homebrew
这导致我在我的机器上运行了两个版本的 Apache2:2.2 和 2.4。当在终端中询问运行哪个 apache 时,答案是 2.4,但是当试图在我的虚拟主机上打开我的程序实例时,我无法访问该页面。 之后发生的事情令人困惑,因为我让其他一些人在努力解决它,他们更改并移动了文件,所以当我拿回我的电脑时,我什至不知道从哪里开始了解我在哪里,所以我尝试卸载两个 apache 版本并重新安装 2.4。
由于我找不到任何帮助我卸载 apache 的指南并且 brew 命令 remove 不起作用,我去擦除 apache 文件夹并在我的目录中搜索包含“apache”或“httpd”字样的任何内容"(我能找到的任何东西,这意味着我也可能错过了一些文件,因为我只是不知道在哪里搜索它们)。
在我这样做之后,我按照其他指南 https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions 重新安装了 apache 2.4,直到 PHP 安装(我还没有执行)。
再次安装 apache 后,我在 httpd-vhost.conf 中插入了虚拟主机的数据,如下所示:
<VirtualHost *:80>
ServerAdmin personal@mail.com
DocumentRoot "/Users/username/apache_vh/myApp"
ServerName myApp.username.com
ErrorLog "/usr/local/var/log/apache2/myApp-error_log"
CustomLog "/usr/local/var/log/apache2/myApp-access_log" common
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
然后我修改了 /usr/local/etc/apache2/2.4 文件夹中的 httpd.conf 文件,内容如下(我省略了注释行):
ServerRoot "/usr/local/opt/httpd24"
Listen 80
LoadModule authn_file_module libexec/mod_authn_file.so
[...]
LoadModule authn_core_module libexec/mod_authn_core.so
LoadModule authz_host_module libexec/mod_authz_host.so
LoadModule authz_groupfile_module libexec/mod_authz_groupfile.so
LoadModule authz_user_module libexec/mod_authz_user.so
[...]
LoadModule authz_core_module libexec/mod_authz_core.so
LoadModule access_compat_module libexec/mod_access_compat.so
LoadModule auth_basic_module libexec/mod_auth_basic.so
[...]
LoadModule reqtimeout_module libexec/mod_reqtimeout.so
[...]
LoadModule filter_module libexec/mod_filter.so
[...]
LoadModule mime_module libexec/mod_mime.so
LoadModule log_config_module libexec/mod_log_config.so
[...]
LoadModule env_module libexec/mod_env.so
[...]
LoadModule headers_module libexec/mod_headers.so
[...]
LoadModule setenvif_module libexec/mod_setenvif.so
LoadModule version_module libexec/mod_version.so
[...]
LoadModule unixd_module libexec/mod_unixd.so
[...]
LoadModule status_module libexec/mod_status.so
LoadModule autoindex_module libexec/mod_autoindex.so
[...]
<IfModule mpm_prefork_module>
#LoadModule cgi_module libexec/mod_cgi.so
</IfModule>
<IfModule !mpm_prefork_module>
#LoadModule cgid_module libexec/mod_cgid.so
</IfModule>
[...]
LoadModule dir_module libexec/mod_dir.so
[...]
LoadModule alias_module libexec/mod_alias.so
LoadModule rewrite_module libexec/mod_rewrite.so
<IfModule unixd_module>
User _www
Group staff
</IfModule>
ServerAdmin you@example.com
ServerName localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory "/Users/username/Sites">
MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "/usr/local/var/log/apache2/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "/usr/local/var/log/apache2/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/var/apache2/cgi-bin/"
</IfModule>
<Directory "/usr/local/var/apache2/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /usr/local/etc/apache2/2.4/mime.types
#AddType application/x-gzip .tgz
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
#AddHandler cgi-script .cgi
#AddHandler type-map var
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>
# Virtual hosts
Include /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf
[...]
<IfModule proxy_html_module>
Include /usr/local/etc/apache2/2.4/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
后来我在 /etc 文件夹中的 hosts 文件中添加了以下内容(与 /usr/local/etc 不同,这个位于根目录下,上一级 /usr):
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 myApp.username.com
我希望看到“它有效!”在 localhost:8080 和 myApp 在 localhost:80 上。 我确实看到“它有效!”在 localhost:8080 上,但如果我更新页面,我会得到“无法访问此站点/localhost 拒绝连接。”。我已经启动、停止、重新启动了 apache,但我一直都得到同样的行为。 在 localhost:80 上,我得到了 myApp,但我无法运行它,PHP 没有被解析,我只看到文件夹的树结构。
我运行了 apachectl configtest,我得到了语法 OK。我运行了 php -v 并得到了 PHP 5.4.45 (cli)(构建时间:2016 年 11 月 23 日 11:12:05)所以一切正常。
检查我上面粘贴的 httpd.conf 文件,我发现我缺少 php 模块,所以我添加了LoadModule php5_module libexec/libphp5.so
我仍然遇到同样的问题。
我似乎真的不明白的是所有文件夹的结构,因为我正在尝试遵循其他指南,但它们似乎指向我必须删除的 apache2 文件夹,而我不应该尝试卸载旧版本,显然它在重新安装期间没有重新创建(/etc/apache2/users)。我的 etc 文件夹中没有根级别的 apache2 文件夹,所以我假设我必须在 /usr/local 下的 /etc/apache2 中搜索 /users,但在那个文件夹中我只有目录2.4。
我对所有这些目录和文件的组织感到非常困惑,如果我不小心删除了 /etc,我似乎无法理解它们是否被试图帮助我的人移动了/apache2/users 卸载那些以前的版本,或者我基本上搞砸了太多不同的指南。
所以我的问题是:
我能以某种方式解决这个问题,因为它是在 localhost 正确解析 PHP 的端口 80 上显示 myApp 吗?
如果没有,我怎样才能以干净的方式卸载 apache,确保我不会删除不应该触及的重要文件,同时我会删除所有会与新安装的版本?
【问题讨论】:
-
我还有不止一个地方有 index.html 来表示“它有效!”消息是:/Library/WebServer/Documents/index.html.en 和 /usr/local/var/www/htdocs/index.html 我尝试修改它们,但我无法成功更改文本,所以公共文件夹 apache 在 localhost:8080 上响应时指的是两者都不是(或者我仍然缺少一些东西)。
标签: php parsing virtualhost macos-sierra apache2.4