我已经购买了Laravel项目,并且有一个控制器脚本/代码导致了我的问题。我已经将XAMPP更新到7.3.3并完成了安装,但是,到最后它给了我Error 500。
经过几个小时的调试,我发现注释下面的代码可以解决此问题,但随后在网站上给我带来了更大的错误。下面的代码有什么问题?
完整代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use URL;
use DB;
use Hash;
use App\GeneralSetting;
use App\BusinessSetting;
use App\User;
use App\Product;
class InstallController extends Controller
{
public function step0() {
$this->writeEnvironmentFile('APP_URL', URL::to('/'));
return view('installation.step0');
}
public function step1() {
$permission['curl_enabled'] = function_exists('curl_version');
$permission['db_file_write_perm'] = is_writable(base_path('.env'));
$permission['routes_file_write_perm'] = is_writable(base_path('app/Providers/RouteServiceProvider.php'));
return view('installation.step1', compact('permission'));
}
public function step2() {
return view('installation.step2');
}
public function step3($error = "") {
if($error == ""){
return view('installation.step3');
}else {
return view('installation.step3', compact('error'));
}
}
public function step4() {
return view('installation.step4');
}
public function step5() {
return view('installation.step5');
}
public function purchase_code(Request $request) {
$request->session()->put('purchase_code', $request->purchase_code);
return redirect('step3');
}
public function system_settings(Request $request) {
$generalsetting = GeneralSetting::first();
$generalsetting->site_name = $request->name;
$generalsetting->address = $request->address;
$generalsetting->phone = $request->phone;
$generalsetting->email = $request->email;
$generalsetting->save();
$businessSetting = BusinessSetting::where('type', 'system_default_currency')->first();
$businessSetting->value = $request->system_default_currency;
$businessSetting->save();
$this->writeEnvironmentFile('APP_NAME', $request->system_name);
$user = new User;
$user->name = $request->admin_name;
$user->email = $request->admin_email;
$user->password = Hash::make($request->admin_password);
$user->user_type = 'admin';
$user->email_verified_at = date('Y-m-d H:m:s');
$user->save();
foreach(Product::all() as $product){
$product->user_id = $user->id;
$product->save();
}
$previousRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.php');
$newRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.txt');
copy($newRouteServiceProvier, $previousRouteServiceProvier);
//sleep(5);
return view('installation.step6');
// return redirect('step6');
}
public function database_installation(Request $request) {
if(self::check_database_connection($request->DB_HOST, $request->DB_DATABASE, $request->DB_USERNAME, $request->DB_PASSWORD)) {
$path = base_path('.env');
if (file_exists($path)) {
foreach ($request->types as $type) {
$this->writeEnvironmentFile($type, $request[$type]);
}
return redirect('step4');
}else {
return redirect('step3');
}
}else {
return redirect('step3/database_error');
}
}
public function import_sql() {
$sql_path = base_path('shop.sql');
DB::unprepared(file_get_contents($sql_path));
return redirect('step5');
}
function check_database_connection($db_host = "", $db_name = "", $db_user = "", $db_pass = "") {
if(@mysqli_connect($db_host, $db_user, $db_pass, $db_name)) {
return true;
}else {
return false;
}
}
public function writeEnvironmentFile($type, $val) {
$path = base_path('.env');
if (file_exists($path)) {
$val = '"'.trim($val).'"';
file_put_contents($path, str_replace(
$type.'="'.env($type).'"', $type.'='.$val, file_get_contents($path)
));
}
}
}
可解决错误500(已删除/注释)但导致更多问题的代码段:
$user->save();
foreach(Product::all() as $product){
$product->user_id = $user->id;
$product->save();
}
我不知道为什么删除/注释掉那部分代码似乎可行,但是我希望有人可以解释?
答案 0 :(得分:0)
此问题已解决。解决方案如下。
我按照Mayank Dudakiya的说明进行操作,并在env文件中将app_debug设置为true。然后,我可以查看所有问题,并一一解决了这些问题,总共有四个主要问题。
我的实际问题是由于mysqld中的innodb内存大小所致。只需对my.ini进行简单的编辑,就可以将其从5m设置为500m,并解决了该问题,并允许数据库正确安装和提示。
感谢所有回复的人。