简体   繁体   English

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

[英]My Laravel 5.5 app not working on remote server namecheap VPS after deployment but working fine on local server with WAMP

Everything about this app is working fine on my local sever, but refused to work remotely.关于这个应用程序的一切在我的本地服务器上运行良好,但拒绝远程工作。 if i visit the app www.mysite.com.如果我访问应用程序 www.mysite.com。 It always shows internal server error.它总是显示内部服务器错误。 Though i don't have any route in web.php but i expected to redirect back to 404 not found page but not doing that but it does on localhost.虽然我在 web.php 中没有任何路由,但我希望重定向回 404 not found 页面但没有这样做,但它在本地主机上。

The other main problem is , i have many routes in api.php , if i send data to any of the routes, they accept data and might even save them in database where it is necessary but it will never return the json Response that i have defined after every successful operation.另一个主要问题是,我在api.php 中有很多路由,如果我将数据发送到任何路由,它们会接受数据,甚至可能将它们保存在需要的数据库中,但它永远不会返回我拥有的 json 响应在每次成功操作后定义。 The response i always get is 500 internal server error even if the operation was successful.即使操作成功,我始终得到的响应是 500 内部服务器错误。 I have been on this issue for over two weeks now.我已经在这个问题上讨论了两个多星期了。

I am using PHP 7.2 on the server我在服务器上使用 PHP 7.2

Here is my .htaccess file这是我的 .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>

api.php api.php

<?php

Route::group(['prefix' => 'user', 'namespace' => 'User'], function () {

    Route::post('/login', 'UserAuthController@userLogin');
    Route::post('/signup', 'UserAuthController@userSignup');

});

UserController.php用户控制器.php

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);
        }
    }

the signup route for example, is working fine but will never return the Json response i specified, it will rather return 500 internal server error even if everything went well.例如,注册路由工作正常,但永远不会返回我指定的 Json 响应,即使一切顺利,它也会返回 500 内部服务器错误。

No error is being logged in my storage/log if everything went well and i dont get the response.如果一切顺利并且我没有得到响应,我的存储/日志中不会记录任何错误。 But i do see error there if the operation was not successful.但如果操作不成功,我确实会在那里看到错误。

all folders have 777 permissions and i have as well clear all caches so many times所有文件夹都有777权限,我也多次清除所有缓存

Problem solved .问题解决了 The problem happens to be my middle ware.问题恰好是我的中间件。

It was configured like the following before之前是这样配置的

<?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);
    }
}

I now changed it to this new one below and everything started working perfectly我现在把它改成了下面的这个新的,一切都开始完美地工作了

<?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');
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Php脚本不能在Wamp Localhost上工作,但在远程服务器上工作正常 - Php Script not working on Wamp Localhost but working fine on remote server Laravel图像未在服务器上显示并且在我的本地计算机上工作正常 - Laravel image not shown on server and working fine on my local machine AJAX程序未在Webstie上运行,但在本地WAMP服务器上运行正常 - AJAX Program Not running on Webstie but working fine on Local WAMP Server 在本地主机Wamp服务器上工作 - Working on local host wamp server 会话在远程服务器上的页面重新加载时重新生成,在本地服务器上运行良好 - Session is regenerate on page reload in remote server working fine in local server Wamp Server 3.0.6可以正常工作,但不能在网络上运行 - Wamp Server 3.0.6 working fine as localhost, but not on network laravel 5.5 Auth::attempt login 在本地服务器上工作但在实时服务器上不工作 - laravel 5.5 Auth::attempt login working on local server but not working on live server 网站在本地但不在在线服务器(WAMP)上运行 - Website working on local but not on online server (WAMP) 带有.htaccess的SEO在本地WAMP服务器上不起作用 - SEO with .htaccess not working on local WAMP server 脚本可以在Wamp服务器上运行,但不能在我的VPS上运行 - script works on wamp server but not on my vps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM