montilla Posted May 21, 2019 Share Posted May 21, 2019 Good morning, people! I'm having the following problem in my projectx in php: I created a project with Composer in php where I put php to listen to the public folder from the command prompt. However, when I upload the project to the site or to the xampp htdocs, the result of displaying the index (domain / projectx / public) is white. It does not display anything or any warning. Running with the php server via prompt listening directly to the public folder the project runs normally. The structure of the project is this (it has an attached image too): projeto x -App -Controller (folder with controllers) -Model (folder with models) -View (folder with views) -Connection (DB connection class) -Route (Class that manages the routes accessed in the browser and instantiates the necessary controllers) -public -.htaccess -index.php (Application start page that instantiates the Route class to determine the flow of the application) -vendor -composer (folder with composer files) -autoload.php composer.json composer.lock composer.phar When I include files in the public folder and access directly, the file works normally. That is, the server is listening to all folders. Could you help me with this? If I have to configure something on the server or in my project? I am new to PHP and would greatly appreciate your help. Right now, I'm grateful! Application running on the latest version of Composer. Tested on php version 5.6.40 and 7.1 Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/ Share on other sites More sharing options...
ginerjm Posted May 21, 2019 Share Posted May 21, 2019 Guess you have to be a true Composer user because I don't have a clue what any of the stuff you posted above is. I'm pretty sure it is not PHP code. Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1566953 Share on other sites More sharing options...
taquitosensei Posted May 21, 2019 Share Posted May 21, 2019 A white screen could be a fatal error. I would turn on error reporting put ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); at the top of your index.php, if it is a fatal error, the error should display instead of the white screen. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1566958 Share on other sites More sharing options...
kicken Posted May 21, 2019 Share Posted May 21, 2019 3 hours ago, montilla said: When I include files in the public folder and access directly, the file works normally. That is, the server is listening to all folders. Does that mean if you access the url http://example.com/public/index.php then things work? If so then you'll either need to re-configure your server so that the document root points to the public folder or setup a .htaccess file in your project folder to redirect requests to the public folder. Otherwise, if you mean adding a different .php file to the public folder and it works but the index.php file does not, then as mentioned above you probably have an error. The best way to find out is to check the error log, either for your server or a separate php error log depending on how it's configured. Create a file that executes the phpinfo() function to see how things are configured. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1566960 Share on other sites More sharing options...
montilla Posted May 22, 2019 Author Share Posted May 22, 2019 Good night! The context is that I use a shared hosting, and the folder available to the project is not the root of hosting. I researched other topics and will try to make some settings in the hosting tomorrow. I will come back with the results to share with you. I am from Brazil and our time zones should be different. Sorry for the divergence. My sincere thanks from now on. I hope to see you again and continue to help me on this journey. Big hug! 11 hours ago, taquitosensei said: A white screen could be a fatal error. I would turn on error reporting put ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); at the top of your index.php, if it is a fatal error, the error should display instead of the white screen. 10 hours ago, kicken said: Does that mean if you access the url http://example.com/public/index.php then things work? If so then you'll either need to re-configure your server so that the document root points to the public folder or setup a .htaccess file in your project folder to redirect requests to the public folder. Otherwise, if you mean adding a different .php file to the public folder and it works but the index.php file does not, then as mentioned above you probably have an error. The best way to find out is to check the error log, either for your server or a separate php error log depending on how it's configured. Create a file that executes the phpinfo() function to see how things are configured. Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1566984 Share on other sites More sharing options...
montilla Posted May 23, 2019 Author Share Posted May 23, 2019 On 5/21/2019 at 11:17 AM, taquitosensei said: A white screen could be a fatal error. I would turn on error reporting put ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); at the top of your index.php, if it is a fatal error, the error should display instead of the white screen. I included the code without code, but the page remains blank with no reference at all. What do you indicate? Remembering that my index.php is not at the root of hosting. Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567044 Share on other sites More sharing options...
gizmola Posted May 24, 2019 Share Posted May 24, 2019 The terminology you are using is a little odd. Servers don't "listen" to directories. Directories are either in web space or not. It looks to me like the only folder you want to be in "web space" is the public directory. Is your web root /public or are all the directories beneath the web root? There are many background questions that might help shed some light including: What web server is this running under? Apache? Nginx? Some of this info can be obtained from a quick script in the public directory that just contains phpinfo() What is in the composer.json, and in particular, the autoload configuration? What is in the .htaccess? What is in the index.php? Is this a framework project (CakePHP maybe?) When you say that this is shared hosting, does that mean that you don't have a shell and just ftp'd the site from your development box? Are you able to run composer install on the host? At the end of the day, there has to be something in a log that tells you what the error is. Where are the error logs for the site? Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567047 Share on other sites More sharing options...
montilla Posted May 25, 2019 Author Share Posted May 25, 2019 On 5/24/2019 at 1:31 AM, gizmola said: The terminology you are using is a little odd. Servers don't "listen" to directories. Directories are either in web space or not. It looks to me like the only folder you want to be in "web space" is the public directory. Is your web root /public or are all the directories beneath the web root? There are many background questions that might help shed some light including: What web server is this running under? Apache? Nginx? Some of this info can be obtained from a quick script in the public directory that just contains phpinfo() What is in the composer.json, and in particular, the autoload configuration? What is in the .htaccess? What is in the index.php? Is this a framework project (CakePHP maybe?) When you say that this is shared hosting, does that mean that you don't have a shell and just ftp'd the site from your development box? Are you able to run composer install on the host? At the end of the day, there has to be something in a log that tells you what the error is. Where are the error logs for the site? Good afternoon! I got past the blank page. It was a problem installing Composer on the server. I can access the index, but the server is not recognizing the other directories in my Route.php file. You are returning a 404 error. Answering your questions: * Linux Apache CentOS Server 6.9 - Kinghost Hosting; * My composer.json: { "name": "miniframework", "require": { "php": ">= 5.6" }, "authors": [ { "name": "Fabio Faria", "email": "[email protected]" } ], "autoload": { "psr-4": { "App\\": "App/", "MF\\": "vendor/MF/" } } } * My autoload.php: <?php // autoload.php @generated by Composer require_once __DIR__ . '/composer/autoload_real.php'; return ComposerAutoloaderInitf924af3bf344aef2d95a140d392154f6::getLoader(); * My Route.php: <?php //namespace correspondente ao diretório em que o arquivo está contido namespace App; use MF\Init\Bootstrap; class Route extends Bootstrap{ protected function initRoutes() { //configura array de rotas dos controllers $routes["home"] = array( "route" => "/", "controller" => "IndexController", "action" => "index" //action que será desparada no IndexController ); $routes["autenticar"] = array( "route" => "/autenticar", "controller" => "AuthController", "action" => "autenticar" //action que será desparada no AuthController ); $routes["laudos"] = array( "route" => "/laudos", "controller" => "AppController", "action" => "laudos" //action que será desparada no AppController ); $routes["sair"] = array( "route" => "/sair", "controller" => "AuthController", "action" => "sair" //action que será desparada no AuthController ); $routes["acao"] = array( "route" => "/acao", "controller" => "AppController", "action" => "acao" //action que será desparada no AppController ); $routes["buscar"] = array( "route" => "/buscar", "controller" => "AppController", "action" => "buscar" //action que será desparada no AppController ); $this->setRoutes($routes); } } ?> Right now, I'm grateful! Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567068 Share on other sites More sharing options...
montilla Posted May 25, 2019 Author Share Posted May 25, 2019 On 5/24/2019 at 1:31 AM, gizmola said: The terminology you are using is a little odd. Servers don't "listen" to directories. Directories are either in web space or not. It looks to me like the only folder you want to be in "web space" is the public directory. Is your web root /public or are all the directories beneath the web root? There are many background questions that might help shed some light including: What web server is this running under? Apache? Nginx? Some of this info can be obtained from a quick script in the public directory that just contains phpinfo() What is in the composer.json, and in particular, the autoload configuration? What is in the .htaccess? What is in the index.php? Is this a framework project (CakePHP maybe?) When you say that this is shared hosting, does that mean that you don't have a shell and just ftp'd the site from your development box? Are you able to run composer install on the host? At the end of the day, there has to be something in a log that tells you what the error is. Where are the error logs for the site? Continuing the answers: * My .htaccess is empty; * My index.php: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require_once "../vendor/autoload.php"; $route = new \App\Route; ?> * I do not have frameworks, only Composer; * That. I have only the FTP user with active SSH, which is where I installed Composer. The homepage of the site is this: http://oficinadoalicatecertific.com.br/ When we click the "Entrar" button at the top right, the action triggers the address /autenticar, but it generates the 404 error. The home page comes from Route.php, but something does not let you recognize the other routes. Can you help me? Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567069 Share on other sites More sharing options...
montilla Posted May 25, 2019 Author Share Posted May 25, 2019 Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567070 Share on other sites More sharing options...
montilla Posted May 25, 2019 Author Share Posted May 25, 2019 Updating: Composer is automatically changing my .htaccess by inserting the line "Deny from all" Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567071 Share on other sites More sharing options...
requinix Posted May 25, 2019 Share Posted May 25, 2019 No, composer is not doing that. If your .htaccess is empty (or has a Deny from All) then of course /autenticar won't work. You need something in there to route URLs through your PHP script. Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567072 Share on other sites More sharing options...
montilla Posted May 25, 2019 Author Share Posted May 25, 2019 16 minutes ago, requinix said: No, composer is not doing that. If your .htaccess is empty (or has a Deny from All) then of course /autenticar won't work. You need something in there to route URLs through your PHP script. But why locally does the project work perfectly? And if so, what setting should I set in this file? Whoever takes care of the routes is my Route.php, right? Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567074 Share on other sites More sharing options...
requinix Posted May 25, 2019 Share Posted May 25, 2019 18 minutes ago, montilla said: But why locally does the project work perfectly? Your local and production environments are not the same. Compare and contrast. 18 minutes ago, montilla said: Whoever takes care of the routes is my Route.php, right? Your PHP isn't being executed in the first place. That's the problem. The web server (Apache) has to know that it needs to execute your PHP. If it does not then you'll get those 404s. Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567075 Share on other sites More sharing options...
montilla Posted May 25, 2019 Author Share Posted May 25, 2019 39 minutes ago, requinix said: Your local and production environments are not the same. Compare and contrast. Your PHP isn't being executed in the first place. That's the problem. The web server (Apache) has to know that it needs to execute your PHP. If it does not then you'll get those 404s. How can I fix this? Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567076 Share on other sites More sharing options...
montilla Posted May 26, 2019 Author Share Posted May 26, 2019 I got it! With your tips, I came to the .htaccess issues and studying deeper, I saw that I had to do the routes through it or using a framework that abstracted routes by setting few parameters in .htaccess. I used the Slim framework. Thank you all for the promptness! Strong hug! ??? 1 Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567085 Share on other sites More sharing options...
devank71 Posted May 30, 2019 Share Posted May 30, 2019 Many thanks for sharing such great information about php. Keep sharing. Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567149 Share on other sites More sharing options...
gizmola Posted May 30, 2019 Share Posted May 30, 2019 10 hours ago, devank71 said: Many thanks for sharing such great information about php. Keep sharing. Glad you worked it out. We have been doing the same thing for over 15 years now, and hopefully for many more. ? Quote Link to comment https://forums.phpfreaks.com/topic/308736-php-structure-with-composer-does-not-work-in-production/#findComment-1567156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.