How to configure Laravel correctly on ec2 instance (Amazon Linux 2023)?

0

Hello everyone,

I'm new to Laravel and want to deploy an application written according to the Laravel framework on an EC2 instance. I browsed the generated Laravel welcome page through my browser, making sure I had Laravel installed. I uploaded the script code to the /var/www/html directory and installed the Laravel application in the /var/www/mylaravel directory. And added a virtual host to the /etc/httpd/conf/httpd.conf file and pointed it to the /var/www/mylarael/public public directory. However, I am unable to route to the script's installer through Laravel, meaning that when I type in the browser: https://mydomain.com/install, the page returns: 404 error. Additionally, I have created a symbolic link to /var/www/mylarael/public in the /var/www/html directory. But it still doesn't work, what should I do?

Best wishes!

Karl
질문됨 2달 전308회 조회
1개 답변
0

Hello.

Please check the web server logs.
Since it is a 404 error, I think that the file is missing or that Laravel is not routing properly.
You should be able to check the routing information by moving to the directory containing Laravel and running the following command.

php artisan route:list
profile picture
전문가
답변함 2달 전
  • Hello, Riku_Kobayashi

    Can you take a look at it for me? This is the routing information: " GET|HEAD/................................................ ................................................................. ............................ POST _ignition/execute-solution ............. ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController GET|HEAD _ignition/health-check ........................ ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController POST _ignition/update-config ........................ ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController GET|HEAD up........................................ ................................................................. .............................

                                                                                                                      Showing [5] routes
    

    "

  • As far as I can see from the results, there doesn't seem to be a route called "/install". Try adding a route to "/install". https://readouble.com/laravel/10.x/en/routing.html

  • Hi, Riku_Kobayashi

    I navigated to my Laravel project directory (cd /var/www/mylaravel), entered the following code in the command line terminal: php artisan make:controller InstallControllers_openaitpl, and generated a controller file "InstallControllers_openaitpl.php". I added the following code to the file: "//app/Http/Controllers/InstallControllers_openaitpl.php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    class InstallControllers_openaitpl extends Controller { public function index() { return view('install'); // Assuming you have a view named "install.blade.php" } } "save. At the same time, I opened web.php in the /var/www/mylaravel/routes/ directory and added the following code to the file: " use App\Http\Controllers\InstallControllers_openaitpl;

    Route::get('/install', [InstallControllers_openaitpl::class, 'index']);

    " save. When I enter my project URL (https://mydomain.com/install) in the browser, the page returns: "Cannot declare class App\Http\Controllers\InstallControllers_openaitpl, because the name is already in use " No matter how I change the namespace, the page always returns: "The name is already in use." Why does this happen? Did I do something wrong?

    Best wishes!

  • If the error is correct, the class name may already be in use. The same error may also occur if there is a misspelling of "namespace". By the way, did you clear the cache after adding the route?

    php artisan cache:clear
    

    This may not be very relevant, but what happens if you change the class name as follows?

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    
    class InstallController extends Controller
    {
        public function index()
        {
            return view('install');
        }
    }
    
  • Hi, Riku_Kobayashi

    This doesn't seem to work. Thank you for your help!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠