1

just today I opened this hosting (at serverplan.com with cpanel) to load my site created using codeigniter 4 (Ver: 4.1.9) only I'm experiencing some problems.

the folder structure is as follows:

\home2\bfinoshj
  - .cpanel
  - bin
  - etc
  - ...
  - ...
  - framework
    - app
    - tests
    - vendor
    - writable
  - public_html
    - assets
    - index.php
    - robots.txt
    - vendor
  - ...

first I modified the public_html/index.php file by changing the line like this:

from: $pathsConfig = FCPATH . '../app/Config/Paths.php';

to: $pathsConfig = FCPATH . '../framework/app/Config/Paths.php';

then I set the .env file like this

CI_ENVIRONMENT = production

app.baseURL = 'https://www.example.com/'
app.forceGlobalSecureRequests = true

database.default.hostname = my_host
database.default.database = my_db
database.default.username = my_user
database.default.password = my_pass

(for privacy reasons I have omitted the data), the rest I left commented.

later I also set app/config/App.php and app/config/Database.php correctly.

despite this the site does not work, and the following errors are shown in the logs:

from codeigniter

CRITICAL - 2022-05-05 14:20:47 --> is_file(): open_basedir restriction in effect. File(/home2/bfinoshj/framework/vendor/autoload.php/Config/Events.php) is not within the allowed path(s): (/home2/bfinoshj/:/opt/cpanel/ea-php81/root/usr:/usr/local/lib/php:/tmp:/etc/pki/tls/certs/ca-bundle.crt:/var/cpanel/php/sessions:/usr/local/bin/wp)
#0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'is_file(): open...', '/home2/bfinoshj...', 174)
#1 /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php(174): is_file('/home2/bfinoshj...')
#2 /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/Events/Events.php(80): CodeIgniter\Autoloader\FileLocator->search('Config/Events.p...')
#3 /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/Events/Events.php(141): CodeIgniter\Events\Events::initialize()
#4 /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/CodeIgniter.php(308): CodeIgniter\Events\Events::trigger('pre_system')
#5 /home2/bfinoshj/public_html/index.php(37): CodeIgniter\CodeIgniter->run()
#6 {main}

this from hosting log:

[05-May-2022 14:20:47 Europe/Rome] PHP Warning:  is_file(): open_basedir restriction in effect. File(/home2/bfinoshj/framework/vendor/autoload.php/Helpers/url_helper.php) is not within the allowed path(s): (/home2/bfinoshj/:/opt/cpanel/ea-php81/root/usr:/usr/local/lib/php:/tmp:/etc/pki/tls/certs/ca-bundle.crt:/var/cpanel/php/sessions:/usr/local/bin/wp) in /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php on line 174
[05-May-2022 14:20:47 Europe/Rome] PHP Warning:  is_file(): open_basedir restriction in effect. File(/home2/bfinoshj/framework/vendor/autoload.php/Config/Services.php) is not within the allowed path(s): (/home2/bfinoshj/:/opt/cpanel/ea-php81/root/usr:/usr/local/lib/php:/tmp:/etc/pki/tls/certs/ca-bundle.crt:/var/cpanel/php/sessions:/usr/local/bin/wp) in /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php on line 174
[05-May-2022 14:20:47 Europe/Rome] PHP Warning:  is_file(): open_basedir restriction in effect. File(/home2/bfinoshj/framework/vendor/autoload.php/Config/Registrar.php) is not within the allowed path(s): (/home2/bfinoshj/:/opt/cpanel/ea-php81/root/usr:/usr/local/lib/php:/tmp:/etc/pki/tls/certs/ca-bundle.crt:/var/cpanel/php/sessions:/usr/local/bin/wp) in /home2/bfinoshj/framework/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php on line 174

I have already contacted support to ask to disable open_basedir from the php.ini, but they replied that it is not possible for security reasons.

How can I solve? Thanks in advance

  • `/var/cpanel/php/sessions:/usr/local/bin/wp` says something about session. quick question, have you tried to change the session storage to database instead of file? see [this](https://stackoverflow.com/questions/28414383/codeigniter-open-basedir-restriction-in-effect-on-shared-hosting) and [the docs](https://codeigniter.com/user_guide/libraries/sessions.html#databasehandler-driver). – Bagus Tesa May 05 '22 at 12:54
  • I tried to change from File to Database but the errors always remain the same. while there is nothing in the folder –  May 05 '22 at 15:05
  • support advised me to remove `/home2/bfinoshj/` from paths, but still it doesn't work and I don't know how to start from the root of the project without having to go back every time with `../` –  May 05 '22 at 15:07
  • i just realized, you put your codeigniter core files under `framework` folder which outside `public_html` directory. i'd suspect the `open_basedir` is set to only allow `public_html`, which causes your `framework` folder unreachable by `index.php`. there is no trivial (legal) way to circumvent `open_basedir`. you should put the `framework` folder in `public_html` then protect it using [`.htaccess`](https://stackoverflow.com/a/19118529) (or [url rewrite](https://stackoverflow.com/a/38068519)) to prevent the contents being accessible from browser – Bagus Tesa May 05 '22 at 15:47
  • However, I don't know if I'm reasoning wrong or not. `/home2/bfinoshj/framework/vendor/autoload.php/Helpers/url_helper.php` if we take this error as an example (but especially it applies to everyone) it belongs to the paths where open_basedir is activity (which would be `/home2/bfinoshj/`)..? –  May 05 '22 at 16:16

0 Answers0