首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache服务器开发环境

Apache服务器开发环境
EN

Stack Overflow用户
提问于 2018-03-27 19:13:29
回答 1查看 576关注 0票数 0

我在努力解释我遇到的问题。

为此,我通常使用XAMPP或MAMP,但我希望使用默认安装的附带的Apache。

因此,OS默认安装了apache服务器和php,它们运行得很好,没有任何问题,而且localhost可以很好地工作,我有很多其他的项目,比如projects和php。

我的问题是..。

我试图在我的计算机上为php-laravel项目安装一个dev环境,所以在我用自制软件安装了laravel之后,对文件进行了一些更改:

/私有/etc/apache2/extra/httpd-vhosts.conf /private/etc/apache2/httpd.conf /etc/主机

httpd-vhosts.conf

代码语言:javascript
复制
NameVirtualHost *:80

<VirtualHost *:80>
        DocumentRoot "~/Sites"
        #VirtualDocumentRoot "~/Sites"
        ServerName localhost
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot "~/Sites/cms/public"
        ServerName cms.test
        ServerAlias *.test
</VirtualHosts>

httpd.conf

代码语言:javascript
复制
ServerRoot "/usr"
<IfDefine SERVER_APP_HAS_DEFAULT_PORTS>
    Listen 8080
</IfDefine>
<IfDefine !SERVER_APP_HAS_DEFAULT_PORTS>
    Listen 80
</IfDefine>
User myusername
ServerName localhost:80
DocumentRoot "/Users/myusername/Sites"
<Directory "/Users/myusername/Sites">
    Options All
    MultiviewsMatch Any
    AllowOverride All
    Require all granted
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

主机

代码语言:javascript
复制
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1       cms.test

在此之后,我重新启动了服务器,当我试图转到:

localhost 我刚在chrome localhost上写

如果我试过localhost/info.php localhost/info.php

正如您在“站点”文件夹中看到的,有一个info.php文件文件夹站点是ServerDirectory所在的地方,如您所见,有一个info.php文件。

当我尝试localhost/cms/public/index.php 结果是一样的

我执行$ whereis ,结果是

然后执行$ /usr/sbin/httpd -V,结果是

代码语言:javascript
复制
Server version: Apache/2.4.28 (Unix)
Server built:   Oct  9 2017 19:54:20
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

我还执行了命令apachectl -S,结果是

代码语言:javascript
复制
VirtualHost configuration:
ServerRoot: "/usr/local/opt/httpd"
Main DocumentRoot: "/usr/local/var/www"
Main ErrorLog: "/usr/local/var/log/httpd/error_log"
Mutex rewrite-map: using_defaults
Mutex default: dir="/usr/local/var/run/httpd/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/usr/local/var/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="_www" id=70
Group: name="_www" id=70

我可以看到两种不同的配置,我不知道我能做什么来解决这个问题。

所以这就是为什么我要寻求帮助,我真的不知道我还能做些什么来解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2018-03-28 00:08:05

1)看起来您在多个位置安装了apache。检查一下以确保。做:

代码语言:javascript
复制
find /usr -name apachectl

如果您得到了多个结果,那么很可能您已经安装了一个来自Homebrew的版本(它将在/usr/local/bin中安装apachectl,并将其配置文件的PidFile指令设置为/usr/local/var/ run /httpd/httpd.pid),并且有另一个版本,它将安装在/usr/sbin中,这是您的系统二进制文件夹(根据我的经验,将PidFile设置为在/etc/var/run/中运行)。

"Whereis“不返回优先级为的apachectl (即在执行命令时调用的)。更好的命令是:

代码语言:javascript
复制
which apachectl

它将显示您在输入apachectl时正在使用的apachectl。

如果您有多个安装,则需要在~/..bash_profile中为所需的apachectl版本设置优先级。

您之所以看到两种不同的配置,是因为您正在使用/usr/sbin/httpd来检查其中一个配置,而使用apachectl -S检查另一个配置文件,后者很可能调用了Homebrew安装的httpd。

2)阻止对目录的访问可能是由于文件本身没有正确的权限而造成的问题。你经常需要

代码语言:javascript
复制
chown -R user:group dir_name

目录,其中用户和组是在您的配置文件中列出的用户。在我的机器上,这是配置文件中这两个文件的_www。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49520760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档