Webpage from localhost with a try/catch pdo connection to database won't load

Hi people!

I’ve been struggling with this for a month maybe, and am unable to find any proper answer by myself on internet.
As part of my courses, I am learning oriented-object php and MVC architecture. But whenever I create a Model object with a try/catch containing a PDO connection to my database, I just land on a white page; no error messages, nada, just a deep white browser page.
The thing is, if I take the exact same files and load them through MAMP on my macbook, everything works fine. And the problem is not necessarily fedora related, as I tried also on Ubuntu and Cinnamon, with the same results.
My httpd.service et mariadb are activated. My databases id’s are corrects, I setted and revised them with mysql_secure_installation.
I thought the issue might be due to SELinux, but even in permissive mode it still doesn’t work. I tried with nginx from a file located in my Desktop, same result. I can load pages with a straight connection to a database, or without database without problems. But it seems that everytime my connection is a bit ‘far’ from my index.php, it doesn’t work.
So I’m about to forget even trying to use linux for local dev and go full docker, but to be honest, it seems to me that I am just missing something basic about Linux and files permissions (I also try a full bunch a owner and permission changes on my /var/www/html folders, without success).
Needless to say I am quite a noob in Linux environment, but I plan to stay here, so hopefully your lights will guide me wisely!

Welcome to ask.:fedora:edora @yanlieb

A white page is already a good sign.
I know from my own experience that tweaking with a web-server needs quite a lot of basic knowledge. Did you follow a manual? Which one?

Getting started with Apache HTTP Server :: Fedora Docs

As you have a white page, are you using the right web-root? Index.php with a phpinfo works?

What exactly do you want achieve? As I remember index.php is working per default, everything else you have to configure. But the info’s you should get from phpinfo.

Hello ilikelinux, thanks for your time and reply!

The goal was to create a CRUD with an MVC architecture in php. Thing is, I have my version, and my teacher’s version, and both works perfectly on my macbook, but not on my Linux.

Your answer helped me find other paths to think about, and I finally resolved the issue, which was quite stupid, but extremely confusing, especially for my newbie brain.

I started by creating an index.php with phpinfo() in my html folder, as you mentionned, just to be sure I was clean from the start. And I decided to follow this step-by-step debug once again.

Thanks to google chrome, I had an error message : 500. A quick internet search helped me locate the error_log in /var/log/httpd/error_log. I left it open in my terminal with ‘vim’, in order to follow in real time the errors. This is where the facepalms start.

First, in my index.php I create a new object by instanciating my controller :

$app = new Controllers\VtcController;

My VtcController class is in a folder called ‘controller’ = not ‘C’, but ‘c’ … Facepalm 1 :

$app = new controllers\VtcController;

Then in my controller.php I create an object that instanciates my model manager:

public function __construct(){
        $this->db = new \Models\VtcManager;
    }

And guess what… my VtcManager is in a folder called models, with an ‘m’, not an ‘M’.
I decided to go with the ‘use’ attribute, in order to remove the first '' (and mostly because it seems to ‘please’ more phpstorm) :

use models;

class VtcController
{
    private $db;

    public function __construct(){
        $this->db = new models\VtcManager;
    }

//etc...

I am still confused as to why it works on a mac/windows with the first capital letter. This was already weird to me when my teacher saw us that. Why using a capital letter if my file is written all in lowercase?
But as it was working, I thought this was the normal way… Like, okay, if you want to instanciate a class from another folder, you have to write the folder name like this…

Hopefully this would help other new fedora/linux users coming from mac/windows! (and i’d feel less alone…)

1 Like

A Gift for you :wink: :
New Linux Users | pitfalls and differences

Nice thought. I remember when i was in that situation. It is quite long since. This motivated me to do the topic above.