Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的Laravel 5.5应用程序在部署后无法在远程服务器上运行,但在使用WAMP的本地服务器上运行良好_Php_Laravel 5_Vps - Fatal编程技术网

Php 我的Laravel 5.5应用程序在部署后无法在远程服务器上运行,但在使用WAMP的本地服务器上运行良好

Php 我的Laravel 5.5应用程序在部署后无法在远程服务器上运行,但在使用WAMP的本地服务器上运行良好,php,laravel-5,vps,Php,Laravel 5,Vps,在我的本地服务器上,该应用程序的所有功能都正常工作,但拒绝远程工作。如果我访问应用程序www.mysite.com。它总是显示内部服务器错误。虽然我在web.php中没有任何路由,但我希望重定向回404 not found页面,但没有这样做,但它在localhost上有 另一个主要问题是,我在api.php中有许多路由,如果我向其中任何一个路由发送数据,它们都会接受数据,甚至可能在必要时将其保存在数据库中,但它永远不会返回我在每次成功操作后定义的json响应。即使操作成功,我总是得到500内部服

在我的本地服务器上,该应用程序的所有功能都正常工作,但拒绝远程工作。如果我访问应用程序www.mysite.com。它总是显示内部服务器错误。虽然我在web.php中没有任何路由,但我希望重定向回404 not found页面,但没有这样做,但它在localhost上有

另一个主要问题是,我在api.php中有许多路由,如果我向其中任何一个路由发送数据,它们都会接受数据,甚至可能在必要时将其保存在数据库中,但它永远不会返回我在每次成功操作后定义的json响应。即使操作成功,我总是得到500内部服务器错误的响应。我已经讨论这个问题两个多星期了

我正在服务器上使用PHP7.2

这是我的.htaccess文件

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
    RewriteEngine On
    RewriteBase /
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
例如,注册路由工作正常,但不会返回我指定的Json响应,即使一切顺利,它也会返回500个内部服务器错误

如果一切顺利,我没有得到响应,我的存储/日志中不会记录任何错误。但如果操作不成功,我确实看到了错误


所有文件夹都有777权限,我还多次清除了所有缓存

问题已解决。问题恰好是我的中间件

它的配置如下所示

<?php

namespace App\Http\Middleware;

use Closure;

class CORS
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        header('Access-Control-Allow-Origin : *');
        header('Access-Control-Allow-Headers : Content-Type,X-Auth-Token,Authorization,Origin');
        return $next($request);
    }
}

你能检查一下php的错误日志吗?可能在
/var/log
中,除非您有自定义配置。如果你说它有时执行你的代码,但仍然返回500,那么我可能会考虑一些中间件,试图在请求之后执行一些事情,或者可能发生一些事件。在上面,服务器上可能缺少一些php模块。让我们尝试检查是否可以获得日志消息。我找到了下面的错误日志,您让我在其中检查[Sat Feb 22 14:37:06.006557 2020][http:error][pid 26129:tid 47139616982784][c客户端105.112.178.154:24113]AH02429:响应头名称“Access Control Allow-Origin”包含无效字符,正在中止请求。很高兴我能提供帮助。如果你喜欢这个评论,或者其他评论,那么你也可以把它们选为“有用的”。你可以在评论旁边的左边找到它。您将看到一个“upvote”图标和一个“flag”图标,这意味着您可以upvote或报告评论。
public function userSignup(Request $request)
    {
        $rules = [
            'name' => 'required|string|max:200',
            'password' => 'required|between:8,100|confirmed',
            'phone' => 'unique:users|required|digits:11|numeric',
            'email' => 'unique:users|required|email',

        ];
        $validator = Validator::make($request->all(), $rules);
        $code = mt_rand(100000, 900000);
        $hCode = FacadesHash::make($code);
        if ($validator->passes()) {
            $user = User::create([
                'name' => $request['name'],
                'email' => $request['email'],
                'phone' => $request['phone'],
                'otp' => $hCode,
                'password' => FacadesHash::make($request['password']),
            ]);

            $data = [
                'name' => $request['name'], 'subject' => 'Email Confirmation',
                'view' => 'mails.emailconfirm', 'code' => $code
            ];


            return response()->json(['success' => true, 'status' => 200, 'message' => 'Your account has been created successfully and an OTP code has been sent to your email'], 200);
        } else {

            return response()->json(['success' => false, 'status' => 200, 'message' => $validator->errors()->first()], 200);
        }
    }
<?php

namespace App\Http\Middleware;

use Closure;

class CORS
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        header('Access-Control-Allow-Origin : *');
        header('Access-Control-Allow-Headers : Content-Type,X-Auth-Token,Authorization,Origin');
        return $next($request);
    }
}
<?php

namespace App\Http\Middleware;

use Closure;

class CORS
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Headers', 'Content-type, X-Auth-Token, Authorization, Origin');
    }
}