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
posta 2 mesi fa306 visualizzazioni
1 Risposta
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
ESPERTO
con risposta 2 mesi fa
  • 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!

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande