susanBuck / e2-fall22

0 stars 0 forks source link

Getting 404 for contact and about pages! #38

Closed racheleverett closed 2 years ago

racheleverett commented 2 years ago

I have successfully set the framework and the index page works great but no matter what I do, no other pages are working, I receive 404 error for all pages like about, contact!

This is my routes file

return [
    '/' => ['AppController', 'index'],
    '/contact' => ['AppController', 'contact'],
    '/about' => ['AppController', 'about'],
];

And AppController

namespace App\Controllers;

class AppController extends Controller
{
    /**
     * This method is triggered by the route "/"
     */
    public function index()
    {
        $welcomes = ['Welcome', 'Aloha', 'Welkom', 'Bienvenidos', 'Bienvenu', 'Welkomma'];

        return $this->app->view('index', [
            'welcome' => $welcomes[array_rand($welcomes)]
        ]);
    }

    public function contact()
    {
        return $this->app->view('contact', ['email' => 'support@zipfoods.com']);
    }

    public function about()
    {
        return $this->app->view('about');
    }
}

Please help.

susanBuck commented 2 years ago

Hi @racheleverett -

I logged into your server and see the following site config for your zipfoods app:

server {

    listen 80;
    server_name e2zipfoods.racheleverett.me;
    root /var/www/e2/zipfoods/public/;

    index index.php index.html;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Please update this config so it includes the three lines specific to the location directive as shown in this example:

server {
    listen 80;
    server_name e2zipfoods.racheleverett.me;
    root /var/www/e2/zipfoods/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Ref: https://hesweb.dev/e2/notes/php/frameworks/setup#web-server-setup

The purpose of those three lines is to route all incoming traffic through the index.php file. Without these lines, your routing system in the framework won't work.

After making those changes, don't forget to restart the server.

Give that a shot and if it's still not working let me know!

racheleverett commented 2 years ago

About and contact pages have started working.

Thank you for the help, appreciate it.