Class Autoload Issues on Nginx+PHP-FPM 7.1 BUT Not on PHP 7.0 (Built-in)

345 views
Skip to first unread message

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 11:49:21 AM3/3/17
to f3-fra...@googlegroups.com
Hello,

This is a strange issue.  I have no issues running my code with built-in PHP 7.0 web server on my Mac but I F3 fails to find custom route class to load on my Nginx 1.10 and PHP-FPM 7.1.2.

My setup has the following folder structure (of relevant files):
- html (root)      <== This was incorrectly named f3 (it is called 'f3' on my Mac but 'html' on the Nginx server - both are document roots)
 
- index.php
 
- app
   
- controls
     
- HomeController.php
   
- config
     
- config.ini
     
- route.ini
- private
 
- lib (f3)

In config.ini I have the following autoloader settings:
[globals]
AUTOLOAD
= app/

In route.ini I have the following custom route:
[routes]
GET
/        = \Controls\Common\HomeController->render

And the HomeController class is defined with:
namespace Controls\Common;

class HomeController extends \Controls\Base\CoreController {

If I try to access the root of my web app I get the following error on my Nignx/PHP-FPM 7.1.2 system but works perfectly fine on my built-in PHP 7.0:
Not Found
HTTP
404 (GET /)
[/srv/apps/nginx/skgcasoccer.com/private/lib/base.php:1561] Base->error()
[index.php:50] Base->run()

In addition, in place php files like phpinfo.php work perfectly fine on both.

If I comment out the line 1561 in base.php which does a class_exists check I get the following error:
Internal Server Error
Invalid class \Controls\Common\HomeController
[/srv/apps/nginx/skgcasoccer.com/private/lib/base.php:2152] Base->error()
[/srv/apps/nginx/skgcasoccer.com/private/lib/base.php:1747] Base->grab()
[/srv/apps/nginx/skgcasoccer.com/private/lib/base.php:1599] Base->call()
[index.php:50] Base->run()

So it is referencing the right class and referencing it properly it just can't seem to locate it.

It's almost as if on Nginx/PHP-FPM 7.1.2 it is thinking the root folder of the class loading is different from that on PHP 7.0.

Do I need to tell Nginx something special like set the "root" inside the PHP block to the f3 folder vs. the web server root or something.

Any help is extremely appreciated.  I have spent many hours on this issue.

Thanks,

--Nikolaos

ved

unread,
Mar 3, 2017, 12:14:32 PM3/3/17
to f3-fra...@googlegroups.com
Hey, it's probably not related with nginx since it works with a previous php version but please post your nginx config anyway.

Also, please tell us what version of F3 you are using.
If you're not using the latest master from bcosca/fatfree-core then please try it as some php7 fixes were made there that still haven't been ported to stable.

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 12:52:51 PM3/3/17
to Fat-Free Framework
Thanks Ved.  Providing my configuration below however...

I am not 100% clear on what in the filesystem is considered the root of the class loading?
For example in my folder structure is the root the "f3" folder (at least that is what I assume)?

Here is my Nginx configuration skgcasoccer site configuration:

server {
  listen          
192.168.0.126:443 ssl;
  server_name      v3
.skgcasoccer.com;
  ssl_certificate        
/srv/etc/nginx/ssl/certs/ssl-cert-v3.skgcasoccer.com.crt;
  ssl_certificate_key    
/srv/etc/nginx/ssl/private/ssl-cert-v3.skgcasoccer.com.key;
  access_log      
/srv/logs/nginx/skgcasoccer.com/access_v3.skgcasoccer.com.log;
  error_log        
/srv/logs/nginx/skgcasoccer.com/error_v3.skgcasoccer.com.log notice;

  include
/srv/etc/nginx/include/skgcasoccer.com_core.conf;
}

and the included configuration "skgcasoccer.com_core.conf" is as follows:

        root           /srv/apps/nginx/skgcasoccer.com/html;
        index          index
.php index.htm index.html;

        location
= /favicon.ico { log_not_found off; access_log off; }
        location = /
robots.txt { allow all; log_not_found off; access_log off; }

        location
/ {
                index index
.php index.html index.htm;
                try_files $uri
/index.php?$query_string;
       
}
        location
~ \.php$ {
                fastcgi_index index
.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
;
                fastcgi_pass unix
:/var/run/php-fpm/php-fpm-skgcasoccer.com.sock;
                include
/srv/etc/nginx/conf/fastcgi_params;
               
# FastCGI Bufffers for performance

                fastcgi_buffer_size
128k;
                fastcgi_buffers
256 16k;
                fastcgi_busy_buffers_size
256k;
                fastcgi_temp_file_write_size
256k;
                fastcgi_read_timeout
300;
       
}

        location
~* \.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ { access_log off; expires 1w; }

I already tried adding an explicit root directive in the PHP location block however it essentially is inheriting the same value from the top of the file.

Any ideas / thoughts appreciated,

--Nikolaos

ved

unread,
Mar 3, 2017, 1:42:39 PM3/3/17
to Fat-Free Framework
What about your F3 version? Did you try the latest master from fatfree-core ?

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 2:03:48 PM3/3/17
to Fat-Free Framework
Sorry.  Version is 3.6.0 (19 November 2016).

--Nikolaos

bcosca

unread,
Mar 3, 2017, 2:45:51 PM3/3/17
to Fat-Free Framework
Is this an existing directory that points to the DOCUMENT_ROOT that php should be reporting?

root           /srv/apps/nginx/skgcasoccer.com/html;

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 2:52:39 PM3/3/17
to Fat-Free Framework
Sorry for the confusion.  The 'html' folder is the root folder of the web site on the Nginx server and 'f3' was the name of the root folder on my Mac.

I have edited my original post details with changes in red.

--Nikolaos 

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 4:00:59 PM3/3/17
to Fat-Free Framework
Took the latest fatfree core master and same issue.  Other than trying PHP 7.0 does anyone have any other ideas/leads.

I am building a server and this is now a deployment show stopper!  ;-(

--Nikolaos

ved

unread,
Mar 3, 2017, 5:06:08 PM3/3/17
to f3-fra...@googlegroups.com
Why not just place the lib folder inside the root folder or use composer to handle all that?

I'm also using nginx and php-fpm (v7.1.2) and everything works pretty fine. My (abbreviated) nginx cfg is:

server {
        listen
443 ssl http2;
        server_name example
.com;
        root
/var/www/site;
 
        location
/ {
                try_files $uri $uri
/ /index.php?$query_string;
       
}
 
        location
~ \.php$ {
                fastcgi_pass
127.0.0.1:9000;
                include snippets
/fastcgi-php.conf;
       
}
}

Inside "/var/www/site" is either a composer.json file and respective vendor folder, or a lib folder with F3 inside and I just use the require base.php method.

Using composer on most apps but even when using the require base.php it still works fine.

You should simplify your setup to the most until it works or enable more verbose logging on your php-fpm daemons.

Try to uncomment "catch_workers_output = yes" on your "/etc/php/7.1/fpm/pool.d/www.conf" or related pool file and try again and then see your logs again.

EDIT: assuming Debian on those paths, but should be easy to find the equivalent files on other distros

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 6:33:13 PM3/3/17
to Fat-Free Framework
Really appreciate the assistance.  So moving the 'lib' folder to inside the root doesn't make a difference... neither does going with Nginx+PHP 7.0.

I stripped down my Nginx config and then I ended up with a 403 error... so I will need to do some trial and error.

Can you post your fastcgi-php.conf... I have a feeling something in my conf settings is making things go south.

--Nikolaos

Sascha

unread,
Mar 3, 2017, 6:44:43 PM3/3/17
to Nikolaos Giannopoulos via Fat-Free Framework, Fat-Free Framework
You said, you were playing around with PHP 7.0 built-in. Have you even configured your nginx to use php7.0-fpm instead of php7.1-fpm?

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/a3fa33f7-bf9d-4ef2-bf67-da89fae3ea0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikolaos Giannopoulos

unread,
Mar 3, 2017, 6:53:29 PM3/3/17
to Fat-Free Framework
Hi Sascha,

So I have VM images running:
- Ubuntu 16.04 LTS with Nginx 1.10 and PHP-FPM 7.1.2
- Ubuntu 16.04 LTS with Nginx 1.10 and PHP-FPM 7.0.16
I have scripts that build out the install (its actually compiled from source) so it just runs for a while to complete....

And on my Mac I have built-in PHP 7.0 running without issues although I have not tried setting up Nginx on my Mac

--Nikolaos

Sascha

unread,
Mar 3, 2017, 7:11:31 PM3/3/17
to Fat-Free Framework
It's still not really clear to me. Does F3 work in any of your VMs? Have you tried F3's testing framewor (https://github.com/bcosca/fatfree)?

ikkez

unread,
Mar 4, 2017, 5:01:46 AM3/4/17
to f3-fra...@googlegroups.com
rename "HomeController.php" to "homecontroller.php"
Either have all files and folders in the same case as their Namespace/ClassName or all lowercase.

controls/HomeController.php that contains \Controls\HomeController will cause problems on case-sensitive file systems

Nikolaos Giannopoulos

unread,
Mar 11, 2017, 1:43:15 AM3/11/17
to Fat-Free Framework
Thanks Ikkez for providing an answer that worked and everyone else that assisted.  I marked this thread as solved but wanted to include the problem/solution.

Essentially where I went wrong was in using a mixed case namespace naming when in fact the namespace folders were lower case

e.g. if I had the following class snippet:
namespace Controls\Common;

class HomeController extends \Controls\Base\CoreController {

and the controls/, common/, base/, etc. subfolders were lowercase then I should have had:
namespace controls\common;

class HomeController extends \controls\base\CoreController {

and everything works fine on my Linux box... on my Mac it works either way....

Thanks Again!

--Nikolaos

tom chris

unread,
Apr 10, 2017, 4:47:54 AM4/10/17
to Fat-Free Framework
I've autoload issue but it from other side

autoload = ../app/classes/;  <= External Class with Namespaces that cause problem without it works.

so i have to use composer autoload to handle when F3 autoload failed on it.


Nikolaos Giannopoulos

unread,
Apr 10, 2017, 7:15:50 AM4/10/17
to f3-fra...@googlegroups.com
Are you sure you should be leading with "../"?

ved

unread,
Apr 10, 2017, 7:34:00 AM4/10/17
to f3-fra...@googlegroups.com
First, what exactly is the issue/problem?

Anyway, try using:

AUTOLOAD = "../app/classes/"

Or set the full system path

tom chris

unread,
Apr 10, 2017, 2:55:47 PM4/10/17
to Fat-Free Framework
Problem is Namespaces

autoload failed on Namespaces and when using without namespaces it works.

i tried ../app as mention by bcosca but even that failed :p

so i end up using using composer

../ is need to find path of app dir and that classes subdir


ved

unread,
Apr 11, 2017, 4:47:45 AM4/11/17
to Fat-Free Framework
Can't we get any more details about the error? All you stated so far is that the "problem is namespaces" which is not very helpful since you didn't even tell us how your namespaces are setup.
At least paste a sample of how you have your namespaces on your classes. Also, set your DEBUG to 3 and paste any errors that you get here please.

Anyway, I'm also using namespaces and have apps with and without composer.

Here's my (simplified) setup in case it helps.

$f3 = require('lib/base.php');
$f3
->set('AUTOLOAD', 'app/;app/ext/');

Inside app/ I have a "controllers" and a "models" folders. Each controller and model inside those folders are using "namespace Controllers;" and "namespace Models;" respectively.

Routes are then setup like so:

$f3->route('GET|POST /something','\Controllers\SomeControler->some_method');

And to call a model inside a controller:

$mymodel = new \Models\MyModel();

This is all working fine. If I need to change from the require method to using composer, everything still works and I don't need to change anything else.

Hope it helps, but we do need more info otherwise we can't really guess your setup.
Reply all
Reply to author
Forward
0 new messages