【问题标题】:MAMP 500 Internal Server ErrorMAMP 500 内部服务器错误
【发布时间】:2017-01-31 04:57:59
【问题描述】:

我遇到了一个小问题。

我做了两个虚拟主机“web-backend.local”和“oplossingen.web-backend.local”。

但我总是遇到“500 内部服务器错误”

我做错了什么?

主机文件:

##
# 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
fe80::1%lo0     localhost

# MAMP VirtualHost Mappings
127.0.0.1 web-backend.local
127.0.0.1 oplossingen.web-backend.local

httpd-vhosts.conf:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

<VirtualHost web-backend.local:* >
DocumentRoot "/Users/yawuarsernadelgado/Documents/web-backend/cursus"
ServerName web-backend.local
<Directory "/Users/yawuarsernadelgado/Documents/web-backend/cursus">
    AllowOverride All
    Require all granted
    Options +Indexes
    IndexOptions NameWidth=*
</Directory>
ServerAlias web-backend.local
</VirtualHost>

<VirtualHost oplossingen.web-backend.local:* >
DocumentRoot "/Users/yawuarsernadelgado/Documents/web-backend/oplossingen"
ServerName oplossingen.web-backend.local
<Directory "/Users/yawuarsernadelgado/Documents/web-backend/oplossingen">
    Allow from all
    Require all granted
    Options +Indexes
    IndexOptions NameWidth=*
</Directory>
</VirtualHost>

【问题讨论】:

  • 尝试查看您的 apache 日志和 php 日志。

标签: mamp virtualhost


【解决方案1】:

虽然被举报MAMP 500 Server Error,但通常与MAMP关系不大。

500 个内部服务器错误表明您已经崩溃了 php 页面。解决方案是在您可能崩溃的页面中添加以下错误报告 php 代码:


    // display php error
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

如果你使用jQuery.Ajax,那上面action.php的代码恐怕不行,还有另外一个方法,后面跟着

  • 将此添加到index.htmlindex.php

<div id="show-error" style="position: fixed; z-index: 10000; height: 20vh; width: 100vw; background:#f08080; border-radius:20px; opacity: 0.8; display: flex; font-size: 2rem; justify-content: center; align-items: center; display: none;"></div>

  • 在ajax调用的php文件中,设置成功码和失败码

try{
    // main   
    echo json_encode(['status' => 1, 'msg' => 'succeed']);
}catch(Exception $e){
    echo json_encode(['status' => 0, 'msg' => $e->getMessage()]);
}

  • 最后,在 ajax javascript 文件中,如果发生错误,则捕获错误

$.ajax({
    url: '../php/action.php', 
    method: 'POST',
    data: array('some data'), 
}).done(function(result){
    var output = JSON.parse(result);
    if(output.status == 0){
        $('#show-error').show();
        $('#show-error').html(output.msg);
        exit();
    }else{
        // no error occurred
    }
});

【讨论】:

    【解决方案2】:

    从每个虚拟主机的 httpd-vhosts.conf 文件中删除以下行:

    <Directory "/Users/yawuarsernadelgado/Documents/web-backend/cursus">
        AllowOverride All
        Require all granted
        Options +Indexes
        IndexOptions NameWidth=*
    </Directory>
    

    为我工作:D

    【讨论】:

      猜你喜欢
      • 2019-01-17
      • 2011-10-17
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      相关资源
      最近更新 更多