1

I gave a glance at similar questions, but I think my problem is different since I have already ported the website I am working on to a local host successfully. Now I need to port the production website, currently hosted in a shared hosting, to a more professional space. Both are under linux OS, the localhost replica on my PC is under Windows. Once I have copied all the folders and files from the currently shared production hosting to the new hosting, what I can see is that just the index method of the main controller is reachable, whereas all the other public methods are not reachable and a "Not Found. The requested URL was not found on this server." error is returned.

The folders are organized into two main groups each with a distinct Codeigniter3 implementation:

  • public_html
    • endUsers
      • cache
      • config
      • controllers
        • frontController
          • index
          • research
          • news
          • (other methods) ...
      • models
      • (etc) ...
    • admin
      • cache
      • config
      • controllers
      • models
      • (etc) ...

where "admin" is the completely independent section for the website administrators and it is known just by them. Provided that the domain of the website is "mywebsite.com", the environment is configured to reach all the pages hiding the folder "endUsers". The homepage is reachable just by the URL "mywebsite.com" without writing the endUsers folder name as well as all the other controllers and methods. For instance, launching a research from a form on the home page the end user will see the resulting URL "mywebsite.com/frontController/research" and not "mywebsite.com/endUsers/frontController/research". For the administrator pages it goes differently, the admins have to explicit the folder "admin", something like "mywebsite.com/admin/controller_name".

The configuration .htaccess file in both the working current production hosting and the localhost is defined as follows:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 


RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 4000
   php_value memory_limit 1024M
   php_value post_max_size 256M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
   php_value upload_max_filesize 1024M
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 4000
   php_value memory_limit 1024M
   php_value post_max_size 256M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
   php_value upload_max_filesize 1024M
   php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

The routs.php file is as follows

$route['default_controller'] = 'frontController';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

I don't know which configuration in the new hosting server could still be wrong (Apache or Codeigniter); in all three cases, the web server is Apache.

EDIT 20/04/2023 In apache2.config I changed

<Directory /var/www/>
   Options Indexes
   FollowSymLinks Allow
   Override None
   Require all granted
</Directory>

into

Override All

This changed the error I get trying to access frontController methods different than index() into "500 Internal Server Error". I don't know which configuration in the new hosting server could still be wrong (Apache or Codeigniter); in all three cases, the web server is Apache. I gave a glance at the error log where I can read

[Thu Apr 20 13:32:29.497750 2023] [core:error] [pid 207555] [client [IP]:41410] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. 
Use 'LimitInternalRecursion' to increase the limit if necessary. 
Use 'LogLevel debug' to get a backtrace., referer: https://[IP]/index.php/frontController/productsResearch"

At first the home page after this change was working (browser cache or really working?); right now it isn't. The system administrator tool is Webmill, not cPanel.

fede72bari
  • 343
  • 5
  • 17
  • did you change in your root index.php (the one you see) the system and application path? It might to need to look like: `$system_path = '/home/your_server_name/public_html/wherever_system_is/system';` – Vickel Apr 19 '23 at 13:30
  • @Vickel thank you, I have checked and in the three cases, the two working and the new one not working, that variable is set to "$system_path = 'endUsers/system';", so to a relative path that should be fine in any case. – fede72bari Apr 19 '23 at 13:50
  • Is your Apache configured to interpret .htaccess files in the first place? – CBroe Apr 19 '23 at 13:53
  • `BEGIN cPanel-generated handler, do not edit` - was that actually inserted by the cPanel on this specific server? Or are you copying server-specific code around willy-nilly. – CBroe Apr 19 '23 at 13:54
  • @CBroe thank you. I am not an expert on Apache configuration regretfully. In the current production website the configuration should be the one proposed by the hosting service by default and it is reacheable by cPanel. In the new space, they offered me Webmin instead cPanel. Where could I check if Apache interpret .htaccess in the first place? And where could I check if "BEGIN cPanel-generated handler, do not edit" was inserted? Please consider that index is a method of the frontController and Apache redirects there in case of home page landing also in the new hosting. – fede72bari Apr 19 '23 at 13:59
  • If you can access/check the apache config, go check `AccessFileName` and `AllowOverride`, those are the two most important ones regarding interpretation of local config files, and getting mod_rewrite to work. _"Please consider that index is a method of the frontController and Apache redirects there in case of home page landing also in the new hosting."_ - that is probably not due to any actual redirect/rewrite though, but probably only Apache picking the index.php at the root level as the default file. – CBroe Apr 19 '23 at 14:08
  • #CBroe in Codeigniter index.php is a configuration and routing file as @Vickel indirectly suggested. The home page index is returned by a function (method) in frontController the default name of which is index: public function index(){ // do something } So that I cannot understand why Apache redirects correctly to a function of frontController for home page requests and not for the other functions of the same controller. I will give a look at that files thanks. – fede72bari Apr 19 '23 at 15:21
  • @CBroe looking at my localhost installation over XAMPP that is working correctly, I can find these files that might be the one you were mentioning: httpd.config, httpd-ssl.config, httpd-xampp.config Regretefully, the fields AcecessFileName and AllowOverride the value of which could be copied in the new not working space are not present in that config files. I run a global research of that keywords in all the apache folder an they have been not found. It seems they are not so important for the correct working of the environment. – fede72bari Apr 20 '23 at 08:43
  • The `public/index.php` is the router file, yes. But if you just request `/`, then the web server will automatically serve that index.php, based on standard DirectoryIndex configuration. Based on the requested path `/`, it knows that this is supposed to trigger your index action now. It does not _need_ a working rewrite setup, for _this_ particular thing to work. Your issue _is_ that your rewrite setup is not working; you are simply drawing the wrong conclusion from the fact that the index page is working here. – CBroe Apr 20 '23 at 09:03
  • @Cbroe thank you again. If I well understoond the routing index.php is called by the web server just asking for the home page (still it goes correctly to endUsers/index.php and not admin/index.php) because somehow it is the default directory. But the web server is not able to call it again when a specific controller and one of its methods are required. It makes sense; which name could have the Apache config files apart the ones that i have already checked and listed above (httpd.config, httpd-ssl.config, httpd-xampp.config)? – fede72bari Apr 20 '23 at 11:11
  • It really depends on your setup, default would probably be that you have individual config files for each Vhost under /etc/apache2/sites-available – CBroe Apr 20 '23 at 11:22
  • @Cbroe in the working localhost I cannot find those settings, but in the not working one I found them in apache2.config. I found "AccessFileName .htaccess" which appears correct. For AllowOverride I found " Options Indexes FollowSymLinks AllowOverride None Require all granted " for the public html directory. Should I change into "AllowOverride All"? – fede72bari Apr 20 '23 at 11:24
  • `FileInfo` should probably do in this situation, I guess; but if you are on your local system, then `All` probably doesn't do much harm either. – CBroe Apr 20 '23 at 11:28

0 Answers0