PHP file name case sensitivity on AWS EC2?

I am working with PHP OOP. While doing things, on my vagrant testing server I set up some code that connects to a database and performs PHP. In the PHP I have files that are lower case names. A lot of my code names these classes in proper case (e.g., DatabaseObject). The code I used on the testing server (vagrant) works flawlessly. The next thing that I did is move my code to an AWS EC2 instance. Now it is there, and I am getting errors. After trying some things, I realized that my errors are related to my class names not being in the same case as my *.php files that hold them. This is the first time that I have seen this. I followed some instructions on how to add lines to the httpd.conf file but there is still no change. I then just manually changed the names of the *.php files and things started to work. However I am saying to myself, there has to be a simpler way? For one, my local server via Vagrant does not have this problem. Can anyone offer any advice? Thanks

Warning: include(classes/DatabaseObject.class.php): failed to open stream: No such file or directory in /var/www/html/chain_gang/private/initialize.php on line 45

Warning: include(): Failed opening 'classes/DatabaseObject.class.php' for inclusion (include_path='.:/usr/share/pear7:/usr/share/php7') in /var/www/html/chain_gang/private/initialize.php on line 45

Fatal error: Uncaught Error: Class 'DatabaseObject' not found in /var/www/html/chain_gang/private/initialize.php:51 Stack trace: #0 /var/www/html/chain_gang/public/index.php(4): require_once() #1 {main} thrown in /var/www/html/chain_gang/private/initialize.php on line 51

Sounds like your EC2 instance is running Linux, while you are running vagrant with a mounted share from either MacOS or Windows.

MacOS and Windows are case insensitive and will happily load database.php for the Database class, whereas Linux will not.

Even if your vagrant box is Linux that doesn’t matter, as the file loading is done through the share by your own OS.

But it’s good practice to have the name of the file exactly the same as the class therein so solving that would be your best option here.

If you follow the PSR standards you won’t have problems like this.

Thanks so much. When I just changed the filenames to match the same syntax inside the file. It works perfectly. I will use your advice. I was thinking it could lead to other problems, however, this seems good. :slight_smile:

Thanks so much. I will try to learn and implement this. :slight_smile:

1 Like

Focus on PSR-1, PSR-2 and PSR-4

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.